diff --git a/cmd/Makemodule.am b/cmd/Makemodule.am index 5c9ed56..e472106 100644 --- a/cmd/Makemodule.am +++ b/cmd/Makemodule.am @@ -19,7 +19,7 @@ SRVHEADERS = cmd/service/servicecmd.h service_SOURCES = cmd/service/servicecmd.c cmd/service/help.c service_SOURCES += cmd/service/enable.c cmd/service/disable.c service_SOURCES += cmd/service/dumpscript.c cmd/service/list.c -service_SOURCES += cmd/service/status.c +service_SOURCES += cmd/service/status.c cmd/service/loadsvc.c service_SOURCES += $(SRVHEADERS) service_CPPFLAGS = $(AM_CPPFLAGS) service_CFLAGS = $(AM_CFLAGS) diff --git a/cmd/service/dumpscript.c b/cmd/service/dumpscript.c index 7102b5c..23966ee 100644 --- a/cmd/service/dumpscript.c +++ b/cmd/service/dumpscript.c @@ -6,24 +6,6 @@ #include #include "servicecmd.h" -#include "service.h" - -static service_t *try_load(const char *directory, const char *filename) -{ - service_t *svc; - int dirfd; - - dirfd = open(directory, O_RDONLY | O_DIRECTORY); - - if (dirfd < 0) { - perror(directory); - return NULL; - } - - svc = rdsvc(dirfd, filename, 0); - close(dirfd); - return svc; -} enum { NEED_QUOTES = 0x01, @@ -111,7 +93,7 @@ static int cmd_dumpscript(int argc, char **argv) strcat(filename, argv[i]); } - svc = try_load(SVCDIR, filename); + svc = loadsvc(SVCDIR, filename, 0); if (svc == NULL) { fprintf(stderr, "Could not load service '%s'\n", filename); diff --git a/cmd/service/loadsvc.c b/cmd/service/loadsvc.c new file mode 100644 index 0000000..bbd15f8 --- /dev/null +++ b/cmd/service/loadsvc.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: ISC */ +#include "servicecmd.h" + +#include +#include +#include + +service_t *loadsvc(const char *directory, const char *filename, int flags) +{ + service_t *svc; + int dirfd; + + dirfd = open(directory, O_RDONLY | O_DIRECTORY); + + if (dirfd < 0) { + perror(directory); + return NULL; + } + + svc = rdsvc(dirfd, filename, flags); + close(dirfd); + return svc; +} diff --git a/cmd/service/servicecmd.h b/cmd/service/servicecmd.h index a8d3b2a..e7cc998 100644 --- a/cmd/service/servicecmd.h +++ b/cmd/service/servicecmd.h @@ -7,6 +7,7 @@ #include #include +#include "service.h" #include "util.h" /* @@ -38,6 +39,8 @@ typedef struct command_t { /* Global list of available commands */ extern command_t *commands; +service_t *loadsvc(const char *directory, const char *filename, int flags); + /* Implemented in servicecmd.c. Prints program usage message and terminates with the given exit status.