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:
Joachim Nilsson
2017-02-10 10:17:41 +01:00
parent 958cab8cc7
commit 0f64e18f27
5 changed files with 44 additions and 44 deletions
-5
View File
@@ -58,11 +58,6 @@ char *strip_line(char *line)
return line;
}
void runlevel_set(int pre, int now)
{
utmp_set_runlevel(pre, now);
}
static int print_timestamp(void)
{
#if defined(CONFIG_PRINTK_TIME)
-2
View File
@@ -49,8 +49,6 @@ extern int _slup; /* INTERNAL: Is syslog up yet? */
char *strip_line (char *line);
void runlevel_set (int pre, int now);
int pid_alive (pid_t pid);
char *pid_get_name (pid_t pid, char *name, size_t len);
+40
View File
@@ -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) ||
+2 -37
View File
@@ -205,44 +205,9 @@ int utmp_set_runlevel(int pre, int now)
return utmp_set(RUN_LVL, (encode(pre) << 8) | (encode(now) & 0xFF), NULL, NULL, "runlevel");
}
int utmp_show(char *file)
void runlevel_set(int pre, int now)
{
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;
utmp_set_runlevel(pre, now);
}
/**
+2
View File
@@ -33,6 +33,8 @@ int utmp_set_dead (int pid);
int utmp_set_runlevel(int pre, int now);
int utmp_show (char *file);
void runlevel_set (int pre, int now);
#endif /* FINIT_UTMP_API_H_ */
/**