mirror of
https://github.com/troglobit/finit.git
synced 2026-10-19 11:09:35 +00:00
Relocate utmp_show() to initctl.c
Only used by this tool, no need to keep it in the shared utmp-api.c Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
958cab8cc7
commit
0f64e18f27
5 files changed
+44
-44
No files matched your search
@@ -367,6 +367,46 @@ static int do_halt (char *UNUSED(arg)) { return do_signal(SIGUSR1, "halt");
|
||||
static int do_poweroff(char *UNUSED(arg)) { return do_signal(SIGUSR2, "power off"); }
|
||||
static int do_reboot (char *UNUSED(arg)) { return do_signal(SIGTERM, "reboot"); }
|
||||
|
||||
int utmp_show(char *file)
|
||||
{
|
||||
time_t sec;
|
||||
struct utmp *ut;
|
||||
struct tm *sectm;
|
||||
|
||||
int pid;
|
||||
char id[sizeof(ut->ut_id) + 1], user[sizeof(ut->ut_user) + 1], when[80];
|
||||
|
||||
printf("%s =============================================================================================\n", file);
|
||||
utmpname(file);
|
||||
|
||||
setutent();
|
||||
while ((ut = getutent())) {
|
||||
char addr[64];
|
||||
|
||||
memset(id, 0, sizeof(id));
|
||||
strlcpy(id, ut->ut_id, sizeof(id));
|
||||
|
||||
memset(user, 0, sizeof(user));
|
||||
strlcpy(user, ut->ut_user, sizeof(user));
|
||||
|
||||
sec = ut->ut_tv.tv_sec;
|
||||
sectm = localtime(&sec);
|
||||
strftime(when, sizeof(when), "%F %T", sectm);
|
||||
|
||||
pid = ut->ut_pid;
|
||||
if (ut->ut_addr_v6[1] || ut->ut_addr_v6[2] || ut->ut_addr_v6[3])
|
||||
inet_ntop(AF_INET6, ut->ut_addr_v6, addr, sizeof(addr));
|
||||
else
|
||||
inet_ntop(AF_INET, &ut->ut_addr, addr, sizeof(addr));
|
||||
|
||||
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, addr, when);
|
||||
}
|
||||
endutent();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_utmp(char *UNUSED(cmd))
|
||||
{
|
||||
return utmp_show(_PATH_WTMP) ||
|
||||
|
||||
Reference in new issue
Block a user