diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-25 11:12:32 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-25 11:12:32 +0000 |
| commit | 0a83fc398495799b4c96f3cd07304d38181cfc6f (patch) | |
| tree | d05666335cf16079b7f52c5d75d3bf395fef2b86 /shell | |
| parent | 201c72a8d672c1e2985bd340f6fa527251d695ba (diff) | |
| download | busybox-w32-0a83fc398495799b4c96f3cd07304d38181cfc6f.tar.gz busybox-w32-0a83fc398495799b4c96f3cd07304d38181cfc6f.tar.bz2 busybox-w32-0a83fc398495799b4c96f3cd07304d38181cfc6f.zip | |
hush: avoid duplicating HUSH_VERSION
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/shell/hush.c b/shell/hush.c index 1c7cddd36..a7b55415f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -329,16 +329,6 @@ enum { | |||
| 329 | 329 | ||
| 330 | #define HUSH_VER_STR "0.02" | 330 | #define HUSH_VER_STR "0.02" |
| 331 | 331 | ||
| 332 | static const char version_str[] = "HUSH_VERSION="HUSH_VER_STR; | ||
| 333 | |||
| 334 | static const struct variable const_shell_ver = { | ||
| 335 | .next = NULL, | ||
| 336 | .varstr = (char*)version_str, | ||
| 337 | .max_len = 1, /* 0 can provoke free(name) */ | ||
| 338 | .flg_export = 1, | ||
| 339 | .flg_read_only = 1, | ||
| 340 | }; | ||
| 341 | |||
| 342 | /* "Globals" within this file */ | 332 | /* "Globals" within this file */ |
| 343 | 333 | ||
| 344 | /* Sorted roughly by size (smaller offsets == smaller code) */ | 334 | /* Sorted roughly by size (smaller offsets == smaller code) */ |
| @@ -371,8 +361,8 @@ struct globals { | |||
| 371 | struct close_me *close_me_head; | 361 | struct close_me *close_me_head; |
| 372 | const char *cwd; | 362 | const char *cwd; |
| 373 | unsigned last_bg_pid; | 363 | unsigned last_bg_pid; |
| 374 | struct variable *top_var; /* = &shell_ver (both are set in main()) */ | 364 | struct variable *top_var; /* = &shell_ver (set in main()) */ |
| 375 | struct variable shell_ver; /* = const_shell_ver */ | 365 | struct variable shell_ver; |
| 376 | #if ENABLE_FEATURE_SH_STANDALONE | 366 | #if ENABLE_FEATURE_SH_STANDALONE |
| 377 | struct nofork_save_area nofork_save; | 367 | struct nofork_save_area nofork_save; |
| 378 | #endif | 368 | #endif |
| @@ -3661,6 +3651,15 @@ static void setup_job_control(void) | |||
| 3661 | int hush_main(int argc, char **argv); | 3651 | int hush_main(int argc, char **argv); |
| 3662 | int hush_main(int argc, char **argv) | 3652 | int hush_main(int argc, char **argv) |
| 3663 | { | 3653 | { |
| 3654 | static const char version_str[] = "HUSH_VERSION="HUSH_VER_STR; | ||
| 3655 | static const struct variable const_shell_ver = { | ||
| 3656 | .next = NULL, | ||
| 3657 | .varstr = (char*)version_str, | ||
| 3658 | .max_len = 1, /* 0 can provoke free(name) */ | ||
| 3659 | .flg_export = 1, | ||
| 3660 | .flg_read_only = 1, | ||
| 3661 | }; | ||
| 3662 | |||
| 3664 | int opt; | 3663 | int opt; |
| 3665 | FILE *input; | 3664 | FILE *input; |
| 3666 | char **e; | 3665 | char **e; |
| @@ -3668,12 +3667,14 @@ int hush_main(int argc, char **argv) | |||
| 3668 | 3667 | ||
| 3669 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | 3668 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); |
| 3670 | 3669 | ||
| 3670 | /* Deal with HUSH_VERSION */ | ||
| 3671 | shell_ver = const_shell_ver; /* copying struct here */ | 3671 | shell_ver = const_shell_ver; /* copying struct here */ |
| 3672 | top_var = &shell_ver; | 3672 | top_var = &shell_ver; |
| 3673 | /* initialize our shell local variables with the values | 3673 | unsetenv("HUSH_VERSION"); /* in case it exists in initial env */ |
| 3674 | /* Initialize our shell local variables with the values | ||
| 3674 | * currently living in the environment */ | 3675 | * currently living in the environment */ |
| 3675 | e = environ; | ||
| 3676 | cur_var = top_var; | 3676 | cur_var = top_var; |
| 3677 | e = environ; | ||
| 3677 | if (e) while (*e) { | 3678 | if (e) while (*e) { |
| 3678 | char *value = strchr(*e, '='); | 3679 | char *value = strchr(*e, '='); |
| 3679 | if (value) { /* paranoia */ | 3680 | if (value) { /* paranoia */ |
| @@ -3685,7 +3686,7 @@ int hush_main(int argc, char **argv) | |||
| 3685 | } | 3686 | } |
| 3686 | e++; | 3687 | e++; |
| 3687 | } | 3688 | } |
| 3688 | putenv(shell_ver.varstr); | 3689 | putenv((char *)version_str); /* reinstate HUSH_VERSION */ |
| 3689 | 3690 | ||
| 3690 | #if ENABLE_FEATURE_EDITING | 3691 | #if ENABLE_FEATURE_EDITING |
| 3691 | line_input_state = new_line_input_t(FOR_SHELL); | 3692 | line_input_state = new_line_input_t(FOR_SHELL); |
