diff --git a/initd/main.c b/initd/main.c index be9fc0d..d3e22b6 100644 --- a/initd/main.c +++ b/initd/main.c @@ -39,14 +39,14 @@ static void handle_exited(service_t *svc) switch (svc->type) { case SVC_RESPAWN: if (target == TGT_REBOOT || target == TGT_SHUTDOWN) { - delsrv(svc); + delsvc(svc); break; } svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty); if (svc->pid == -1) { print_status(svc->desc, STATUS_FAIL, false); - delsrv(svc); + delsvc(svc); } svclist_add(svc); @@ -57,7 +57,7 @@ static void handle_exited(service_t *svc) STATUS_OK : STATUS_FAIL, false); /* fall-through */ default: - delsrv(svc); + delsvc(svc); break; } } @@ -107,7 +107,7 @@ static void start_runlevel(int level) if (!svc->num_exec) { print_status(svc->desc, STATUS_OK, false); - delsrv(svc); + delsvc(svc); continue; } @@ -121,12 +121,12 @@ static void start_runlevel(int level) status == EXIT_SUCCESS ? STATUS_OK : STATUS_FAIL, true); - delsrv(svc); + delsvc(svc); } else { svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty); if (svc->pid == -1) { print_status(svc->desc, STATUS_FAIL, false); - delsrv(svc); + delsvc(svc); continue; } @@ -196,7 +196,7 @@ int main(void) if (reboot(LINUX_REBOOT_CMD_CAD_OFF)) perror("cannot disable CTRL+ALT+DEL"); - if (srvscan(SVCDIR, &cfg)) { + if (svcscan(SVCDIR, &cfg)) { fputs("Error reading service list from " SVCDIR "\n" "Trying to continue anyway\n", stderr); } diff --git a/lib/Makemodule.am b/lib/Makemodule.am index a9d7e0c..1d7da73 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -1,9 +1,9 @@ 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/strexpand.c lib/src/rdsrv.c lib/src/srvscan.c -libinit_a_SOURCES += lib/src/del_srv_list.c lib/src/srv_tsort.c +libinit_a_SOURCES += lib/src/strexpand.c lib/src/rdsvc.c lib/src/svcscan.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_CPPFLAGS = $(AM_CPPFLAGS) libinit_a_CFLAGS = $(AM_CFLAGS) diff --git a/lib/include/service.h b/lib/include/service.h index dd7700c..28d73f1 100644 --- a/lib/include/service.h +++ b/lib/include/service.h @@ -71,9 +71,9 @@ typedef struct { /* 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 @@ -82,14 +82,14 @@ void delsrv(service_t *srv); Returns 0 on success, -1 on failure. The function takes care of 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. */ -service_t *srv_tsort(service_t *list); +service_t *svc_tsort(service_t *list); const char *svc_type_to_string(int type); diff --git a/lib/src/del_srv_list.c b/lib/src/del_svc_list.c similarity index 86% rename from lib/src/del_srv_list.c rename to lib/src/del_svc_list.c index d54c40b..553a701 100644 --- a/lib/src/del_srv_list.c +++ b/lib/src/del_svc_list.c @@ -19,17 +19,17 @@ #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; for (i = 0; i < TGT_MAX; ++i) { while (list->targets[i] != NULL) { - srv = list->targets[i]; - list->targets[i] = srv->next; + svc = list->targets[i]; + list->targets[i] = svc->next; - delsrv(srv); + delsvc(svc); } } } diff --git a/lib/src/delsrv.c b/lib/src/delsvc.c similarity index 70% rename from lib/src/delsrv.c rename to lib/src/delsvc.c index 87b65bc..3e077fb 100644 --- a/lib/src/delsrv.c +++ b/lib/src/delsvc.c @@ -19,24 +19,24 @@ #include "service.h" -void delsrv(service_t *srv) +void delsvc(service_t *svc) { size_t i; - for (i = 0; i < srv->num_exec; ++i) - free(srv->exec[i]); + for (i = 0; i < svc->num_exec; ++i) + free(svc->exec[i]); - for (i = 0; i < srv->num_before; ++i) - free(srv->before[i]); + for (i = 0; i < svc->num_before; ++i) + free(svc->before[i]); - for (i = 0; i < srv->num_after; ++i) - free(srv->after[i]); + for (i = 0; i < svc->num_after; ++i) + free(svc->after[i]); - free(srv->before); - free(srv->after); - free(srv->name); - free(srv->desc); - free(srv->exec); - free(srv->ctty); - free(srv); + free(svc->before); + free(svc->after); + free(svc->name); + free(svc->desc); + free(svc->exec); + free(svc->ctty); + free(svc); } diff --git a/lib/src/rdsrv.c b/lib/src/rdsvc.c similarity index 72% rename from lib/src/rdsrv.c rename to lib/src/rdsvc.c index 88d41e8..972f7e4 100644 --- a/lib/src/rdsrv.c +++ b/lib/src/rdsvc.c @@ -27,34 +27,34 @@ #include "service.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) { (void)filename; (void)lineno; - srv->name = arg; + svc->name = arg; 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) { (void)filename; (void)lineno; - srv->desc = arg; + svc->desc = arg; 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) { (void)filename; (void)lineno; - srv->ctty = arg; + svc->ctty = arg; 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) { - 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) { 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; } - srv->exec = new; - srv->exec[srv->num_exec++] = arg; + svc->exec = new; + svc->exec[svc->num_exec++] = arg; 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) { - char **new = realloc(srv->before, - sizeof(char*) * (srv->num_before + 1)); + char **new = realloc(svc->before, + sizeof(char*) * (svc->num_before + 1)); if (new == NULL) { 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; } - srv->before = new; - srv->before[srv->num_before++] = arg; + svc->before = new; + svc->before[svc->num_before++] = arg; 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) { - 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) { 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; } - srv->after = new; - srv->after[srv->num_after++] = arg; + svc->after = new; + svc->after[svc->num_after++] = arg; 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) { int type = svc_type_from_string(arg); @@ -111,12 +111,12 @@ static int srv_type(service_t *srv, char *arg, return -1; } - srv->type = type; + svc->type = type; free(arg); 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) { int target = svc_target_from_string(arg); @@ -127,7 +127,7 @@ static int srv_target(service_t *srv, char *arg, return -1; } - srv->target = target; + svc->target = target; free(arg); return 0; } @@ -136,26 +136,26 @@ static int srv_target(service_t *srv, char *arg, static const struct { const char *key; - int (*handle)(service_t *srv, char *arg, + int (*handle)(service_t *svc, char *arg, const char *filename, size_t lineno); -} srv_params[] = { - { "name", srv_name }, - { "description", srv_desc }, - { "exec", srv_exec }, - { "type", srv_type }, - { "target", srv_target }, - { "tty", srv_tty }, - { "before", srv_before }, - { "after", srv_after }, +} svc_params[] = { + { "name", svc_name }, + { "description", svc_desc }, + { "exec", svc_exec }, + { "type", svc_type }, + { "target", svc_target }, + { "tty", svc_tty }, + { "before", svc_before }, + { "after", svc_after }, }; -service_t *rdsrv(int dirfd, const char *filename) +service_t *rdsvc(int dirfd, const char *filename) { const char *arg, *args[1]; char *line, *key, *value; size_t i, argc, lineno; - service_t *srv; + service_t *svc; int fd; fd = openat(dirfd, filename, O_RDONLY); @@ -172,8 +172,8 @@ service_t *rdsrv(int dirfd, const char *filename) argc = 0; } - srv = calloc(1, sizeof(*srv)); - if (srv == NULL) { + svc = calloc(1, sizeof(*svc)); + if (svc == NULL) { fputs("out of memory\n", stderr); close(fd); return NULL; @@ -215,12 +215,12 @@ service_t *rdsrv(int dirfd, const char *filename) continue; } - for (i = 0; i < ARRAY_SIZE(srv_params); ++i) { - if (!strcmp(srv_params[i].key, key)) + for (i = 0; i < ARRAY_SIZE(svc_params); ++i) { + if (!strcmp(svc_params[i].key, key)) break; } - if (i >= ARRAY_SIZE(srv_params)) { + if (i >= ARRAY_SIZE(svc_params)) { fprintf(stderr, "%s: %zu: unknown parameter '%s'\n", filename, lineno, key); goto fail_line; @@ -232,7 +232,7 @@ service_t *rdsrv(int dirfd, const char *filename) goto fail_line; } - if (srv_params[i].handle(srv, value, filename, lineno)) { + if (svc_params[i].handle(svc, value, filename, lineno)) { free(value); goto fail_line; } @@ -241,11 +241,11 @@ service_t *rdsrv(int dirfd, const char *filename) } close(fd); - return srv; + return svc; fail_line: free(line); fail: close(fd); - delsrv(srv); + delsvc(svc); return NULL; } diff --git a/lib/src/srv_tsort.c b/lib/src/svc_tsort.c similarity index 98% rename from lib/src/srv_tsort.c rename to lib/src/svc_tsort.c index d375c4f..50517f2 100644 --- a/lib/src/srv_tsort.c +++ b/lib/src/svc_tsort.c @@ -43,7 +43,7 @@ static bool has_dependencies(service_t *list, service_t *svc) return false; } -service_t *srv_tsort(service_t *list) +service_t *svc_tsort(service_t *list) { service_t *nl = NULL, *end = NULL; service_t *svc, *prev; diff --git a/lib/src/srvscan.c b/lib/src/svcscan.c similarity index 89% rename from lib/src/srvscan.c rename to lib/src/svcscan.c index 69d0b91..32c1dee 100644 --- a/lib/src/srvscan.c +++ b/lib/src/svcscan.c @@ -27,12 +27,12 @@ #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; struct dirent *ent; const char *ptr; - service_t *srv; + service_t *svc; struct stat sb; DIR *dir; @@ -82,14 +82,14 @@ int srvscan(const char *directory, service_list_t *list) if (type != S_IFREG && type != S_IFLNK) continue; - srv = rdsrv(dfd, ent->d_name); - if (srv == NULL) { + svc = rdsvc(dfd, ent->d_name); + if (svc == NULL) { ret = -1; continue; } - srv->next = list->targets[srv->target]; - list->targets[srv->target] = srv; + svc->next = list->targets[svc->target]; + list->targets[svc->target] = svc; } for (i = 0; i < TGT_MAX; ++i) { @@ -97,7 +97,7 @@ int srvscan(const char *directory, service_list_t *list) continue; errno = 0; - list->targets[i] = srv_tsort(list->targets[i]); + list->targets[i] = svc_tsort(list->targets[i]); if (errno != 0) { fprintf(stderr, "sorting services read from %s: %s\n", diff --git a/servicecmd/list.c b/servicecmd/list.c index 45d2b19..07153f2 100644 --- a/servicecmd/list.c +++ b/servicecmd/list.c @@ -53,7 +53,7 @@ static int cmd_list(int argc, char **argv) if (check_arguments(argv[0], argc, 1, 2)) return EXIT_FAILURE; - if (srvscan(SVCDIR, &list)) { + if (svcscan(SVCDIR, &list)) { fprintf(stderr, "Error while reading services from %s\n", SVCDIR); ret = EXIT_FAILURE; @@ -75,7 +75,7 @@ static int cmd_list(int argc, char **argv) print_services(list.targets[i]); } out: - del_srv_list(&list); + del_svc_list(&list); return ret; }