aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2019-03-19 23:52:28 +0100
committerDavid Oberhollenzer <goliath@infraroot.at>2019-03-19 23:53:49 +0100
commit1850f31d6d1d88621b6891ed05c283e26620a242 (patch)
tree3ab15b200b92226da3f8ee99af8b70133c3468fa /cmd
parent065d3b678d58e9e758d19e015b1e25a79a8aaec6 (diff)
Seperate service loading/error loging from dumpscript command
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Makemodule.am2
-rw-r--r--cmd/service/dumpscript.c20
-rw-r--r--cmd/service/loadsvc.c23
-rw-r--r--cmd/service/servicecmd.h3
4 files changed, 28 insertions, 20 deletions
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 <errno.h>
#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 <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+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 <stdio.h>
#include <ctype.h>
+#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.