Hi List

Gentoo currently uses halt -w to record a system shutdown action in wtmp
but not actually shut the system down at this point. Attached is a patch
that enables this for busybox halt. If this patch is not accepted, then
please consider silently accepting the -w option so a Gentoo shutdown is
a bit cleaner using busybox.

sysvinit halt also has the -d option, which means "Don't write a wtmp
record", however this conflicts with busybox where -d means delay. This
patch does not address this. Maybe there should be a shutdown applet
with the delay option to mirror sysvinit and BSD instead.

Thanks

Roy
diff -ur busybox-1.8.2.orig/include/usage.h busybox-1.8.2/include/usage.h
--- busybox-1.8.2.orig/include/usage.h	2007-11-10 01:40:53.000000000 +0000
+++ busybox-1.8.2/include/usage.h	2008-01-23 14:52:49.000000000 +0000
@@ -1301,7 +1301,8 @@
        "\n\nOptions:\n" \
        "	-d	Delay interval for halting\n" \
        "	-n	No call to sync()\n" \
-       "	-f	Force halt (don't go through init)"
+       "	-f	Force halt (don't go through init)\n" \
+       "	-w	Only write a wtmp record"
 
 #define hdparm_trivial_usage \
        "[options] [device] .."
diff -ur busybox-1.8.2.orig/init/halt.c busybox-1.8.2/init/halt.c
--- busybox-1.8.2.orig/init/halt.c	2007-11-10 01:40:53.000000000 +0000
+++ busybox-1.8.2/init/halt.c	2008-01-23 15:24:41.000000000 +0000
@@ -9,6 +9,8 @@
 
 #include "libbb.h"
 #include <sys/reboot.h>
+#include <sys/utsname.h>
+#include <utmp.h>
 
 int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int halt_main(int argc, char **argv)
@@ -30,13 +32,37 @@
 
 	char *delay;
 	int which, flags, rc = 1;
+#if ENABLE_FEATURE_WTMP
+	struct utmp utmp;
+	struct timeval tv;
+	struct utsname uts;
+#endif
 
 	/* Figure out which applet we're running */
 	for (which = 0; "hpr"[which] != *applet_name; which++);
 
 	/* Parse and handle arguments */
-	flags = getopt32(argv, "d:nf", &delay);
+	flags = getopt32(argv, "d:nfw", &delay);
 	if (flags & 1) sleep(xatou(delay));
+
+#if ENABLE_FEATURE_WTMP
+	if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) {
+		close(creat(bb_path_wtmp_file, 0664));
+	}
+	memset(&utmp, 0, sizeof (utmp));
+	gettimeofday(&tv, NULL);
+	utmp.ut_tv.tv_sec = tv.tv_sec;
+	utmp.ut_tv.tv_usec = tv.tv_usec;
+	safe_strncpy(utmp.ut_user, "shutdown", UT_NAMESIZE);
+	utmp.ut_type = RUN_LVL;
+	safe_strncpy(utmp.ut_id, "~~", sizeof (utmp.ut_id));
+	safe_strncpy(utmp.ut_line, "~~", UT_LINESIZE);
+	if (uname(&uts) == 0)
+		safe_strncpy(utmp.ut_host, uts.release, sizeof (utmp.ut_host));
+	updwtmp(bb_path_wtmp_file, &utmp);
+#endif /* !ENABLE_FEATURE_WTMP */
+
+	if (flags & 8) return 0;
 	if (!(flags & 2)) sync();
 
 	/* Perform action. */
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to