halt: reinstate -w even if !FEATURE_WTMP; beautify code in halt.c
No binary (build failed)
—
(log yok)
| @@ -13,60 +13,66 @@ | |
| #if ENABLE_FEATURE_WTMP | |
| #include <sys/utsname.h> | |
| #include <utmp.h> | |
| + | |
| + | static void write_wtmp(void) |
| + | { |
| + | struct utmp utmp; |
| + | struct utsname uts; |
| + | if (access(bb_path_wtmp_file, R_OK|W_OK) == -1) { |
| + | close(creat(bb_path_wtmp_file, 0664)); |
| + | } |
| + | memset(&utmp, 0, sizeof(utmp)); |
| + | utmp.ut_tv.tv_sec = time(NULL); |
| + | 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); |
| + | |
| + | } |
| + | #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[] = { | |
| - | #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 |
| + | 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++) |
| + | for (which = 0; "hpr"[which] != applet_name[0]; which++) |
| continue; | |
| /* Parse and handle arguments */ | |
| opt_complementary = "d+"; /* -d N */ | |
| - | flags = getopt32(argv, "d:nf" USE_FEATURE_WTMP("w"), &delay); |
| + | /* We support -w even if !ENABLE_FEATURE_WTMP, in order |
| + | * to not break scripts */ |
| + | flags = getopt32(argv, "d:nfw", &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)); |
| - | } |
| - | memset(&utmp, 0, sizeof(utmp)); |
| - | utmp.ut_tv.tv_sec = time(NULL); |
| - | 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); |
| + | write_wtmp(); |
| if (flags & 8) /* -w */ | |
| return EXIT_SUCCESS; | |
| - | #endif /* !ENABLE_FEATURE_WTMP */ |
| if (!(flags & 2)) /* no -n */ | |
| sync(); | |
| @@ -19,7 +19,7 @@ | |
| #include <syslog.h> | |
| #if ENABLE_FEATURE_UTMP | |
| - | #include <utmp.h> |
| + | #include <utmp.h> /* updwtmp() */ |
| #endif | |
| /* | |
| @@ -29,9 +29,6 @@ | |
| #ifdef LOGIN_PROCESS /* defined in System V utmp.h */ | |
| #include <sys/utsname.h> | |
| #include <time.h> | |
| - | #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 | |