aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2015-04-02 23:03:46 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2015-04-02 23:03:46 +0200
commit86a7f18f211af1abda5c855d2674b0fcb53de524 (patch)
tree9fd1eadb83bf48b29e9468ea8ff0e43c0736c245 /miscutils
parent1186894f773e13ab9ca2b3e05a194e9b88796fbe (diff)
downloadbusybox-86a7f18f211af1abda5c855d2674b0fcb53de524.tar.gz
*: Switch to POSIX utmpx API
UTMP is SVID legacy, UTMPX is mandated by POSIX. Glibc and uClibc have identical layout of UTMP and UTMPX, both of these libc treat _PATH_UTMPX as _PATH_UTMP so from a user-perspective nothing changes except the names of the API entrypoints. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/last.c8
-rw-r--r--miscutils/last_fancy.c16
-rw-r--r--miscutils/runlevel.c12
-rw-r--r--miscutils/wall.c8
4 files changed, 24 insertions, 20 deletions
diff --git a/miscutils/last.c b/miscutils/last.c
index a144c7e47..6d8b58463 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -32,21 +32,21 @@
#if defined UT_LINESIZE \
&& ((UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256))
-#error struct utmp member char[] size(s) have changed!
+#error struct utmpx member char[] size(s) have changed!
#elif defined __UT_LINESIZE \
&& ((__UT_LINESIZE != 32) || (__UT_NAMESIZE != 64) || (__UT_HOSTSIZE != 256))
-#error struct utmp member char[] size(s) have changed!
+#error struct utmpx member char[] size(s) have changed!
#endif
#if EMPTY != 0 || RUN_LVL != 1 || BOOT_TIME != 2 || NEW_TIME != 3 || \
OLD_TIME != 4
-#error Values for the ut_type field of struct utmp changed
+#error Values for the ut_type field of struct utmpx changed
#endif
int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
- struct utmp ut;
+ struct utmpx ut;
int n, file = STDIN_FILENO;
time_t t_tmp;
off_t pos;
diff --git a/miscutils/last_fancy.c b/miscutils/last_fancy.c
index 16ed9e920..8194e31b5 100644
--- a/miscutils/last_fancy.c
+++ b/miscutils/last_fancy.c
@@ -22,6 +22,10 @@
#define HEADER_LINE_WIDE "USER", "TTY", \
INET6_ADDRSTRLEN, INET6_ADDRSTRLEN, "HOST", "LOGIN", " TIME", ""
+#if !defined __UT_LINESIZE && defined UT_LINESIZE
+# define __UT_LINESIZE UT_LINESIZE
+#endif
+
enum {
NORMAL,
LOGGED,
@@ -39,7 +43,7 @@ enum {
#define show_wide (option_mask32 & LAST_OPT_W)
-static void show_entry(struct utmp *ut, int state, time_t dur_secs)
+static void show_entry(struct utmpx *ut, int state, time_t dur_secs)
{
unsigned days, hours, mins;
char duration[sizeof("(%u+02:02)") + sizeof(int)*3];
@@ -104,7 +108,7 @@ static void show_entry(struct utmp *ut, int state, time_t dur_secs)
duration_str);
}
-static int get_ut_type(struct utmp *ut)
+static int get_ut_type(struct utmpx *ut)
{
if (ut->ut_line[0] == '~') {
if (strcmp(ut->ut_user, "shutdown") == 0) {
@@ -142,7 +146,7 @@ static int get_ut_type(struct utmp *ut)
return ut->ut_type;
}
-static int is_runlevel_shutdown(struct utmp *ut)
+static int is_runlevel_shutdown(struct utmpx *ut)
{
if (((ut->ut_pid & 255) == '0') || ((ut->ut_pid & 255) == '6')) {
return 1;
@@ -154,7 +158,7 @@ static int is_runlevel_shutdown(struct utmp *ut)
int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int last_main(int argc UNUSED_PARAM, char **argv)
{
- struct utmp ut;
+ struct utmpx ut;
const char *filename = _PATH_WTMP;
llist_t *zlist;
off_t pos;
@@ -242,9 +246,9 @@ int last_main(int argc UNUSED_PARAM, char **argv)
{
llist_t *el, *next;
for (el = zlist; el; el = next) {
- struct utmp *up = (struct utmp *)el->data;
+ struct utmpx *up = (struct utmpx *)el->data;
next = el->link;
- if (strncmp(up->ut_line, ut.ut_line, UT_LINESIZE) == 0) {
+ if (strncmp(up->ut_line, ut.ut_line, __UT_LINESIZE) == 0) {
if (show) {
show_entry(&ut, NORMAL, up->ut_tv.tv_sec);
show = 0;
diff --git a/miscutils/runlevel.c b/miscutils/runlevel.c
index 76231df22..8558db862 100644
--- a/miscutils/runlevel.c
+++ b/miscutils/runlevel.c
@@ -29,19 +29,19 @@
int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int runlevel_main(int argc UNUSED_PARAM, char **argv)
{
- struct utmp *ut;
+ struct utmpx *ut;
char prev;
- if (argv[1]) utmpname(argv[1]);
+ if (argv[1]) utmpxname(argv[1]);
- setutent();
- while ((ut = getutent()) != NULL) {
+ setutxent();
+ while ((ut = getutxent()) != NULL) {
if (ut->ut_type == RUN_LVL) {
prev = ut->ut_pid / 256;
if (prev == 0) prev = 'N';
printf("%c %c\n", prev, ut->ut_pid % 256);
if (ENABLE_FEATURE_CLEAN_UP)
- endutent();
+ endutxent();
return 0;
}
}
@@ -49,6 +49,6 @@ int runlevel_main(int argc UNUSED_PARAM, char **argv)
puts("unknown");
if (ENABLE_FEATURE_CLEAN_UP)
- endutent();
+ endutxent();
return 1;
}
diff --git a/miscutils/wall.c b/miscutils/wall.c
index bb709ee39..50658f457 100644
--- a/miscutils/wall.c
+++ b/miscutils/wall.c
@@ -32,7 +32,7 @@
int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int wall_main(int argc UNUSED_PARAM, char **argv)
{
- struct utmp *ut;
+ struct utmpx *ut;
char *msg;
int fd;
@@ -46,8 +46,8 @@ int wall_main(int argc UNUSED_PARAM, char **argv)
msg = xmalloc_read(fd, NULL);
if (ENABLE_FEATURE_CLEAN_UP && argv[1])
close(fd);
- setutent();
- while ((ut = getutent()) != NULL) {
+ setutxent();
+ while ((ut = getutxent()) != NULL) {
char *line;
if (ut->ut_type != USER_PROCESS)
continue;
@@ -56,7 +56,7 @@ int wall_main(int argc UNUSED_PARAM, char **argv)
free(line);
}
if (ENABLE_FEATURE_CLEAN_UP) {
- endutent();
+ endutxent();
free(msg);
}
return EXIT_SUCCESS;