halt: reinstate -w even if !FEATURE_WTMP; beautify code in halt.c
This commit is contained in:
parent
8d89bed840
commit
9725daa03a
76
init/halt.c
76
init/halt.c
@ -13,44 +13,11 @@
|
||||
#if ENABLE_FEATURE_WTMP
|
||||
#include <sys/utsname.h>
|
||||
#include <utmp.h>
|
||||
#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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user