mirror of
https://github.com/pygos/init.git
synced 2024-11-21 18:59:46 +01:00
Seperate service loading/error loging from dumpscript command
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
065d3b678d
commit
1850f31d6d
4 changed files with 28 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
23
cmd/service/loadsvc.c
Normal file
23
cmd/service/loadsvc.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue