mirror of
https://github.com/troglobit/finit.git
synced 2026-10-14 10:19:36 +00:00
Factor out runlevel handling to new UTMP API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
7cdd42195b
commit
a016359891
4 files changed
+35
-19
No files matched your search
+2
-1
@@ -1,7 +1,8 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
sbin_PROGRAMS = finit initctl reboot
|
||||
finit_SOURCES = finit.c api.c client.c conf.c exec.c getty.c helpers.c pid.c \
|
||||
sig.c svc.c service.c plugin.c tty.c cond.c cond-w.c sm.c
|
||||
sig.c svc.c service.c plugin.c tty.c cond.c cond-w.c sm.c \
|
||||
utmp-api.c utmp-api.h
|
||||
pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h plugin.h svc.h
|
||||
if INETD
|
||||
finit_SOURCES += inetd.c
|
||||
|
||||
@@ -31,14 +31,13 @@
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <utmp.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
#include "private.h"
|
||||
#include "utmp-api.h"
|
||||
|
||||
char *strip_line(char *line)
|
||||
{
|
||||
@@ -57,24 +56,9 @@ char *strip_line(char *line)
|
||||
return line;
|
||||
}
|
||||
|
||||
static int encode(int lvl)
|
||||
{
|
||||
if (!lvl) return 0;
|
||||
return lvl + '0';
|
||||
}
|
||||
|
||||
void runlevel_set(int pre, int now)
|
||||
{
|
||||
struct utmp utent;
|
||||
|
||||
memset(&utent, 0, sizeof(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();
|
||||
utmp_set_runlevel(pre, now);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+29
@@ -24,6 +24,35 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
int utmp_set(int type, int pid, char *user)
|
||||
{
|
||||
int result;
|
||||
struct utmp ut;
|
||||
|
||||
memset(&ut, 0, sizeof(ut));
|
||||
ut.ut_type = type;
|
||||
ut.ut_pid = pid;
|
||||
strlcpy(ut.ut_user, user, sizeof(ut.ut_user));
|
||||
|
||||
setutent();
|
||||
result = pututline(&ut) ? 0 : 1;;
|
||||
endutent();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int encode(int lvl)
|
||||
{
|
||||
if (!lvl) return 0;
|
||||
return lvl + '0';
|
||||
}
|
||||
|
||||
int utmp_set_runlevel(int pre, int now)
|
||||
{
|
||||
return utmp_set(RUN_LVL, (encode(pre) << 8) | (encode(now) & 0xFF), "runlevel");
|
||||
}
|
||||
|
||||
int utmp_show(char *file)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
int utmp_set (int type, int pid, char *user);
|
||||
int utmp_set_runlevel(int pre, int now);
|
||||
int utmp_show(char *file);
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user