mirror of
https://github.com/pygos/init.git
synced 2024-11-25 04:20:42 +01:00
Remove some no longer needed cruft
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
c14c3c0173
commit
d9a5736bdf
11 changed files with 41 additions and 160 deletions
|
@ -2,7 +2,6 @@ shutdown_SOURCES = cmd/shutdown.c
|
|||
shutdown_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
shutdown_CFLAGS = $(AM_CFLAGS)
|
||||
shutdown_LDFLAGS = $(AM_LDFLAGS)
|
||||
shutdown_LDADD = libutil.a
|
||||
|
||||
runsvc_SOURCES = cmd/runsvc/runsvc.c cmd/runsvc/env.c cmd/runsvc/runsvc.h
|
||||
runsvc_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
static const struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "poweroff", no_argument, NULL, 'p' },
|
||||
{ "reboot", no_argument, NULL, 'r' },
|
||||
{ "force", no_argument, NULL, 'f' },
|
||||
|
@ -25,7 +24,7 @@ static const struct option options[] = {
|
|||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
static const char *shortopt = "hVprfn";
|
||||
static const char *shortopt = "hprfn";
|
||||
|
||||
static const char *defact_str = "power-off";
|
||||
static int defact = RB_POWER_OFF;
|
||||
|
@ -78,8 +77,6 @@ int main(int argc, char **argv)
|
|||
case 'r':
|
||||
defact = RB_AUTOBOOT;
|
||||
break;
|
||||
case 'V':
|
||||
print_version(ptr);
|
||||
case 'h':
|
||||
usage(ptr, EXIT_SUCCESS);
|
||||
default:
|
||||
|
|
|
@ -4,9 +4,7 @@ libinit_a_SOURCES += lib/init/svc_tsort.c lib/include/service.h
|
|||
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libinit_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
libutil_a_SOURCES = lib/util/argv_exec.c lib/util/enum_by_name.c
|
||||
libutil_a_SOURCES += lib/util/enum_to_name.c lib/util/print_version.c
|
||||
libutil_a_SOURCES += lib/util/fopenat.c lib/include/util.h
|
||||
libutil_a_SOURCES = lib/util/argv_exec.c lib/include/util.h
|
||||
libutil_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libutil_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ enum {
|
|||
it terminates.
|
||||
*/
|
||||
SVC_RESPAWN,
|
||||
|
||||
SVC_MAX
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int value;
|
||||
} enum_map_t;
|
||||
|
||||
typedef struct exec_t {
|
||||
struct exec_t *next;
|
||||
int argc; /* number of elements in argument vector */
|
||||
|
@ -37,31 +32,8 @@ enum {
|
|||
SOCK_FLAG_DGRAM = 0x04,
|
||||
};
|
||||
|
||||
/*
|
||||
Search through an array of enum_map_t entries to resolve a string to
|
||||
a numeric value. The end of the map is indicated by a sentinel entry
|
||||
with the name set to NULL.
|
||||
*/
|
||||
const enum_map_t *enum_by_name(const enum_map_t *map, const char *name);
|
||||
|
||||
/*
|
||||
Search through an array of enum_map_t entries to resolve a numeric
|
||||
value to a string name. The end of the map is indicated by a sentinel
|
||||
entry with the name set to NULL.
|
||||
*/
|
||||
const char *enum_to_name(const enum_map_t *map, int value);
|
||||
|
||||
/* print a default version info and license string */
|
||||
NORETURN void print_version(const char *program);
|
||||
|
||||
int setup_tty(const char *tty, bool truncate);
|
||||
|
||||
NORETURN void argv_exec(exec_t *e);
|
||||
|
||||
/*
|
||||
Similar to openat: opens a file relative to a dirfd, but returns
|
||||
a FILE pointer instead of an fd.
|
||||
*/
|
||||
FILE *fopenat(int fd, const char *filename, const char *mode);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
|
|
@ -1,41 +1,49 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <string.h>
|
||||
#include "service.h"
|
||||
#include "util.h"
|
||||
|
||||
static const enum_map_t type_map[] = {
|
||||
{ "once", SVC_ONCE },
|
||||
{ "wait", SVC_WAIT },
|
||||
{ "respawn", SVC_RESPAWN },
|
||||
{ NULL, 0 },
|
||||
static const char *type_map[] = {
|
||||
"once",
|
||||
"wait",
|
||||
"respawn",
|
||||
};
|
||||
|
||||
static const enum_map_t target_map[] = {
|
||||
{ "boot", TGT_BOOT },
|
||||
{ "shutdown", TGT_SHUTDOWN },
|
||||
{ "reboot", TGT_REBOOT },
|
||||
{ NULL, 0 },
|
||||
static const char *target_map[] = {
|
||||
"boot",
|
||||
"shutdown",
|
||||
"reboot",
|
||||
};
|
||||
|
||||
const char *svc_type_to_string(int type)
|
||||
{
|
||||
return enum_to_name(type_map, type);
|
||||
return type >= 0 && type < SVC_MAX ? type_map[type] : NULL;
|
||||
}
|
||||
|
||||
int svc_type_from_string(const char *type)
|
||||
{
|
||||
const enum_map_t *ent = enum_by_name(type_map, type);
|
||||
size_t i;
|
||||
|
||||
return ent == NULL ? -1 : ent->value;
|
||||
for (i = 0; i < ARRAY_SIZE(type_map); ++i) {
|
||||
if (strcmp(type_map[i], type) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *svc_target_to_string(int target)
|
||||
{
|
||||
return enum_to_name(target_map, target);
|
||||
return target >= 0 && target < TGT_MAX ? target_map[target] : NULL;
|
||||
}
|
||||
|
||||
int svc_target_from_string(const char *target)
|
||||
{
|
||||
const enum_map_t *ent = enum_by_name(target_map, target);
|
||||
size_t i;
|
||||
|
||||
return ent == NULL ? -1 : ent->value;
|
||||
for (i = 0; i < ARRAY_SIZE(target_map); ++i) {
|
||||
if (strcmp(target_map[i], target) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "libcfg.h"
|
||||
#include "util.h"
|
||||
|
@ -12,18 +13,26 @@
|
|||
int rdline_init(rdline_t *t, int dirfd, const char *filename,
|
||||
int argc, const char *const *argv)
|
||||
{
|
||||
int fd = openat(dirfd, filename, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
goto fail_open;
|
||||
|
||||
memset(t, 0, sizeof(*t));
|
||||
|
||||
t->fp = fopenat(dirfd, filename, "r");
|
||||
t->fp = fdopen(fd, "r");
|
||||
if (t->fp == NULL) {
|
||||
perror(filename);
|
||||
return -1;
|
||||
close(fd);
|
||||
goto fail_open;
|
||||
}
|
||||
|
||||
t->filename = filename;
|
||||
t->argc = argc;
|
||||
t->argv = argv;
|
||||
return 0;
|
||||
fail_open:
|
||||
perror(filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void rdline_cleanup(rdline_t *t)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
const enum_map_t *enum_by_name(const enum_map_t *map, const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; map[i].name != NULL; ++i) {
|
||||
if (!strcmp(map[i].name, name))
|
||||
return map + i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
const char *enum_to_name(const enum_map_t *map, int value)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; map[i].name != NULL; ++i) {
|
||||
if (map[i].value == value)
|
||||
return map[i].name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
FILE *fopenat(int dirfd, const char *filename, const char *mode)
|
||||
{
|
||||
const char *ptr = mode;
|
||||
int fd, flags = 0;
|
||||
FILE *fp;
|
||||
|
||||
switch (*(ptr++)) {
|
||||
case 'r':
|
||||
flags = O_RDONLY;
|
||||
break;
|
||||
case 'w':
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
break;
|
||||
case 'a':
|
||||
flags = O_WRONLY | O_CREAT | O_APPEND;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*ptr == '+') {
|
||||
flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
|
||||
++ptr;
|
||||
}
|
||||
|
||||
if (*ptr == 'b')
|
||||
++ptr;
|
||||
|
||||
if (*ptr != '\0') {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = openat(dirfd, filename, flags, 0644);
|
||||
if (fd == -1)
|
||||
return NULL;
|
||||
|
||||
fp = fdopen(fd, mode);
|
||||
if (fp == NULL)
|
||||
close(fd);
|
||||
|
||||
return fp;
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/* SPDX-License-Identifier: ISC */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
static const char *version_string =
|
||||
"%s (pygos init) " PACKAGE_VERSION "\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
void print_version(const char *program)
|
||||
{
|
||||
fprintf(stdout, version_string, program);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in a new issue