mirror of
https://github.com/troglobit/finit.git
synced 2026-11-29 21:08:21 +00:00
Add support for calling initctl with process name as well as JOBID
This patch makes it possible to communicate process name or JOB[:ID] from initctl to Finit. When the process name translates into a service with multiple instances Finit applies the requested command to all instances. For example, two Dropbear SSH services running on two different ports, calling `initctl stop dropbear` stops both services. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5d2172eac8
commit
577622c945
7 files changed
+166
-107
No files matched your search
@@ -32,6 +32,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <utmp.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -122,6 +123,42 @@ int atonum(char *str)
|
||||
return val;
|
||||
}
|
||||
|
||||
static int encode(int lvl)
|
||||
{
|
||||
if (!lvl) return 0;
|
||||
return lvl + '0';
|
||||
}
|
||||
|
||||
void runlevel_set(int pre, int now)
|
||||
{
|
||||
struct utmp utent;
|
||||
|
||||
utent.ut_type = RUN_LVL;
|
||||
utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF);
|
||||
strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user));
|
||||
|
||||
setutent();
|
||||
pututline(&utent);
|
||||
endutent();
|
||||
}
|
||||
|
||||
int runlevel_get(void)
|
||||
{
|
||||
int lvl = '?'; /* Non-existing runlevel */
|
||||
struct utmp *utent;
|
||||
|
||||
setutent();
|
||||
while ((utent = getutent())) {
|
||||
if (utent->ut_type == RUN_LVL) {
|
||||
lvl = utent->ut_pid & 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
endutent();
|
||||
|
||||
return lvl - '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* runlevel_string - Convert a bit encoded runlevel to .conf syntax
|
||||
* @levels: Bit encoded runlevels
|
||||
|
||||
Reference in new issue
Block a user