#define DEBUG_SEGV_HANDLER 0
#include "libbb.h"
+#include "common_bufsiz.h"
#include <syslog.h>
#include <sys/resource.h>
#ifdef __linux__
*/
#define RESTART 0x80
-
/* A linked list of init_actions, to be read from inittab */
struct init_action {
struct init_action *next;
char command[1];
};
-static struct init_action *init_action_list = NULL;
-
+struct globals {
+ struct init_action *init_action_list;
#if !ENABLE_FEATURE_INIT_SYSLOG
-static const char *log_console = VC_5;
+ const char *log_console;
#endif
+} FIX_ALIASING;
+#define G (*(struct globals*)bb_common_bufsiz1)
+#define INIT_G() do { \
+ setup_common_bufsiz(); \
+ IF_NOT_FEATURE_INIT_SYSLOG(G.log_console = VC_5;) \
+} while (0)
enum {
L_LOG = 0x1,
if (log_fd < 0) {
log_fd = STDERR_FILENO;
- if (log_console) {
- log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
+ if (G.log_console) {
+ log_fd = device_open(G.log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (log_fd < 0) {
- bb_error_msg("can't log to %s", log_console);
+ bb_error_msg("can't log to %s", G.log_console);
where = L_CONSOLE;
} else {
close_on_exec_on(log_fd);
if (!s || strcmp(s, "linux") == 0)
putenv((char*)"TERM=vt102");
# if !ENABLE_FEATURE_INIT_SYSLOG
- log_console = NULL;
+ G.log_console = NULL;
# endif
} else
#endif
if (pid > 0) {
update_utmp_DEAD_PROCESS(pid);
- for (a = init_action_list; a; a = a->next) {
+ for (a = G.init_action_list; a; a = a->next) {
if (a->pid == pid) {
a->pid = 0;
return a;
{
struct init_action *a;
- for (a = init_action_list; a; a = a->next) {
+ for (a = G.init_action_list; a; a = a->next) {
if (!(a->action_type & action_type))
continue;
* To achieve that, if we find a matching entry, we move it
* to the end.
*/
- nextp = &init_action_list;
+ nextp = &G.init_action_list;
while ((a = *nextp) != NULL) {
/* Don't enter action if it's already in the list.
* This prevents losing running RESPAWNs.
{
struct init_action *a;
- for (a = init_action_list; a; a = a->next) {
+ for (a = G.init_action_list; a; a = a->next) {
if (!(a->action_type & RESTART))
continue;
message(L_LOG, "reloading /etc/inittab");
/* Disable old entries */
- for (a = init_action_list; a; a = a->next)
+ for (a = G.init_action_list; a; a = a->next)
a->action_type = 0;
/* Append new entries, or modify existing entries
#if ENABLE_FEATURE_KILL_REMOVED
/* Kill stale entries */
/* Be nice and send SIGTERM first */
- for (a = init_action_list; a; a = a->next)
+ for (a = G.init_action_list; a; a = a->next)
if (a->action_type == 0 && a->pid != 0)
kill(a->pid, SIGTERM);
if (CONFIG_FEATURE_KILL_DELAY) {
/* NB: parent will wait in NOMMU case */
if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
sleep(CONFIG_FEATURE_KILL_DELAY);
- for (a = init_action_list; a; a = a->next)
+ for (a = G.init_action_list; a; a = a->next)
if (a->action_type == 0 && a->pid != 0)
kill(a->pid, SIGKILL);
_exit(EXIT_SUCCESS);
* We never rerun SYSINIT entries anyway,
* removing them too saves a few bytes
*/
- nextp = &init_action_list;
+ nextp = &G.init_action_list;
while ((a = *nextp) != NULL) {
/*
* Why pid == 0 check?
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int init_main(int argc UNUSED_PARAM, char **argv)
{
+ INIT_G();
+
if (argv[1] && strcmp(argv[1], "-q") == 0) {
return kill(1, SIGHUP);
}