Add support for including .conf files.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2014-04-19 22:56:19 +02:00
1 parent be3257f805
commit 62287f8fcc
3 files changed
+42 -11

No files matched your search

+35 -8
View File
@@ -86,20 +86,24 @@ int parse_runlevels(char *runlevels)
return bitmask; return bitmask;
} }
void parse_finit_conf(char *file) static int parse_conf(char *file)
{ {
FILE *fp; FILE *fp;
char line[LINE_SIZE]; char line[LINE_SIZE];
char cmd[CMD_SIZE]; char cmd[CMD_SIZE];
username = strdup(DEFUSER);
hostname = strdup(DEFHOST);
rcsd = strdup(FINIT_RCSD);
if ((fp = fopen(file, "r")) != NULL) {
char *x; char *x;
const char *err = NULL; const char *err = NULL;
/* Assume absolute path is given ... */
fp = fopen(file, "r");
if (!fp) {
/* ... if it fails, try /etc/finit.d/ as prefix */
snprintf(line, sizeof(line), "%s/%s", rcsd, file);
fp = fopen(file, "r");
if (!fp)
return 1;
}
_d("Parse %s ...", file); _d("Parse %s ...", file);
while (!feof(fp)) { while (!feof(fp)) {
if (!fgets(line, sizeof(line), fp)) if (!fgets(line, sizeof(line), fp))
@@ -158,11 +162,23 @@ void parse_finit_conf(char *file)
network = strdup(strip_line(x)); network = strdup(strip_line(x));
continue; continue;
} }
/* This is the directory from which executable scripts and
* any finit include files are read, default /etc/finit.d/ */
if (MATCH_CMD(line, "runparts ", x)) { if (MATCH_CMD(line, "runparts ", x)) {
if (rcsd) free(rcsd); if (rcsd) free(rcsd);
rcsd = strdup(strip_line(x)); rcsd = strdup(strip_line(x));
continue; continue;
} }
/* Parse any include file, use rcsd if absolute path not given. */
if (MATCH_CMD(line, "include ", x)) {
char *file = strip_line(x);
char buf[60];
snprintf(buf, sizeof(buf), "Loading include file %s", file);
print_desc("", buf);
print_result(parse_conf(file));
continue;
}
if (MATCH_CMD(line, "startx ", x)) { if (MATCH_CMD(line, "startx ", x)) {
svc_register(SVC_CMD_SERVICE, strip_line(x), username); svc_register(SVC_CMD_SERVICE, strip_line(x), username);
continue; continue;
@@ -219,8 +235,19 @@ void parse_finit_conf(char *file)
continue; continue;
} }
} }
fclose(fp); fclose(fp);
}
return 0;
}
int parse_finit_conf(char *file)
{
username = strdup(DEFUSER);
hostname = strdup(DEFHOST);
rcsd = strdup(FINIT_RCSD);
return parse_conf(file);
} }
+6 -2
View File
@@ -160,6 +160,8 @@ static void banner(void)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int result;
if (getpid() != 1) if (getpid() != 1)
return client(argc, argv); return client(argc, argv);
@@ -200,14 +202,16 @@ int main(int argc, char* argv[])
/* /*
* Parse configuration file * Parse configuration file
*/ */
parse_finit_conf(FINIT_CONF); result = parse_finit_conf(FINIT_CONF);
print_desc("Loading " FINIT_CONF, NULL);
print_result(result);
/* /*
* Load plugins. Must run after finit.conf has registered * Load plugins. Must run after finit.conf has registered
* all services, or service plugins won't have anything to * all services, or service plugins won't have anything to
* hook on to. * hook on to.
*/ */
print_desc("", "Loading Finit plugins"); print_desc("Loading Finit plugins", NULL);
print_result(plugin_load_all(PLUGIN_PATH)); print_result(plugin_load_all(PLUGIN_PATH));
/* /*
+1 -1
View File
@@ -92,7 +92,7 @@ extern char *__progname;
/* conf.c */ /* conf.c */
int parse_runlevels (char *runlevels); int parse_runlevels (char *runlevels);
void parse_finit_conf (char *file); int parse_finit_conf (char *file);
#endif /* FINIT_H_ */ #endif /* FINIT_H_ */