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-w32-86a7f18f211af1abda5c855d2674b0fcb53de524.tar.gz
busybox-w32-86a7f18f211af1abda5c855d2674b0fcb53de524.tar.bz2
busybox-w32-86a7f18f211af1abda5c855d2674b0fcb53de524.zip
*: 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 @@
32 32
33#if defined UT_LINESIZE \ 33#if defined UT_LINESIZE \
34 && ((UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256)) 34 && ((UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256))
35#error struct utmp member char[] size(s) have changed! 35#error struct utmpx member char[] size(s) have changed!
36#elif defined __UT_LINESIZE \ 36#elif defined __UT_LINESIZE \
37 && ((__UT_LINESIZE != 32) || (__UT_NAMESIZE != 64) || (__UT_HOSTSIZE != 256)) 37 && ((__UT_LINESIZE != 32) || (__UT_NAMESIZE != 64) || (__UT_HOSTSIZE != 256))
38#error struct utmp member char[] size(s) have changed! 38#error struct utmpx member char[] size(s) have changed!
39#endif 39#endif
40 40
41#if EMPTY != 0 || RUN_LVL != 1 || BOOT_TIME != 2 || NEW_TIME != 3 || \ 41#if EMPTY != 0 || RUN_LVL != 1 || BOOT_TIME != 2 || NEW_TIME != 3 || \
42 OLD_TIME != 4 42 OLD_TIME != 4
43#error Values for the ut_type field of struct utmp changed 43#error Values for the ut_type field of struct utmpx changed
44#endif 44#endif
45 45
46int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 46int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 47int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
48{ 48{
49 struct utmp ut; 49 struct utmpx ut;
50 int n, file = STDIN_FILENO; 50 int n, file = STDIN_FILENO;
51 time_t t_tmp; 51 time_t t_tmp;
52 off_t pos; 52 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 @@
22#define HEADER_LINE_WIDE "USER", "TTY", \ 22#define HEADER_LINE_WIDE "USER", "TTY", \
23 INET6_ADDRSTRLEN, INET6_ADDRSTRLEN, "HOST", "LOGIN", " TIME", "" 23 INET6_ADDRSTRLEN, INET6_ADDRSTRLEN, "HOST", "LOGIN", " TIME", ""
24 24
25#if !defined __UT_LINESIZE && defined UT_LINESIZE
26# define __UT_LINESIZE UT_LINESIZE
27#endif
28
25enum { 29enum {
26 NORMAL, 30 NORMAL,
27 LOGGED, 31 LOGGED,
@@ -39,7 +43,7 @@ enum {
39 43
40#define show_wide (option_mask32 & LAST_OPT_W) 44#define show_wide (option_mask32 & LAST_OPT_W)
41 45
42static void show_entry(struct utmp *ut, int state, time_t dur_secs) 46static void show_entry(struct utmpx *ut, int state, time_t dur_secs)
43{ 47{
44 unsigned days, hours, mins; 48 unsigned days, hours, mins;
45 char duration[sizeof("(%u+02:02)") + sizeof(int)*3]; 49 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)
104 duration_str); 108 duration_str);
105} 109}
106 110
107static int get_ut_type(struct utmp *ut) 111static int get_ut_type(struct utmpx *ut)
108{ 112{
109 if (ut->ut_line[0] == '~') { 113 if (ut->ut_line[0] == '~') {
110 if (strcmp(ut->ut_user, "shutdown") == 0) { 114 if (strcmp(ut->ut_user, "shutdown") == 0) {
@@ -142,7 +146,7 @@ static int get_ut_type(struct utmp *ut)
142 return ut->ut_type; 146 return ut->ut_type;
143} 147}
144 148
145static int is_runlevel_shutdown(struct utmp *ut) 149static int is_runlevel_shutdown(struct utmpx *ut)
146{ 150{
147 if (((ut->ut_pid & 255) == '0') || ((ut->ut_pid & 255) == '6')) { 151 if (((ut->ut_pid & 255) == '0') || ((ut->ut_pid & 255) == '6')) {
148 return 1; 152 return 1;
@@ -154,7 +158,7 @@ static int is_runlevel_shutdown(struct utmp *ut)
154int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 158int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
155int last_main(int argc UNUSED_PARAM, char **argv) 159int last_main(int argc UNUSED_PARAM, char **argv)
156{ 160{
157 struct utmp ut; 161 struct utmpx ut;
158 const char *filename = _PATH_WTMP; 162 const char *filename = _PATH_WTMP;
159 llist_t *zlist; 163 llist_t *zlist;
160 off_t pos; 164 off_t pos;
@@ -242,9 +246,9 @@ int last_main(int argc UNUSED_PARAM, char **argv)
242 { 246 {
243 llist_t *el, *next; 247 llist_t *el, *next;
244 for (el = zlist; el; el = next) { 248 for (el = zlist; el; el = next) {
245 struct utmp *up = (struct utmp *)el->data; 249 struct utmpx *up = (struct utmpx *)el->data;
246 next = el->link; 250 next = el->link;
247 if (strncmp(up->ut_line, ut.ut_line, UT_LINESIZE) == 0) { 251 if (strncmp(up->ut_line, ut.ut_line, __UT_LINESIZE) == 0) {
248 if (show) { 252 if (show) {
249 show_entry(&ut, NORMAL, up->ut_tv.tv_sec); 253 show_entry(&ut, NORMAL, up->ut_tv.tv_sec);
250 show = 0; 254 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 @@
29int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 29int runlevel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
30int runlevel_main(int argc UNUSED_PARAM, char **argv) 30int runlevel_main(int argc UNUSED_PARAM, char **argv)
31{ 31{
32 struct utmp *ut; 32 struct utmpx *ut;
33 char prev; 33 char prev;
34 34
35 if (argv[1]) utmpname(argv[1]); 35 if (argv[1]) utmpxname(argv[1]);
36 36
37 setutent(); 37 setutxent();
38 while ((ut = getutent()) != NULL) { 38 while ((ut = getutxent()) != NULL) {
39 if (ut->ut_type == RUN_LVL) { 39 if (ut->ut_type == RUN_LVL) {
40 prev = ut->ut_pid / 256; 40 prev = ut->ut_pid / 256;
41 if (prev == 0) prev = 'N'; 41 if (prev == 0) prev = 'N';
42 printf("%c %c\n", prev, ut->ut_pid % 256); 42 printf("%c %c\n", prev, ut->ut_pid % 256);
43 if (ENABLE_FEATURE_CLEAN_UP) 43 if (ENABLE_FEATURE_CLEAN_UP)
44 endutent(); 44 endutxent();
45 return 0; 45 return 0;
46 } 46 }
47 } 47 }
@@ -49,6 +49,6 @@ int runlevel_main(int argc UNUSED_PARAM, char **argv)
49 puts("unknown"); 49 puts("unknown");
50 50
51 if (ENABLE_FEATURE_CLEAN_UP) 51 if (ENABLE_FEATURE_CLEAN_UP)
52 endutent(); 52 endutxent();
53 return 1; 53 return 1;
54} 54}
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 @@
32int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 32int wall_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
33int wall_main(int argc UNUSED_PARAM, char **argv) 33int wall_main(int argc UNUSED_PARAM, char **argv)
34{ 34{
35 struct utmp *ut; 35 struct utmpx *ut;
36 char *msg; 36 char *msg;
37 int fd; 37 int fd;
38 38
@@ -46,8 +46,8 @@ int wall_main(int argc UNUSED_PARAM, char **argv)
46 msg = xmalloc_read(fd, NULL); 46 msg = xmalloc_read(fd, NULL);
47 if (ENABLE_FEATURE_CLEAN_UP && argv[1]) 47 if (ENABLE_FEATURE_CLEAN_UP && argv[1])
48 close(fd); 48 close(fd);
49 setutent(); 49 setutxent();
50 while ((ut = getutent()) != NULL) { 50 while ((ut = getutxent()) != NULL) {
51 char *line; 51 char *line;
52 if (ut->ut_type != USER_PROCESS) 52 if (ut->ut_type != USER_PROCESS)
53 continue; 53 continue;
@@ -56,7 +56,7 @@ int wall_main(int argc UNUSED_PARAM, char **argv)
56 free(line); 56 free(line);
57 } 57 }
58 if (ENABLE_FEATURE_CLEAN_UP) { 58 if (ENABLE_FEATURE_CLEAN_UP) {
59 endutent(); 59 endutxent();
60 free(msg); 60 free(msg);
61 } 61 }
62 return EXIT_SUCCESS; 62 return EXIT_SUCCESS;