mirror of
https://github.com/troglobit/finit.git
synced 2026-10-18 10:59:34 +00:00
initctl: Break out UTMP logic to separate file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
07f06c8b95
commit
7cdd42195b
4 files changed
+103
-39
No files matched your search
@@ -28,8 +28,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <lite/lite.h>
|
||||
|
||||
#include "config.h"
|
||||
@@ -37,6 +35,7 @@
|
||||
#include "cond.h"
|
||||
#include "helpers.h"
|
||||
#include "service.h"
|
||||
#include "utmp-api.h"
|
||||
|
||||
#define _PATH_COND _PATH_VARRUN "finit/cond/"
|
||||
|
||||
@@ -282,44 +281,10 @@ static int do_halt (char *UNUSED(arg)) { return kill(1, SIGUSR1); }
|
||||
static int do_poweroff(char *UNUSED(arg)) { return kill(1, SIGUSR2); }
|
||||
static int do_reboot (char *UNUSED(arg)) { return kill(1, SIGTERM); }
|
||||
|
||||
static int do_utmp_show(char *file)
|
||||
{
|
||||
time_t sec;
|
||||
struct utmp *ut;
|
||||
struct tm *sectm;
|
||||
|
||||
int pid;
|
||||
char id[sizeof(ut->ut_id)], user[sizeof(ut->ut_user)], when[80];
|
||||
|
||||
printf("%s =============================================================================================\n", file);
|
||||
utmpname(file);
|
||||
|
||||
setutent();
|
||||
while ((ut = getutent())) {
|
||||
memset(id, 0, sizeof(id));
|
||||
strncpy(id, ut->ut_id, sizeof(ut->ut_id));
|
||||
|
||||
memset(user, 0, sizeof(user));
|
||||
strncpy(user, ut->ut_user, sizeof(ut->ut_user));
|
||||
|
||||
sec = ut->ut_tv.tv_sec;
|
||||
sectm = localtime(&sec);
|
||||
strftime(when, sizeof(when), "%F %T", sectm);
|
||||
|
||||
pid = ut->ut_pid;
|
||||
|
||||
printf("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-20.20s] [%-15.15s] [%-19.19s]\n",
|
||||
ut->ut_type, pid, id, user, ut->ut_line, ut->ut_host, "0.0.0.0", when);
|
||||
}
|
||||
endutent();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_utmp(char *UNUSED(cmd))
|
||||
{
|
||||
return do_utmp_show(_PATH_UTMP) ||
|
||||
do_utmp_show(_PATH_WTMP);
|
||||
return utmp_show(_PATH_UTMP) ||
|
||||
utmp_show(_PATH_WTMP);
|
||||
}
|
||||
|
||||
static int show_version(char *UNUSED(arg))
|
||||
|
||||
Reference in new issue
Block a user