rc: add support for scanning USE_PROCD and skip running if not supported

Running check is supported only in procd scripts. This cause prolonged
execution time since the function needs to timeout.

To fix this check if the script USE_PROCD and run running check only if
supported.

Also provide running info only if the running check is supported.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
Christian Marangi 2023-01-31 15:32:59 +01:00
parent 4de3f02e31
commit 5577db9208
No known key found for this signature in database
GPG key ID: AC001D09ADBFEAD7

9
rc.c
View file

@ -47,6 +47,7 @@ struct rc_list_context {
int stop; int stop;
bool enabled; bool enabled;
bool running; bool running;
bool use_procd;
} entry; } entry;
}; };
@ -81,6 +82,7 @@ static void rc_list_add_table(struct rc_list_context *c)
if (c->entry.stop >= 0) 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);
if (c->entry.use_procd)
blobmsg_add_u8(c->buf, "running", c->entry.running); blobmsg_add_u8(c->buf, "running", c->entry.running);
blobmsg_close_table(c->buf, e); blobmsg_close_table(c->buf, e);
@ -112,6 +114,9 @@ static int rc_list_exec(struct rc_list_context *c, const char *action, uloop_pro
case -1: case -1:
return -errno; return -errno;
case 0: case 0:
if (!c->entry.use_procd)
exit(-EOPNOTSUPP);
/* Set stdin, stdout & stderr to /dev/null */ /* Set stdin, stdout & stderr to /dev/null */
fd = open("/dev/null", O_RDWR); fd = open("/dev/null", O_RDWR);
if (fd >= 0) { if (fd >= 0) {
@ -192,13 +197,15 @@ static void rc_list_readdir(struct rc_list_context *c)
int count = 0; int count = 0;
beginning = true; beginning = true;
while ((c->entry.start < 0 || c->entry.stop < 0) && while ((c->entry.start < 0 || c->entry.stop < 0 || !c->entry.use_procd) &&
count <= 10 && fgets(line, sizeof(line), fp)) { count <= 10 && 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);
} else if (!strncmp(line, "STOP=", 5)) { } else if (!strncmp(line, "STOP=", 5)) {
c->entry.stop = strtoul(line + 5, NULL, 0); c->entry.stop = strtoul(line + 5, NULL, 0);
} else if (!c->skip_running_check && !strncmp(line, "USE_PROCD=", 10)) {
c->entry.use_procd = !!strtoul(line + 10, NULL, 0);
} }
count++; count++;
} }