mirror of
https://github.com/pygos/init.git
synced 2024-11-22 11:19:45 +01:00
Add flags to selectively skip fields in service files
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
160cd6b6aa
commit
720220a3c3
6 changed files with 43 additions and 23 deletions
|
@ -49,7 +49,7 @@ static service_t *try_load(const char *directory, const char *filename)
|
||||||
if (type != S_IFREG && type != S_IFLNK)
|
if (type != S_IFREG && type != S_IFLNK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
svc = rdsvc(dirfd, filename);
|
svc = rdsvc(dirfd, filename, 0);
|
||||||
close(dirfd);
|
close(dirfd);
|
||||||
return svc;
|
return svc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,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)) {
|
if (svcscan(SVCDIR, &list, 0)) {
|
||||||
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;
|
||||||
|
|
|
@ -193,7 +193,7 @@ int main(void)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (svcscan(SVCDIR, &cfg)) {
|
if (svcscan(SVCDIR, &cfg, 0)) {
|
||||||
fputs("Error reading service list from " SVCDIR "\n"
|
fputs("Error reading service list from " SVCDIR "\n"
|
||||||
"Trying to continue anyway\n", stderr);
|
"Trying to continue anyway\n", stderr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,13 @@ 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 */
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct exec_t {
|
typedef struct exec_t {
|
||||||
struct exec_t *next;
|
struct exec_t *next;
|
||||||
int argc; /* number of elements in argument vector */
|
int argc; /* number of elements in argument vector */
|
||||||
|
@ -83,7 +90,7 @@ typedef struct {
|
||||||
/*
|
/*
|
||||||
Read a service from a file.
|
Read a service from a file.
|
||||||
*/
|
*/
|
||||||
service_t *rdsvc(int dirfd, const char *filename);
|
service_t *rdsvc(int dirfd, const char *filename, int flags);
|
||||||
|
|
||||||
void delsvc(service_t *svc);
|
void delsvc(service_t *svc);
|
||||||
|
|
||||||
|
@ -94,7 +101,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 svcscan(const char *directory, service_list_t *list, int flags);
|
||||||
|
|
||||||
void del_svc_list(service_list_t *list);
|
void del_svc_list(service_list_t *list);
|
||||||
|
|
||||||
|
|
|
@ -204,15 +204,17 @@ static const struct svc_param {
|
||||||
|
|
||||||
unsigned int allow_block : 1;
|
unsigned int allow_block : 1;
|
||||||
|
|
||||||
|
int flags;
|
||||||
|
|
||||||
int (*handle)(service_t *svc, char *arg, rdline_t *rd);
|
int (*handle)(service_t *svc, char *arg, rdline_t *rd);
|
||||||
} svc_params[] = {
|
} svc_params[] = {
|
||||||
{ "description", 0, svc_desc },
|
{ "description", 0, 0, svc_desc },
|
||||||
{ "exec", 1, svc_exec },
|
{ "exec", 1, RDSVC_NO_EXEC, svc_exec },
|
||||||
{ "type", 0, svc_type },
|
{ "type", 0, 0, svc_type },
|
||||||
{ "target", 0, svc_target },
|
{ "target", 0, 0, svc_target },
|
||||||
{ "tty", 0, svc_tty },
|
{ "tty", 0, RDSVC_NO_CTTY, svc_tty },
|
||||||
{ "before", 0, svc_before },
|
{ "before", 0, RDSVC_NO_DEPS, svc_before },
|
||||||
{ "after", 0, svc_after },
|
{ "after", 0, RDSVC_NO_DEPS, svc_after },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int splitkv(rdline_t *rd, char **k, char **v)
|
static int splitkv(rdline_t *rd, char **k, char **v)
|
||||||
|
@ -257,7 +259,7 @@ static const struct svc_param *find_param(rdline_t *rd, const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
service_t *rdsvc(int dirfd, const char *filename)
|
service_t *rdsvc(int dirfd, const char *filename, int flags)
|
||||||
{
|
{
|
||||||
const struct svc_param *p;
|
const struct svc_param *p;
|
||||||
const char *arg, *args[1];
|
const char *arg, *args[1];
|
||||||
|
@ -289,9 +291,11 @@ service_t *rdsvc(int dirfd, const char *filename)
|
||||||
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);
|
||||||
|
|
||||||
|
@ -306,13 +310,19 @@ service_t *rdsvc(int dirfd, const char *filename)
|
||||||
if (p->allow_block && *value == '{') {
|
if (p->allow_block && *value == '{') {
|
||||||
for (++value; *value == ' '; ++value)
|
for (++value; *value == ' '; ++value)
|
||||||
;
|
;
|
||||||
if (*value != '\0' && p->handle(svc, value, &rd))
|
|
||||||
|
if (!(flags & p->flags)) {
|
||||||
|
if (*value != '\0' &&
|
||||||
|
p->handle(svc, value, &rd)) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while ((ret = rdline(&rd)) == 0) {
|
while ((ret = rdline(&rd)) == 0) {
|
||||||
if (strcmp(rd.buffer, "}") == 0)
|
if (strcmp(rd.buffer, "}") == 0)
|
||||||
break;
|
break;
|
||||||
|
if (flags & p->flags)
|
||||||
|
continue;
|
||||||
if (p->handle(svc, rd.buffer, &rd))
|
if (p->handle(svc, rd.buffer, &rd))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +331,10 @@ service_t *rdsvc(int dirfd, const char *filename)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
goto fail_bra;
|
goto fail_bra;
|
||||||
} else if (p->handle(svc, value, &rd)) {
|
} else {
|
||||||
|
if (flags & p->flags)
|
||||||
|
continue;
|
||||||
|
if (p->handle(svc, value, &rd))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
int svcscan(const char *directory, service_list_t *list)
|
int svcscan(const char *directory, service_list_t *list, int flags)
|
||||||
{
|
{
|
||||||
int i, dfd, type, ret = 0;
|
int i, dfd, type, ret = 0;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
|
@ -82,7 +82,7 @@ int svcscan(const char *directory, service_list_t *list)
|
||||||
if (type != S_IFREG && type != S_IFLNK)
|
if (type != S_IFREG && type != S_IFLNK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
svc = rdsvc(dfd, ent->d_name);
|
svc = rdsvc(dfd, ent->d_name, flags);
|
||||||
if (svc == NULL) {
|
if (svc == NULL) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue