rc: support init.d scripts with START=0
Use negative value (instead of 0) to indicate missing START. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
parent
646daa0bec
commit
3fea655981
1 changed files with 12 additions and 8 deletions
20
rc.c
20
rc.c
|
@ -43,8 +43,8 @@ struct rc_list_context {
|
||||||
struct {
|
struct {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
const char *d_name;
|
const char *d_name;
|
||||||
unsigned int start;
|
int start;
|
||||||
unsigned int stop;
|
int stop;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
bool running;
|
bool running;
|
||||||
} entry;
|
} entry;
|
||||||
|
@ -76,9 +76,9 @@ static void rc_list_add_table(struct rc_list_context *c)
|
||||||
|
|
||||||
e = blobmsg_open_table(c->buf, c->entry.d_name);
|
e = blobmsg_open_table(c->buf, c->entry.d_name);
|
||||||
|
|
||||||
if (c->entry.start)
|
if (c->entry.start >= 0)
|
||||||
blobmsg_add_u16(c->buf, "start", c->entry.start);
|
blobmsg_add_u16(c->buf, "start", c->entry.start);
|
||||||
if (c->entry.stop)
|
if (c->entry.stop >= 0)
|
||||||
blobmsg_add_u16(c->buf, "stop", c->entry.stop);
|
blobmsg_add_u16(c->buf, "stop", c->entry.stop);
|
||||||
blobmsg_add_u8(c->buf, "enabled", c->entry.enabled);
|
blobmsg_add_u8(c->buf, "enabled", c->entry.enabled);
|
||||||
blobmsg_add_u8(c->buf, "running", c->entry.running);
|
blobmsg_add_u8(c->buf, "running", c->entry.running);
|
||||||
|
@ -174,6 +174,8 @@ static void rc_list_readdir(struct rc_list_context *c)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
memset(&c->entry, 0, sizeof(c->entry));
|
memset(&c->entry, 0, sizeof(c->entry));
|
||||||
|
c->entry.start = -1;
|
||||||
|
c->entry.stop = -1;
|
||||||
|
|
||||||
snprintf(c->entry.path, sizeof(c->entry.path), "/etc/init.d/%s", e->d_name);
|
snprintf(c->entry.path, sizeof(c->entry.path), "/etc/init.d/%s", e->d_name);
|
||||||
if (rc_check_script(c->entry.path))
|
if (rc_check_script(c->entry.path))
|
||||||
|
@ -189,7 +191,7 @@ static void rc_list_readdir(struct rc_list_context *c)
|
||||||
bool beginning;
|
bool beginning;
|
||||||
|
|
||||||
beginning = true;
|
beginning = true;
|
||||||
while (!c->entry.start && !c->entry.stop && fgets(line, sizeof(line), fp)) {
|
while (c->entry.start < 0 && c->entry.stop < 0 && fgets(line, sizeof(line), fp)) {
|
||||||
if (beginning) {
|
if (beginning) {
|
||||||
if (!strncmp(line, "START=", 6)) {
|
if (!strncmp(line, "START=", 6)) {
|
||||||
c->entry.start = strtoul(line + 6, NULL, 0);
|
c->entry.start = strtoul(line + 6, NULL, 0);
|
||||||
|
@ -202,9 +204,11 @@ static void rc_list_readdir(struct rc_list_context *c)
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "/etc/rc.d/S%02d%s", c->entry.start, c->entry.d_name);
|
if (c->entry.start >= 0) {
|
||||||
if (!stat(path, &s) && (s.st_mode & S_IXUSR))
|
snprintf(path, sizeof(path), "/etc/rc.d/S%02d%s", c->entry.start, c->entry.d_name);
|
||||||
c->entry.enabled = true;
|
if (!stat(path, &s) && (s.st_mode & S_IXUSR))
|
||||||
|
c->entry.enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc_list_exec(c, "running", rc_list_exec_running_cb))
|
if (rc_list_exec(c, "running", rc_list_exec_running_cb))
|
||||||
|
|
Loading…
Reference in a new issue