diff --git a/init/halt.c b/init/halt.c index 42b9edc08..cbb325eb9 100644 --- a/init/halt.c +++ b/init/halt.c @@ -13,44 +13,11 @@ #if ENABLE_FEATURE_WTMP #include #include -#endif -int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int halt_main(int argc UNUSED_PARAM, char **argv) +static void write_wtmp(void) { - static const int magic[] = { -#ifdef RB_HALT_SYSTEM - RB_HALT_SYSTEM, -#elif defined RB_HALT - RB_HALT, -#endif -#ifdef RB_POWER_OFF - RB_POWER_OFF, -#elif defined RB_POWERDOWN - RB_POWERDOWN, -#endif - RB_AUTOBOOT - }; - static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM }; - - int delay = 0; - int which, flags, rc; -#if ENABLE_FEATURE_WTMP struct utmp utmp; struct utsname uts; -#endif - - /* Figure out which applet we're running */ - for (which = 0; "hpr"[which] != *applet_name; which++) - continue; - - /* Parse and handle arguments */ - opt_complementary = "d+"; /* -d N */ - flags = getopt32(argv, "d:nf" USE_FEATURE_WTMP("w"), &delay); - - sleep(delay); - -#if ENABLE_FEATURE_WTMP if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) { close(creat(bb_path_wtmp_file, 0664)); } @@ -64,9 +31,48 @@ int halt_main(int argc UNUSED_PARAM, char **argv) safe_strncpy(utmp.ut_host, uts.release, sizeof(utmp.ut_host)); updwtmp(bb_path_wtmp_file, &utmp); +} +#else +#define write_wtmp() ((void)0) +#endif + +#ifndef RB_HALT_SYSTEM +#define RB_HALT_SYSTEM RB_HALT +#endif + +#ifndef RB_POWER_OFF +#define RB_POWER_OFF RB_POWERDOWN +#endif + +int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int halt_main(int argc UNUSED_PARAM, char **argv) +{ + static const int magic[] = { + RB_HALT_SYSTEM, + RB_POWER_OFF, + RB_AUTOBOOT + }; + static const smallint signals[] = { SIGUSR1, SIGUSR2, SIGTERM }; + + int delay = 0; + int which, flags, rc; + + /* Figure out which applet we're running */ + for (which = 0; "hpr"[which] != applet_name[0]; which++) + continue; + + /* Parse and handle arguments */ + opt_complementary = "d+"; /* -d N */ + /* We support -w even if !ENABLE_FEATURE_WTMP, in order + * to not break scripts */ + flags = getopt32(argv, "d:nfw", &delay); + + sleep(delay); + + write_wtmp(); + if (flags & 8) /* -w */ return EXIT_SUCCESS; -#endif /* !ENABLE_FEATURE_WTMP */ if (!(flags & 2)) /* no -n */ sync(); diff --git a/loginutils/getty.c b/loginutils/getty.c index 358a45c7c..8b0e729fb 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -19,7 +19,7 @@ #include #if ENABLE_FEATURE_UTMP -#include +#include /* updwtmp() */ #endif /* @@ -29,9 +29,6 @@ #ifdef LOGIN_PROCESS /* defined in System V utmp.h */ #include #include -#if ENABLE_FEATURE_WTMP -extern void updwtmp(const char *filename, const struct utmp *ut); -#endif #else /* if !sysV style, wtmp/utmp code is off */ #undef ENABLE_FEATURE_UTMP #undef ENABLE_FEATURE_WTMP