mirror of
https://github.com/pygos/init.git
synced 2024-11-23 19:46:42 +01:00
Cleanup: remove rdsvc flags
With the previous changes, there were only used by the status command. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
5f28289731
commit
70ea16b0b4
9 changed files with 22 additions and 44 deletions
|
@ -93,7 +93,7 @@ static int cmd_dumpscript(int argc, char **argv)
|
||||||
strcat(filename, argv[i]);
|
strcat(filename, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
svc = loadsvc(SVCDIR, filename, 0);
|
svc = loadsvc(SVCDIR, filename);
|
||||||
|
|
||||||
if (svc == NULL) {
|
if (svc == NULL) {
|
||||||
fprintf(stderr, "Could not load service '%s'\n", filename);
|
fprintf(stderr, "Could not load service '%s'\n", filename);
|
||||||
|
|
|
@ -24,7 +24,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 (svcscan(SVCDIR, &list, 0)) {
|
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;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
service_t *loadsvc(const char *directory, const char *filename, int flags)
|
service_t *loadsvc(const char *directory, const char *filename)
|
||||||
{
|
{
|
||||||
service_t *svc;
|
service_t *svc;
|
||||||
int dirfd;
|
int dirfd;
|
||||||
|
@ -17,7 +17,7 @@ service_t *loadsvc(const char *directory, const char *filename, int flags)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
svc = rdsvc(dirfd, filename, flags);
|
svc = rdsvc(dirfd, filename);
|
||||||
close(dirfd);
|
close(dirfd);
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ typedef struct command_t {
|
||||||
/* Global list of available commands */
|
/* Global list of available commands */
|
||||||
extern command_t *commands;
|
extern command_t *commands;
|
||||||
|
|
||||||
service_t *loadsvc(const char *directory, const char *filename, int flags);
|
service_t *loadsvc(const char *directory, const char *filename);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Implemented in servicecmd.c. Prints program usage message and
|
Implemented in servicecmd.c. Prints program usage message and
|
||||||
|
|
|
@ -128,9 +128,7 @@ static int cmd_status(int argc, char **argv)
|
||||||
printf("\tTemplate name: %s\n", resp.service_name);
|
printf("\tTemplate name: %s\n", resp.service_name);
|
||||||
printf("\tExit status: %d\n", resp.exit_status);
|
printf("\tExit status: %d\n", resp.exit_status);
|
||||||
|
|
||||||
svc = loadsvc(SVCDIR, resp.filename,
|
svc = loadsvc(SVCDIR, resp.filename);
|
||||||
RDSVC_NO_EXEC | RDSVC_NO_DEPS |
|
|
||||||
RDSVC_NO_CTTY | RDSVC_NO_FNAME);
|
|
||||||
|
|
||||||
if (svc == NULL) {
|
if (svc == NULL) {
|
||||||
fputs("\tError loading service file\n", stdout);
|
fputs("\tError loading service file\n", stdout);
|
||||||
|
|
|
@ -175,7 +175,7 @@ void supervisor_init(void)
|
||||||
{
|
{
|
||||||
int status = STATUS_OK;
|
int status = STATUS_OK;
|
||||||
|
|
||||||
if (svcscan(SVCDIR, &cfg, 0))
|
if (svcscan(SVCDIR, &cfg))
|
||||||
status = STATUS_FAIL;
|
status = STATUS_FAIL;
|
||||||
|
|
||||||
target = TGT_BOOT;
|
target = TGT_BOOT;
|
||||||
|
@ -191,7 +191,7 @@ void supervisor_reload_config(void)
|
||||||
service_t *svc;
|
service_t *svc;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (svcscan(SVCDIR, &newcfg, 0))
|
if (svcscan(SVCDIR, &newcfg))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < TGT_MAX; ++i) {
|
for (i = 0; i < TGT_MAX; ++i) {
|
||||||
|
|
|
@ -35,14 +35,6 @@ enum {
|
||||||
TGT_MAX
|
TGT_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
RDSVC_NO_FNAME = 0x01, /* do not store a copy of the filename */
|
|
||||||
RDSVC_NO_EXEC = 0x02, /* do not store executable script */
|
|
||||||
RDSVC_NO_CTTY = 0x04, /* do not store the controlling tty */
|
|
||||||
RDSVC_NO_DEPS = 0x08, /* do not store dependencies */
|
|
||||||
RDSVC_NO_DESC = 0x10, /* do not store description */
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/* truncate stdout */
|
/* truncate stdout */
|
||||||
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
SVC_FLAG_TRUNCATE_OUT = 0x01,
|
||||||
|
@ -87,7 +79,7 @@ typedef struct {
|
||||||
/*
|
/*
|
||||||
Read a service from a file.
|
Read a service from a file.
|
||||||
*/
|
*/
|
||||||
service_t *rdsvc(int dirfd, const char *filename, int flags);
|
service_t *rdsvc(int dirfd, const char *filename);
|
||||||
|
|
||||||
void delsvc(service_t *svc);
|
void delsvc(service_t *svc);
|
||||||
|
|
||||||
|
@ -98,7 +90,7 @@ void delsvc(service_t *svc);
|
||||||
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 svcscan(const char *directory, service_list_t *list, int flags);
|
int svcscan(const char *directory, service_list_t *list);
|
||||||
|
|
||||||
void del_svc_list(service_list_t *list);
|
void del_svc_list(service_list_t *list);
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,7 @@ static int try_pack_argv(char *str, rdline_t *rd)
|
||||||
static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
{
|
{
|
||||||
service_t *svc = user;
|
service_t *svc = user;
|
||||||
|
(void)flags;
|
||||||
if (flags & RDSVC_NO_DESC)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (try_unescape(arg, rd))
|
if (try_unescape(arg, rd))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -59,9 +57,7 @@ static int svc_desc(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
static int svc_tty(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
{
|
{
|
||||||
service_t *svc = user;
|
service_t *svc = user;
|
||||||
|
(void)flags;
|
||||||
if (flags & RDSVC_NO_CTTY)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
if (strncmp(arg, "truncate", 8) == 0 && isspace(arg[8])) {
|
||||||
svc->flags |= SVC_FLAG_TRUNCATE_OUT;
|
svc->flags |= SVC_FLAG_TRUNCATE_OUT;
|
||||||
|
@ -81,12 +77,10 @@ static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
{
|
{
|
||||||
service_t *svc = user;
|
service_t *svc = user;
|
||||||
exec_t *e, *end;
|
exec_t *e, *end;
|
||||||
|
(void)flags;
|
||||||
|
|
||||||
svc->flags |= SVC_FLAG_HAS_EXEC;
|
svc->flags |= SVC_FLAG_HAS_EXEC;
|
||||||
|
|
||||||
if (flags & RDSVC_NO_EXEC)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
e = calloc(1, sizeof(*e) + strlen(arg) + 1);
|
e = calloc(1, sizeof(*e) + strlen(arg) + 1);
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
fprintf(stderr, "%s: %zu: out of memory\n",
|
fprintf(stderr, "%s: %zu: out of memory\n",
|
||||||
|
@ -113,9 +107,7 @@ static int svc_exec(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
{
|
{
|
||||||
service_t *svc = user;
|
service_t *svc = user;
|
||||||
|
(void)flags;
|
||||||
if (flags & RDSVC_NO_DEPS)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (svc->before != NULL) {
|
if (svc->before != NULL) {
|
||||||
fprintf(stderr, "%s: %zu: 'before' dependencies respecified\n",
|
fprintf(stderr, "%s: %zu: 'before' dependencies respecified\n",
|
||||||
|
@ -134,9 +126,7 @@ static int svc_before(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
static int svc_after(void *user, char *arg, rdline_t *rd, int flags)
|
||||||
{
|
{
|
||||||
service_t *svc = user;
|
service_t *svc = user;
|
||||||
|
(void)flags;
|
||||||
if (flags & RDSVC_NO_DEPS)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (svc->after != NULL) {
|
if (svc->after != NULL) {
|
||||||
fprintf(stderr, "%s: %zu: 'after' dependencies respecified\n",
|
fprintf(stderr, "%s: %zu: 'after' dependencies respecified\n",
|
||||||
|
@ -231,7 +221,7 @@ static const cfg_param_t svc_params[] = {
|
||||||
{ "after", 0, svc_after },
|
{ "after", 0, svc_after },
|
||||||
};
|
};
|
||||||
|
|
||||||
service_t *rdsvc(int dirfd, const char *filename, int flags)
|
service_t *rdsvc(int dirfd, const char *filename)
|
||||||
{
|
{
|
||||||
const char *arg, *args[1];
|
const char *arg, *args[1];
|
||||||
service_t *svc = NULL;
|
service_t *svc = NULL;
|
||||||
|
@ -255,17 +245,15 @@ service_t *rdsvc(int dirfd, const char *filename, int flags)
|
||||||
if (svc == NULL)
|
if (svc == NULL)
|
||||||
goto fail_oom;
|
goto fail_oom;
|
||||||
|
|
||||||
if (!(flags & RDSVC_NO_FNAME)) {
|
svc->fname = strdup(filename);
|
||||||
svc->fname = strdup(filename);
|
if (svc->fname == NULL)
|
||||||
if (svc->fname == NULL)
|
goto fail_oom;
|
||||||
goto fail_oom;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(svc->name, filename, nlen);
|
memcpy(svc->name, filename, nlen);
|
||||||
svc->id = -1;
|
svc->id = -1;
|
||||||
|
|
||||||
if (rdcfg(svc, &rd, svc_params,
|
if (rdcfg(svc, &rd, svc_params,
|
||||||
sizeof(svc_params) / sizeof(svc_params[0]), flags)) {
|
sizeof(svc_params) / sizeof(svc_params[0]), 0)) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
int svcscan(const char *directory, service_list_t *list, int flags)
|
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;
|
||||||
|
@ -66,7 +66,7 @@ int svcscan(const char *directory, service_list_t *list, int flags)
|
||||||
if (type != S_IFREG && type != S_IFLNK)
|
if (type != S_IFREG && type != S_IFLNK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
svc = rdsvc(dfd, ent->d_name, flags);
|
svc = rdsvc(dfd, ent->d_name);
|
||||||
if (svc == NULL) {
|
if (svc == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue