aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-24 02:28:00 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-24 02:28:00 +0000
commit680b86afbb8ba466176ad6866409496225660009 (patch)
tree79af7332ac8f7fd1560b7f68e17b1ed7edfd29dd
parent1d290d1e24ebe1a5204f16d1dd78255fe76ab60e (diff)
downloadbusybox-w32-680b86afbb8ba466176ad6866409496225660009.tar.gz
busybox-w32-680b86afbb8ba466176ad6866409496225660009.tar.bz2
busybox-w32-680b86afbb8ba466176ad6866409496225660009.zip
halt: write wtmp entry if wtmp support is enabled
-rw-r--r--init/halt.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/init/halt.c b/init/halt.c
index d9f8b1afc..c50d8af63 100644
--- a/init/halt.c
+++ b/init/halt.c
@@ -10,6 +10,11 @@
10#include "libbb.h" 10#include "libbb.h"
11#include <sys/reboot.h> 11#include <sys/reboot.h>
12 12
13#if ENABLE_FEATURE_WTMP
14#include <sys/utsname.h>
15#include <utmp.h>
16#endif
17
13int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 18int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
14int halt_main(int argc, char **argv) 19int halt_main(int argc, char **argv)
15{ 20{
@@ -26,18 +31,46 @@ RB_POWERDOWN,
26#endif 31#endif
27RB_AUTOBOOT 32RB_AUTOBOOT
28 }; 33 };
29 static const int signals[] = { SIGUSR1, SIGUSR2, SIGTERM }; 34 static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM };
30 35
31 char *delay; 36 char *delay;
32 int which, flags, rc = 1; 37 int which, flags, rc = 1;
38#if ENABLE_FEATURE_WTMP
39 struct utmp utmp;
40 struct timeval tv;
41 struct utsname uts;
42#endif
33 43
34 /* Figure out which applet we're running */ 44 /* Figure out which applet we're running */
35 for (which = 0; "hpr"[which] != *applet_name; which++); 45 for (which = 0; "hpr"[which] != *applet_name; which++)
46 continue;
36 47
37 /* Parse and handle arguments */ 48 /* Parse and handle arguments */
38 flags = getopt32(argv, "d:nf", &delay); 49 flags = getopt32(argv, "d:nfw", &delay);
39 if (flags & 1) sleep(xatou(delay)); 50 if (flags & 1)
40 if (!(flags & 2)) sync(); 51 sleep(xatou(delay));
52
53#if ENABLE_FEATURE_WTMP
54 if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
55 close(creat(bb_path_wtmp_file, 0664));
56 }
57 memset(&utmp, 0, sizeof(utmp));
58 gettimeofday(&tv, NULL);
59 utmp.ut_tv.tv_sec = tv.tv_sec;
60 utmp.ut_tv.tv_usec = tv.tv_usec;
61 safe_strncpy(utmp.ut_user, "shutdown", UT_NAMESIZE);
62 utmp.ut_type = RUN_LVL;
63 safe_strncpy(utmp.ut_id, "~~", sizeof(utmp.ut_id));
64 safe_strncpy(utmp.ut_line, "~~", UT_LINESIZE);
65 if (uname(&uts) == 0)
66 safe_strncpy(utmp.ut_host, uts.release, sizeof(utmp.ut_host));
67 updwtmp(bb_path_wtmp_file, &utmp);
68#endif /* !ENABLE_FEATURE_WTMP */
69
70 if (flags & 8) /* -w */
71 return 0;
72 if (!(flags & 2)) /* no -n */
73 sync();
41 74
42 /* Perform action. */ 75 /* Perform action. */
43 if (ENABLE_INIT && !(flags & 4)) { 76 if (ENABLE_INIT && !(flags & 4)) {