1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-11-22 19:19:47 +01:00

Unify naming of service to shorthand svc

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-03-25 12:14:06 +02:00
parent a108beaaf7
commit a71c92b33d
9 changed files with 87 additions and 87 deletions

View file

@ -39,14 +39,14 @@ static void handle_exited(service_t *svc)
switch (svc->type) { switch (svc->type) {
case SVC_RESPAWN: case SVC_RESPAWN:
if (target == TGT_REBOOT || target == TGT_SHUTDOWN) { if (target == TGT_REBOOT || target == TGT_SHUTDOWN) {
delsrv(svc); delsvc(svc);
break; break;
} }
svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty); svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
if (svc->pid == -1) { if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false); print_status(svc->desc, STATUS_FAIL, false);
delsrv(svc); delsvc(svc);
} }
svclist_add(svc); svclist_add(svc);
@ -57,7 +57,7 @@ static void handle_exited(service_t *svc)
STATUS_OK : STATUS_FAIL, false); STATUS_OK : STATUS_FAIL, false);
/* fall-through */ /* fall-through */
default: default:
delsrv(svc); delsvc(svc);
break; break;
} }
} }
@ -107,7 +107,7 @@ static void start_runlevel(int level)
if (!svc->num_exec) { if (!svc->num_exec) {
print_status(svc->desc, STATUS_OK, false); print_status(svc->desc, STATUS_OK, false);
delsrv(svc); delsvc(svc);
continue; continue;
} }
@ -121,12 +121,12 @@ static void start_runlevel(int level)
status == EXIT_SUCCESS ? status == EXIT_SUCCESS ?
STATUS_OK : STATUS_FAIL, STATUS_OK : STATUS_FAIL,
true); true);
delsrv(svc); delsvc(svc);
} else { } else {
svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty); svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
if (svc->pid == -1) { if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false); print_status(svc->desc, STATUS_FAIL, false);
delsrv(svc); delsvc(svc);
continue; continue;
} }
@ -196,7 +196,7 @@ int main(void)
if (reboot(LINUX_REBOOT_CMD_CAD_OFF)) if (reboot(LINUX_REBOOT_CMD_CAD_OFF))
perror("cannot disable CTRL+ALT+DEL"); perror("cannot disable CTRL+ALT+DEL");
if (srvscan(SVCDIR, &cfg)) { if (svcscan(SVCDIR, &cfg)) {
fputs("Error reading service list from " SVCDIR "\n" fputs("Error reading service list from " SVCDIR "\n"
"Trying to continue anyway\n", stderr); "Trying to continue anyway\n", stderr);
} }

View file

@ -1,9 +1,9 @@
HEADRS = lib/include/util.h lib/include/service.h lib/include/telinit.h HEADRS = lib/include/util.h lib/include/service.h lib/include/telinit.h
libinit_a_SOURCES = lib/src/delsrv.c lib/src/rdline.c lib/src/svcmap.c libinit_a_SOURCES = lib/src/delsvc.c lib/src/rdline.c lib/src/svcmap.c
libinit_a_SOURCES += lib/src/splitkv.c lib/src/enum_by_name.c libinit_a_SOURCES += lib/src/splitkv.c lib/src/enum_by_name.c
libinit_a_SOURCES += lib/src/strexpand.c lib/src/rdsrv.c lib/src/srvscan.c libinit_a_SOURCES += lib/src/strexpand.c lib/src/rdsvc.c lib/src/svcscan.c
libinit_a_SOURCES += lib/src/del_srv_list.c lib/src/srv_tsort.c libinit_a_SOURCES += lib/src/del_svc_list.c lib/src/svc_tsort.c
libinit_a_SOURCES += lib/src/opensock.c lib/src/enum_to_name.c $(HEADRS) libinit_a_SOURCES += lib/src/opensock.c lib/src/enum_to_name.c $(HEADRS)
libinit_a_CPPFLAGS = $(AM_CPPFLAGS) libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
libinit_a_CFLAGS = $(AM_CFLAGS) libinit_a_CFLAGS = $(AM_CFLAGS)

View file

@ -71,9 +71,9 @@ typedef struct {
/* /*
Read a service from a file. Read a service from a file.
*/ */
service_t *rdsrv(int dirfd, const char *filename); service_t *rdsvc(int dirfd, const char *filename);
void delsrv(service_t *srv); void delsvc(service_t *svc);
/* /*
Rebuild a service list by scanning a directory and parsing all Rebuild a service list by scanning a directory and parsing all
@ -82,14 +82,14 @@ void delsrv(service_t *srv);
Returns 0 on success, -1 on failure. The function takes care of Returns 0 on success, -1 on failure. The function takes care of
printing error messages on failure. printing error messages on failure.
*/ */
int srvscan(const char *directory, service_list_t *list); int svcscan(const char *directory, service_list_t *list);
void del_srv_list(service_list_t *list); void del_svc_list(service_list_t *list);
/* /*
Sort a list of services by dependencies. Sort a list of services by dependencies.
*/ */
service_t *srv_tsort(service_t *list); service_t *svc_tsort(service_t *list);
const char *svc_type_to_string(int type); const char *svc_type_to_string(int type);

View file

@ -19,17 +19,17 @@
#include "service.h" #include "service.h"
void del_srv_list(service_list_t *list) void del_svc_list(service_list_t *list)
{ {
service_t *srv; service_t *svc;
int i; int i;
for (i = 0; i < TGT_MAX; ++i) { for (i = 0; i < TGT_MAX; ++i) {
while (list->targets[i] != NULL) { while (list->targets[i] != NULL) {
srv = list->targets[i]; svc = list->targets[i];
list->targets[i] = srv->next; list->targets[i] = svc->next;
delsrv(srv); delsvc(svc);
} }
} }
} }

View file

@ -19,24 +19,24 @@
#include "service.h" #include "service.h"
void delsrv(service_t *srv) void delsvc(service_t *svc)
{ {
size_t i; size_t i;
for (i = 0; i < srv->num_exec; ++i) for (i = 0; i < svc->num_exec; ++i)
free(srv->exec[i]); free(svc->exec[i]);
for (i = 0; i < srv->num_before; ++i) for (i = 0; i < svc->num_before; ++i)
free(srv->before[i]); free(svc->before[i]);
for (i = 0; i < srv->num_after; ++i) for (i = 0; i < svc->num_after; ++i)
free(srv->after[i]); free(svc->after[i]);
free(srv->before); free(svc->before);
free(srv->after); free(svc->after);
free(srv->name); free(svc->name);
free(srv->desc); free(svc->desc);
free(srv->exec); free(svc->exec);
free(srv->ctty); free(svc->ctty);
free(srv); free(svc);
} }

View file

@ -27,34 +27,34 @@
#include "service.h" #include "service.h"
#include "util.h" #include "util.h"
static int srv_name(service_t *srv, char *arg, static int svc_name(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
(void)filename; (void)lineno; (void)filename; (void)lineno;
srv->name = arg; svc->name = arg;
return 0; return 0;
} }
static int srv_desc(service_t *srv, char *arg, static int svc_desc(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
(void)filename; (void)lineno; (void)filename; (void)lineno;
srv->desc = arg; svc->desc = arg;
return 0; return 0;
} }
static int srv_tty(service_t *srv, char *arg, static int svc_tty(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
(void)filename; (void)lineno; (void)filename; (void)lineno;
srv->ctty = arg; svc->ctty = arg;
return 0; return 0;
} }
static int srv_exec(service_t *srv, char *arg, static int svc_exec(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
char **new = realloc(srv->exec, sizeof(char*) * (srv->num_exec + 1)); char **new = realloc(svc->exec, sizeof(char*) * (svc->num_exec + 1));
if (new == NULL) { if (new == NULL) {
fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno); fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno);
@ -62,16 +62,16 @@ static int srv_exec(service_t *srv, char *arg,
return -1; return -1;
} }
srv->exec = new; svc->exec = new;
srv->exec[srv->num_exec++] = arg; svc->exec[svc->num_exec++] = arg;
return 0; return 0;
} }
static int srv_before(service_t *srv, char *arg, static int svc_before(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
char **new = realloc(srv->before, char **new = realloc(svc->before,
sizeof(char*) * (srv->num_before + 1)); sizeof(char*) * (svc->num_before + 1));
if (new == NULL) { if (new == NULL) {
fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno); fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno);
@ -79,15 +79,15 @@ static int srv_before(service_t *srv, char *arg,
return -1; return -1;
} }
srv->before = new; svc->before = new;
srv->before[srv->num_before++] = arg; svc->before[svc->num_before++] = arg;
return 0; return 0;
} }
static int srv_after(service_t *srv, char *arg, static int svc_after(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
char **new = realloc(srv->after, sizeof(char*) * (srv->num_after + 1)); char **new = realloc(svc->after, sizeof(char*) * (svc->num_after + 1));
if (new == NULL) { if (new == NULL) {
fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno); fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno);
@ -95,12 +95,12 @@ static int srv_after(service_t *srv, char *arg,
return -1; return -1;
} }
srv->after = new; svc->after = new;
srv->after[srv->num_after++] = arg; svc->after[svc->num_after++] = arg;
return 0; return 0;
} }
static int srv_type(service_t *srv, char *arg, static int svc_type(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
int type = svc_type_from_string(arg); int type = svc_type_from_string(arg);
@ -111,12 +111,12 @@ static int srv_type(service_t *srv, char *arg,
return -1; return -1;
} }
srv->type = type; svc->type = type;
free(arg); free(arg);
return 0; return 0;
} }
static int srv_target(service_t *srv, char *arg, static int svc_target(service_t *svc, char *arg,
const char *filename, size_t lineno) const char *filename, size_t lineno)
{ {
int target = svc_target_from_string(arg); int target = svc_target_from_string(arg);
@ -127,7 +127,7 @@ static int srv_target(service_t *srv, char *arg,
return -1; return -1;
} }
srv->target = target; svc->target = target;
free(arg); free(arg);
return 0; return 0;
} }
@ -136,26 +136,26 @@ static int srv_target(service_t *srv, char *arg,
static const struct { static const struct {
const char *key; const char *key;
int (*handle)(service_t *srv, char *arg, int (*handle)(service_t *svc, char *arg,
const char *filename, size_t lineno); const char *filename, size_t lineno);
} srv_params[] = { } svc_params[] = {
{ "name", srv_name }, { "name", svc_name },
{ "description", srv_desc }, { "description", svc_desc },
{ "exec", srv_exec }, { "exec", svc_exec },
{ "type", srv_type }, { "type", svc_type },
{ "target", srv_target }, { "target", svc_target },
{ "tty", srv_tty }, { "tty", svc_tty },
{ "before", srv_before }, { "before", svc_before },
{ "after", srv_after }, { "after", svc_after },
}; };
service_t *rdsrv(int dirfd, const char *filename) service_t *rdsvc(int dirfd, const char *filename)
{ {
const char *arg, *args[1]; const char *arg, *args[1];
char *line, *key, *value; char *line, *key, *value;
size_t i, argc, lineno; size_t i, argc, lineno;
service_t *srv; service_t *svc;
int fd; int fd;
fd = openat(dirfd, filename, O_RDONLY); fd = openat(dirfd, filename, O_RDONLY);
@ -172,8 +172,8 @@ service_t *rdsrv(int dirfd, const char *filename)
argc = 0; argc = 0;
} }
srv = calloc(1, sizeof(*srv)); svc = calloc(1, sizeof(*svc));
if (srv == NULL) { if (svc == NULL) {
fputs("out of memory\n", stderr); fputs("out of memory\n", stderr);
close(fd); close(fd);
return NULL; return NULL;
@ -215,12 +215,12 @@ service_t *rdsrv(int dirfd, const char *filename)
continue; continue;
} }
for (i = 0; i < ARRAY_SIZE(srv_params); ++i) { for (i = 0; i < ARRAY_SIZE(svc_params); ++i) {
if (!strcmp(srv_params[i].key, key)) if (!strcmp(svc_params[i].key, key))
break; break;
} }
if (i >= ARRAY_SIZE(srv_params)) { if (i >= ARRAY_SIZE(svc_params)) {
fprintf(stderr, "%s: %zu: unknown parameter '%s'\n", fprintf(stderr, "%s: %zu: unknown parameter '%s'\n",
filename, lineno, key); filename, lineno, key);
goto fail_line; goto fail_line;
@ -232,7 +232,7 @@ service_t *rdsrv(int dirfd, const char *filename)
goto fail_line; goto fail_line;
} }
if (srv_params[i].handle(srv, value, filename, lineno)) { if (svc_params[i].handle(svc, value, filename, lineno)) {
free(value); free(value);
goto fail_line; goto fail_line;
} }
@ -241,11 +241,11 @@ service_t *rdsrv(int dirfd, const char *filename)
} }
close(fd); close(fd);
return srv; return svc;
fail_line: fail_line:
free(line); free(line);
fail: fail:
close(fd); close(fd);
delsrv(srv); delsvc(svc);
return NULL; return NULL;
} }

View file

@ -43,7 +43,7 @@ static bool has_dependencies(service_t *list, service_t *svc)
return false; return false;
} }
service_t *srv_tsort(service_t *list) service_t *svc_tsort(service_t *list)
{ {
service_t *nl = NULL, *end = NULL; service_t *nl = NULL, *end = NULL;
service_t *svc, *prev; service_t *svc, *prev;

View file

@ -27,12 +27,12 @@
#include "service.h" #include "service.h"
int srvscan(const char *directory, service_list_t *list) int svcscan(const char *directory, service_list_t *list)
{ {
int i, dfd, type, ret = 0; int i, dfd, type, ret = 0;
struct dirent *ent; struct dirent *ent;
const char *ptr; const char *ptr;
service_t *srv; service_t *svc;
struct stat sb; struct stat sb;
DIR *dir; DIR *dir;
@ -82,14 +82,14 @@ int srvscan(const char *directory, service_list_t *list)
if (type != S_IFREG && type != S_IFLNK) if (type != S_IFREG && type != S_IFLNK)
continue; continue;
srv = rdsrv(dfd, ent->d_name); svc = rdsvc(dfd, ent->d_name);
if (srv == NULL) { if (svc == NULL) {
ret = -1; ret = -1;
continue; continue;
} }
srv->next = list->targets[srv->target]; svc->next = list->targets[svc->target];
list->targets[srv->target] = srv; list->targets[svc->target] = svc;
} }
for (i = 0; i < TGT_MAX; ++i) { for (i = 0; i < TGT_MAX; ++i) {
@ -97,7 +97,7 @@ int srvscan(const char *directory, service_list_t *list)
continue; continue;
errno = 0; errno = 0;
list->targets[i] = srv_tsort(list->targets[i]); list->targets[i] = svc_tsort(list->targets[i]);
if (errno != 0) { if (errno != 0) {
fprintf(stderr, "sorting services read from %s: %s\n", fprintf(stderr, "sorting services read from %s: %s\n",

View file

@ -53,7 +53,7 @@ static int cmd_list(int argc, char **argv)
if (check_arguments(argv[0], argc, 1, 2)) if (check_arguments(argv[0], argc, 1, 2))
return EXIT_FAILURE; return EXIT_FAILURE;
if (srvscan(SVCDIR, &list)) { if (svcscan(SVCDIR, &list)) {
fprintf(stderr, "Error while reading services from %s\n", fprintf(stderr, "Error while reading services from %s\n",
SVCDIR); SVCDIR);
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
@ -75,7 +75,7 @@ static int cmd_list(int argc, char **argv)
print_services(list.targets[i]); print_services(list.targets[i]);
} }
out: out:
del_srv_list(&list); del_svc_list(&list);
return ret; return ret;
} }