mirror of
https://github.com/troglobit/finit.git
synced 2026-11-01 13:10:32 +00:00
Minor refactor, reuse MATCH_CMD() from conf.c in service_register()
When adding a new service option recently, I copy-pasted and forgot to update the length argument to strncasecmp(), so it was time to fix that once and for all. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
561c88a868
commit
4a8ca787d3
3 files changed
+38
-34
No files matched your search
@@ -48,8 +48,6 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define BOOTSTRAP (runlevel == 0)
|
#define BOOTSTRAP (runlevel == 0)
|
||||||
#define MATCH_CMD(l, c, x) \
|
|
||||||
(!strncasecmp(l, c, strlen(c)) && (x = (l) + strlen(c)))
|
|
||||||
|
|
||||||
int logfile_size_max = 200000; /* 200 kB */
|
int logfile_size_max = 200000; /* 200 kB */
|
||||||
int logfile_count_max = 5;
|
int logfile_count_max = 5;
|
||||||
|
|||||||
@@ -29,6 +29,9 @@
|
|||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
#define SERVICE_INTERVAL_DEFAULT 300000 /* 5 mins */
|
#define SERVICE_INTERVAL_DEFAULT 300000 /* 5 mins */
|
||||||
|
#define MATCH_CMD(l, c, x) \
|
||||||
|
(!strncasecmp(l, c, strlen(c)) && (x = (l) + strlen(c)))
|
||||||
|
|
||||||
extern int service_interval;
|
extern int service_interval;
|
||||||
|
|
||||||
int api_init (uev_ctx_t *ctx);
|
int api_init (uev_ctx_t *ctx);
|
||||||
|
|||||||
+35
-32
@@ -1144,7 +1144,6 @@ static void parse_cmdline_args(svc_t *svc, char *cmd)
|
|||||||
svc->args_dirty = (diff > 0);
|
svc->args_dirty = (diff > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* service_register - Register service, task or run commands
|
* service_register - Register service, task or run commands
|
||||||
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
* @type: %SVC_TYPE_SERVICE(0), %SVC_TYPE_TASK(1), %SVC_TYPE_RUN(2)
|
||||||
@@ -1253,6 +1252,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (cmd) {
|
while (cmd) {
|
||||||
|
char *arg;
|
||||||
|
|
||||||
if (type == SVC_TYPE_TTY && cmd[0] == '@')
|
if (type == SVC_TYPE_TTY && cmd[0] == '@')
|
||||||
break; /* @console */
|
break; /* @console */
|
||||||
|
|
||||||
@@ -1264,46 +1265,48 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
cond = &cmd[1];
|
cond = &cmd[1];
|
||||||
else if (cmd[0] == ':') /* :ID */
|
else if (cmd[0] == ':') /* :ID */
|
||||||
id = &cmd[1];
|
id = &cmd[1];
|
||||||
else if (!strncasecmp(cmd, "log", 3))
|
else if (MATCH_CMD(cmd, "log", arg))
|
||||||
log = cmd;
|
log = cmd;
|
||||||
else if (!strncasecmp(cmd, "pid", 3))
|
else if (MATCH_CMD(cmd, "pid", arg))
|
||||||
pid = cmd;
|
pid = cmd;
|
||||||
else if (!strncasecmp(cmd, "name:", 5))
|
else if (MATCH_CMD(cmd, "name:", arg))
|
||||||
name = cmd;
|
name = cmd;
|
||||||
else if (!strncasecmp(cmd, "type:forking", 10))
|
else if (MATCH_CMD(cmd, "type:forking", arg))
|
||||||
forking = 1;
|
forking = 1;
|
||||||
else if (!strncasecmp(cmd, "manual:yes", 10))
|
else if (MATCH_CMD(cmd, "manual:yes", arg))
|
||||||
manual = 1;
|
manual = 1;
|
||||||
else if (!strncasecmp(cmd, "restart:always", 14))
|
else if (MATCH_CMD(cmd, "restart:", arg)) {
|
||||||
restart_max = -1;
|
if (MATCH_CMD(arg, "always", arg))
|
||||||
else if (!strncasecmp(cmd, "restart:", 8))
|
restart_max = -1;
|
||||||
restart_max = atoi(&cmd[8]);
|
else
|
||||||
else if (!strncasecmp(cmd, "restarttmo:", 11)) /* compat alias */
|
restart_max = atoi(arg);
|
||||||
restart_tmo = atoi(&cmd[11]) * 1000;
|
}
|
||||||
else if (!strncasecmp(cmd, "restart_sec:", 12))
|
else if (MATCH_CMD(cmd, "restarttmo:", arg)) /* compat alias */
|
||||||
restart_tmo = atoi(&cmd[12]) * 1000;
|
restart_tmo = atoi(arg) * 1000;
|
||||||
else if (!strncasecmp(cmd, "norestart", 9))
|
else if (MATCH_CMD(cmd, "restart_sec:", arg))
|
||||||
|
restart_tmo = atoi(arg) * 1000;
|
||||||
|
else if (MATCH_CMD(cmd, "norestart", arg))
|
||||||
restart_max = 0;
|
restart_max = 0;
|
||||||
else if (!strncasecmp(cmd, "oncrash:", 8)) {
|
else if (MATCH_CMD(cmd, "oncrash:", arg)) {
|
||||||
if (!strncasecmp(&cmd[8], "reboot", 6))
|
if (MATCH_CMD(arg, "reboot", arg))
|
||||||
oncrash_action = SVC_ONCRASH_REBOOT;
|
oncrash_action = SVC_ONCRASH_REBOOT;
|
||||||
}
|
}
|
||||||
else if (!strncasecmp(cmd, "respawn", 7))
|
else if (MATCH_CMD(cmd, "respawn", arg))
|
||||||
respawn = 1;
|
respawn = 1;
|
||||||
else if (!strncasecmp(cmd, "halt:", 5))
|
else if (MATCH_CMD(cmd, "halt:", arg))
|
||||||
halt = &cmd[5];
|
halt = arg;
|
||||||
else if (!strncasecmp(cmd, "kill:", 5))
|
else if (MATCH_CMD(cmd, "kill:", arg))
|
||||||
delay = &cmd[5];
|
delay = arg;
|
||||||
else if (!strncasecmp(cmd, "pre:", 4))
|
else if (MATCH_CMD(cmd, "pre:", arg))
|
||||||
pre_script = &cmd[4];
|
pre_script = arg;
|
||||||
else if (!strncasecmp(cmd, "post:", 5))
|
else if (MATCH_CMD(cmd, "post:", arg))
|
||||||
post_script = &cmd[5];
|
post_script = arg;
|
||||||
else if (!strncasecmp(cmd, "env:", 4))
|
else if (MATCH_CMD(cmd, "env:", arg))
|
||||||
env = &cmd[4];
|
env = arg;
|
||||||
else if (!strncasecmp(cmd, "cgroup:", 7))
|
else if (MATCH_CMD(cmd, "cgroup:", arg))
|
||||||
cgroup = &cmd[7]; /* only settings */
|
cgroup = arg; /* only settings */
|
||||||
else if (!strncasecmp(cmd, "cgroup.", 7))
|
else if (MATCH_CMD(cmd, "cgroup.", arg))
|
||||||
cgroup = &cmd[6]; /* with group */
|
cgroup = arg; /* with group */
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user