aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-08-16 11:48:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-08-16 11:48:48 +0200
commitd2e07bc16cbd68bc2771f9f163e610e4e327c67c (patch)
tree737d5309821fd44427754223965ec596bfa1fcf8 /init
parent73fbe9dc86df6c7db425c2c3939ff98c8c44974e (diff)
downloadbusybox-w32-d2e07bc16cbd68bc2771f9f163e610e4e327c67c.tar.gz
busybox-w32-d2e07bc16cbd68bc2771f9f163e610e4e327c67c.tar.bz2
busybox-w32-d2e07bc16cbd68bc2771f9f163e610e4e327c67c.zip
init: don't use fixed size buffer for command
We store init actions forever. 256 bytes per action means that a typical inittab of ~10 commands uses 2.5k just to remember command strings - which are usually _much_ shorter than 256 bytes. At a cost of a bit more code, it's possible to allocate only actually needed amount. function old new delta init_exec 224 248 +24 new_init_action 140 142 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'init')
-rw-r--r--init/init.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/init/init.c b/init/init.c
index f3a35d532..05ed4f7a7 100644
--- a/init/init.c
+++ b/init/init.c
@@ -140,7 +140,6 @@
140 * not fully functional init by switching it on! */ 140 * not fully functional init by switching it on! */
141#define DEBUG_INIT 0 141#define DEBUG_INIT 0
142 142
143#define COMMAND_SIZE 256
144#define CONSOLE_NAME_SIZE 32 143#define CONSOLE_NAME_SIZE 32
145 144
146/* Default sysinit script. */ 145/* Default sysinit script. */
@@ -195,7 +194,7 @@ struct init_action {
195 pid_t pid; 194 pid_t pid;
196 uint8_t action_type; 195 uint8_t action_type;
197 char terminal[CONSOLE_NAME_SIZE]; 196 char terminal[CONSOLE_NAME_SIZE];
198 char command[COMMAND_SIZE]; 197 char command[1];
199}; 198};
200 199
201static struct init_action *init_action_list = NULL; 200static struct init_action *init_action_list = NULL;
@@ -398,7 +397,7 @@ static void reset_sighandlers_and_unblock_sigs(void)
398} 397}
399 398
400/* Wrapper around exec: 399/* Wrapper around exec:
401 * Takes string (max COMMAND_SIZE chars). 400 * Takes string.
402 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'. 401 * If chars like '>' detected, execs '[-]/bin/sh -c "exec ......."'.
403 * Otherwise splits words on whitespace, deals with leading dash, 402 * Otherwise splits words on whitespace, deals with leading dash,
404 * and uses plain exec(). 403 * and uses plain exec().
@@ -406,10 +405,15 @@ static void reset_sighandlers_and_unblock_sigs(void)
406 */ 405 */
407static void init_exec(const char *command) 406static void init_exec(const char *command)
408{ 407{
409 char *cmd[COMMAND_SIZE / 2]; 408 /* +8 allows to write VLA sizes below more efficiently: */
410 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */ 409 unsigned command_size = strlen(command) + 8;
411 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */); 410 /* strlen(command) + strlen("exec ")+1: */
412 411 char buf[command_size];
412 /* strlen(command) / 2 + 4: */
413 char *cmd[command_size / 2];
414 int dash;
415
416 dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
413 command += dash; 417 command += dash;
414 418
415 /* See if any special /bin/sh requiring characters are present */ 419 /* See if any special /bin/sh requiring characters are present */
@@ -626,13 +630,13 @@ static void new_init_action(uint8_t action_type, const char *command, const char
626 nextp = &a->next; 630 nextp = &a->next;
627 } 631 }
628 632
629 a = xzalloc(sizeof(*a)); 633 a = xzalloc(sizeof(*a) + strlen(command));
630 634
631 /* Append to the end of the list */ 635 /* Append to the end of the list */
632 append: 636 append:
633 *nextp = a; 637 *nextp = a;
634 a->action_type = action_type; 638 a->action_type = action_type;
635 safe_strncpy(a->command, command, sizeof(a->command)); 639 strcpy(a->command, command);
636 safe_strncpy(a->terminal, cons, sizeof(a->terminal)); 640 safe_strncpy(a->terminal, cons, sizeof(a->terminal));
637 dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n", 641 dbg_message(L_LOG | L_CONSOLE, "command='%s' action=%d tty='%s'\n",
638 a->command, a->action_type, a->terminal); 642 a->command, a->action_type, a->terminal);