aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-10 13:32:20 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-10 13:32:20 +0100
commitf2539c78d2e507150dea06e8702c5ab8713d2b49 (patch)
treefade1ab37811045bff900534dc75f4be77664cc9
parentbaa41c785551ae0580526298aa6fadf4534fc8c0 (diff)
downloadbusybox-w32-f2539c78d2e507150dea06e8702c5ab8713d2b49.tar.gz
busybox-w32-f2539c78d2e507150dea06e8702c5ab8713d2b49.tar.bz2
busybox-w32-f2539c78d2e507150dea06e8702c5ab8713d2b49.zip
init: stop using static data
function old new delta init_action_list 4 - -4 new_init_action 148 142 -6 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-10) Total: -10 bytes text data bss dec hex filename 927839 481 6832 935152 e44f0 busybox_old 927833 481 6824 935138 e44e2 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--init/init.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/init/init.c b/init/init.c
index 6f3374eac..cac165fc7 100644
--- a/init/init.c
+++ b/init/init.c
@@ -128,6 +128,7 @@
128#define DEBUG_SEGV_HANDLER 0 128#define DEBUG_SEGV_HANDLER 0
129 129
130#include "libbb.h" 130#include "libbb.h"
131#include "common_bufsiz.h"
131#include <syslog.h> 132#include <syslog.h>
132#include <sys/resource.h> 133#include <sys/resource.h>
133#ifdef __linux__ 134#ifdef __linux__
@@ -203,7 +204,6 @@
203 */ 204 */
204#define RESTART 0x80 205#define RESTART 0x80
205 206
206
207/* A linked list of init_actions, to be read from inittab */ 207/* A linked list of init_actions, to be read from inittab */
208struct init_action { 208struct init_action {
209 struct init_action *next; 209 struct init_action *next;
@@ -213,11 +213,17 @@ struct init_action {
213 char command[1]; 213 char command[1];
214}; 214};
215 215
216static struct init_action *init_action_list = NULL; 216struct globals {
217 217 struct init_action *init_action_list;
218#if !ENABLE_FEATURE_INIT_SYSLOG 218#if !ENABLE_FEATURE_INIT_SYSLOG
219static const char *log_console = VC_5; 219 const char *log_console;
220#endif 220#endif
221} FIX_ALIASING;
222#define G (*(struct globals*)bb_common_bufsiz1)
223#define INIT_G() do { \
224 setup_common_bufsiz(); \
225 IF_NOT_FEATURE_INIT_SYSLOG(G.log_console = VC_5;) \
226} while (0)
221 227
222enum { 228enum {
223 L_LOG = 0x1, 229 L_LOG = 0x1,
@@ -265,10 +271,10 @@ static void message(int where, const char *fmt, ...)
265 271
266 if (log_fd < 0) { 272 if (log_fd < 0) {
267 log_fd = STDERR_FILENO; 273 log_fd = STDERR_FILENO;
268 if (log_console) { 274 if (G.log_console) {
269 log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY); 275 log_fd = device_open(G.log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
270 if (log_fd < 0) { 276 if (log_fd < 0) {
271 bb_error_msg("can't log to %s", log_console); 277 bb_error_msg("can't log to %s", G.log_console);
272 where = L_CONSOLE; 278 where = L_CONSOLE;
273 } else { 279 } else {
274 close_on_exec_on(log_fd); 280 close_on_exec_on(log_fd);
@@ -328,7 +334,7 @@ static void console_init(void)
328 if (!s || strcmp(s, "linux") == 0) 334 if (!s || strcmp(s, "linux") == 0)
329 putenv((char*)"TERM=vt102"); 335 putenv((char*)"TERM=vt102");
330# if !ENABLE_FEATURE_INIT_SYSLOG 336# if !ENABLE_FEATURE_INIT_SYSLOG
331 log_console = NULL; 337 G.log_console = NULL;
332# endif 338# endif
333 } else 339 } else
334#endif 340#endif
@@ -562,7 +568,7 @@ static struct init_action *mark_terminated(pid_t pid)
562 568
563 if (pid > 0) { 569 if (pid > 0) {
564 update_utmp_DEAD_PROCESS(pid); 570 update_utmp_DEAD_PROCESS(pid);
565 for (a = init_action_list; a; a = a->next) { 571 for (a = G.init_action_list; a; a = a->next) {
566 if (a->pid == pid) { 572 if (a->pid == pid) {
567 a->pid = 0; 573 a->pid = 0;
568 return a; 574 return a;
@@ -596,7 +602,7 @@ static void run_actions(int action_type)
596{ 602{
597 struct init_action *a; 603 struct init_action *a;
598 604
599 for (a = init_action_list; a; a = a->next) { 605 for (a = G.init_action_list; a; a = a->next) {
600 if (!(a->action_type & action_type)) 606 if (!(a->action_type & action_type))
601 continue; 607 continue;
602 608
@@ -630,7 +636,7 @@ static void new_init_action(uint8_t action_type, const char *command, const char
630 * To achieve that, if we find a matching entry, we move it 636 * To achieve that, if we find a matching entry, we move it
631 * to the end. 637 * to the end.
632 */ 638 */
633 nextp = &init_action_list; 639 nextp = &G.init_action_list;
634 while ((a = *nextp) != NULL) { 640 while ((a = *nextp) != NULL) {
635 /* Don't enter action if it's already in the list. 641 /* Don't enter action if it's already in the list.
636 * This prevents losing running RESPAWNs. 642 * This prevents losing running RESPAWNs.
@@ -845,7 +851,7 @@ static void exec_restart_action(void)
845{ 851{
846 struct init_action *a; 852 struct init_action *a;
847 853
848 for (a = init_action_list; a; a = a->next) { 854 for (a = G.init_action_list; a; a = a->next) {
849 if (!(a->action_type & RESTART)) 855 if (!(a->action_type & RESTART))
850 continue; 856 continue;
851 857
@@ -923,7 +929,7 @@ static void reload_inittab(void)
923 message(L_LOG, "reloading /etc/inittab"); 929 message(L_LOG, "reloading /etc/inittab");
924 930
925 /* Disable old entries */ 931 /* Disable old entries */
926 for (a = init_action_list; a; a = a->next) 932 for (a = G.init_action_list; a; a = a->next)
927 a->action_type = 0; 933 a->action_type = 0;
928 934
929 /* Append new entries, or modify existing entries 935 /* Append new entries, or modify existing entries
@@ -936,14 +942,14 @@ static void reload_inittab(void)
936#if ENABLE_FEATURE_KILL_REMOVED 942#if ENABLE_FEATURE_KILL_REMOVED
937 /* Kill stale entries */ 943 /* Kill stale entries */
938 /* Be nice and send SIGTERM first */ 944 /* Be nice and send SIGTERM first */
939 for (a = init_action_list; a; a = a->next) 945 for (a = G.init_action_list; a; a = a->next)
940 if (a->action_type == 0 && a->pid != 0) 946 if (a->action_type == 0 && a->pid != 0)
941 kill(a->pid, SIGTERM); 947 kill(a->pid, SIGTERM);
942 if (CONFIG_FEATURE_KILL_DELAY) { 948 if (CONFIG_FEATURE_KILL_DELAY) {
943 /* NB: parent will wait in NOMMU case */ 949 /* NB: parent will wait in NOMMU case */
944 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */ 950 if ((BB_MMU ? fork() : vfork()) == 0) { /* child */
945 sleep(CONFIG_FEATURE_KILL_DELAY); 951 sleep(CONFIG_FEATURE_KILL_DELAY);
946 for (a = init_action_list; a; a = a->next) 952 for (a = G.init_action_list; a; a = a->next)
947 if (a->action_type == 0 && a->pid != 0) 953 if (a->action_type == 0 && a->pid != 0)
948 kill(a->pid, SIGKILL); 954 kill(a->pid, SIGKILL);
949 _exit(EXIT_SUCCESS); 955 _exit(EXIT_SUCCESS);
@@ -955,7 +961,7 @@ static void reload_inittab(void)
955 * We never rerun SYSINIT entries anyway, 961 * We never rerun SYSINIT entries anyway,
956 * removing them too saves a few bytes 962 * removing them too saves a few bytes
957 */ 963 */
958 nextp = &init_action_list; 964 nextp = &G.init_action_list;
959 while ((a = *nextp) != NULL) { 965 while ((a = *nextp) != NULL) {
960 /* 966 /*
961 * Why pid == 0 check? 967 * Why pid == 0 check?
@@ -1046,6 +1052,8 @@ static void sleep_much(void)
1046int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1052int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1047int init_main(int argc UNUSED_PARAM, char **argv) 1053int init_main(int argc UNUSED_PARAM, char **argv)
1048{ 1054{
1055 INIT_G();
1056
1049 if (argv[1] && strcmp(argv[1], "-q") == 0) { 1057 if (argv[1] && strcmp(argv[1], "-q") == 0) {
1050 return kill(1, SIGHUP); 1058 return kill(1, SIGHUP);
1051 } 1059 }