remove nearly-duplicate PATHs in several places

function                                             old     new   delta
bb_PATH_root_path                                      -      35     +35
varunset                                              60      58      -2
arith                                               2042    2033      -9
bb_default_root_login_path                            30       -     -30
.rodata                                           128794  128762     -32
which_main                                           152     117     -35
defpathvar                                            40       -     -40
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 0/4 up/down: 35/-148)          Total: -113 bytes
This commit is contained in:
Denis Vlasenko 2007-06-12 22:35:19 +00:00
parent f312e32662
commit f5f75c5e82
7 changed files with 13 additions and 16 deletions

View File

@ -22,9 +22,11 @@ int which_main(int argc, char **argv)
bb_show_usage(); bb_show_usage();
} }
/* We shouldn't do this. Ever. Not our business.
if (!getenv("PATH")) { if (!getenv("PATH")) {
setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin", 1); putenv((char*)bb_PATH_root_path);
} }
*/
while (--argc > 0) { while (--argc > 0) {
argv++; argv++;

View File

@ -953,8 +953,9 @@ extern const char bb_dev_null[];
extern const char bb_busybox_exec_path[]; extern const char bb_busybox_exec_path[];
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here */ * but I want to save a few bytes here */
extern const char bb_default_root_login_path[]; /* "/sbin:/usr/sbin:/bin:/usr/bin" */ extern const char bb_PATH_root_path[]; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
#define bb_default_login_path (bb_default_root_login_path + sizeof("/sbin:/usr/sbin")) #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
extern const int const_int_0; extern const int const_int_0;
extern const int const_int_1; extern const int const_int_1;

View File

@ -24,10 +24,6 @@
#define CONSOLE_NAME_SIZE 32 #define CONSOLE_NAME_SIZE 32
#define MAXENV 16 /* Number of env. vars */ #define MAXENV 16 /* Number of env. vars */
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif
#if ENABLE_FEATURE_INIT_COREDUMPS #if ENABLE_FEATURE_INIT_COREDUMPS
/* /*
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
@ -112,7 +108,7 @@ enum {
static const char * const environment[] = { static const char * const environment[] = {
"HOME=/", "HOME=/",
"PATH=" _PATH_STDPATH, bb_PATH_root_path,
"SHELL=/bin/sh", "SHELL=/bin/sh",
"USER=root", "USER=root",
NULL NULL

View File

@ -40,7 +40,7 @@ const char bb_busybox_exec_path[] = CONFIG_BUSYBOX_EXEC_PATH;
const char bb_default_login_shell[] = LIBBB_DEFAULT_LOGIN_SHELL; const char bb_default_login_shell[] = LIBBB_DEFAULT_LOGIN_SHELL;
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here. Check libbb.h before changing! */ * but I want to save a few bytes here. Check libbb.h before changing! */
const char bb_default_root_login_path[] = "/sbin:/usr/sbin:/bin:/usr/bin"; const char bb_PATH_root_path[] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin";
const int const_int_0; const int const_int_0;

View File

@ -56,7 +56,7 @@ void setup_environment(const char *shell, int loginshell, int changeenv, const s
xsetenv("SHELL", shell); xsetenv("SHELL", shell);
xsetenv("USER", pw->pw_name); xsetenv("USER", pw->pw_name);
xsetenv("LOGNAME", pw->pw_name); xsetenv("LOGNAME", pw->pw_name);
xsetenv("PATH", (pw->pw_uid ? bb_default_login_path : bb_default_root_login_path)); xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path));
} }
else if (changeenv) { else if (changeenv) {
/* Set HOME, SHELL, and if not becoming a super-user, /* Set HOME, SHELL, and if not becoming a super-user,

View File

@ -1581,7 +1581,6 @@ static unsigned long rseed;
# define VDYNAMIC 0 # define VDYNAMIC 0
#endif #endif
static const char defpathvar[] = "PATH=/usr/local/bin:/usr/bin:/sbin:/bin";
#ifdef IFS_BROKEN #ifdef IFS_BROKEN
static const char defifsvar[] = "IFS= \t\n"; static const char defifsvar[] = "IFS= \t\n";
#define defifs (defifsvar + 4) #define defifs (defifsvar + 4)
@ -1674,7 +1673,7 @@ static struct var varinit[] = {
{ NULL, VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL\0", changemail }, { NULL, VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL\0", changemail },
{ NULL, VSTRFIXED|VTEXTFIXED|VUNSET, "MAILPATH\0", changemail }, { NULL, VSTRFIXED|VTEXTFIXED|VUNSET, "MAILPATH\0", changemail },
#endif #endif
{ NULL, VSTRFIXED|VTEXTFIXED, defpathvar, changepath }, { NULL, VSTRFIXED|VTEXTFIXED, bb_PATH_root_path, changepath },
{ NULL, VSTRFIXED|VTEXTFIXED, "PS1=$ ", NULL }, { NULL, VSTRFIXED|VTEXTFIXED, "PS1=$ ", NULL },
{ NULL, VSTRFIXED|VTEXTFIXED, "PS2=> ", NULL }, { NULL, VSTRFIXED|VTEXTFIXED, "PS2=> ", NULL },
{ NULL, VSTRFIXED|VTEXTFIXED, "PS4=+ ", NULL }, { NULL, VSTRFIXED|VTEXTFIXED, "PS4=+ ", NULL },
@ -1710,7 +1709,6 @@ static struct var varinit[] = {
#else #else
#define vrandom (&vps4)[1] #define vrandom (&vps4)[1]
#endif #endif
#define defpath (defpathvar + 5)
/* /*
* The following macros access the values of the above variables. * The following macros access the values of the above variables.
@ -7874,7 +7872,7 @@ parse_command_args(char **argv, const char **path)
do { do {
switch (c) { switch (c) {
case 'p': case 'p':
*path = defpath; *path = bb_default_path;
break; break;
default: default:
/* run 'typecmd' for other options */ /* run 'typecmd' for other options */

View File

@ -5213,9 +5213,9 @@ int msh_main(int argc, char **argv)
if (path->value == null) { if (path->value == null) {
/* Can be merged with same string elsewhere in bbox */ /* Can be merged with same string elsewhere in bbox */
if (geteuid() == 0) if (geteuid() == 0)
setval(path, bb_default_root_login_path); setval(path, bb_default_root_path);
else else
setval(path, bb_default_login_path); setval(path, bb_default_path);
} }
export(path); export(path);