aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--archival/bzip2.c6
-rw-r--r--archival/cpio.c4
-rw-r--r--archival/libarchive/bz/bzlib.c4
-rw-r--r--libbb/procps.c4
-rw-r--r--modutils/modprobe-small.c6
-rw-r--r--networking/httpd.c1
-rw-r--r--networking/tftp.c39
-rw-r--r--shell/hush.c105
-rw-r--r--util-linux/mkswap.c2
10 files changed, 86 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index f690ff4f2..e8bead003 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1VERSION = 1 1VERSION = 1
2PATCHLEVEL = 18 2PATCHLEVEL = 18
3SUBLEVEL = 1 3SUBLEVEL = 2
4EXTRAVERSION = 4EXTRAVERSION =
5NAME = Unnamed 5NAME = Unnamed
6 6
diff --git a/archival/bzip2.c b/archival/bzip2.c
index a6abc931c..ab08ffc1a 100644
--- a/archival/bzip2.c
+++ b/archival/bzip2.c
@@ -128,10 +128,12 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(unpack_info_t *info UNUSED_PA
128 break; 128 break;
129 } 129 }
130 130
131#if ENABLE_FEATURE_CLEAN_UP 131 /* Can't be conditional on ENABLE_FEATURE_CLEAN_UP -
132 * we are called repeatedly
133 */
132 BZ2_bzCompressEnd(strm); 134 BZ2_bzCompressEnd(strm);
133 free(iobuf); 135 free(iobuf);
134#endif 136
135 return total; 137 return total;
136} 138}
137 139
diff --git a/archival/cpio.c b/archival/cpio.c
index 6ab268821..9fa8badc5 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -308,16 +308,12 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
308 /* -L makes sense only with -o or -p */ 308 /* -L makes sense only with -o or -p */
309 309
310#if !ENABLE_FEATURE_CPIO_O 310#if !ENABLE_FEATURE_CPIO_O
311 /* no parameters */
312 opt_complementary = "=0";
313 opt = getopt32(argv, OPTION_STR, &cpio_filename); 311 opt = getopt32(argv, OPTION_STR, &cpio_filename);
314 argv += optind; 312 argv += optind;
315 if (opt & CPIO_OPT_FILE) { /* -F */ 313 if (opt & CPIO_OPT_FILE) { /* -F */
316 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); 314 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
317 } 315 }
318#else 316#else
319 /* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */
320 opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0";
321 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); 317 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
322 argv += optind; 318 argv += optind;
323 if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */ 319 if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
diff --git a/archival/libarchive/bz/bzlib.c b/archival/libarchive/bz/bzlib.c
index b3beeabed..5f7db747a 100644
--- a/archival/libarchive/bz/bzlib.c
+++ b/archival/libarchive/bz/bzlib.c
@@ -361,7 +361,6 @@ int BZ2_bzCompress(bz_stream *strm, int action)
361 361
362 362
363/*---------------------------------------------------*/ 363/*---------------------------------------------------*/
364#if ENABLE_FEATURE_CLEAN_UP
365static 364static
366void BZ2_bzCompressEnd(bz_stream *strm) 365void BZ2_bzCompressEnd(bz_stream *strm)
367{ 366{
@@ -372,9 +371,8 @@ void BZ2_bzCompressEnd(bz_stream *strm)
372 free(s->arr2); 371 free(s->arr2);
373 free(s->ftab); 372 free(s->ftab);
374 free(s->crc32table); 373 free(s->crc32table);
375 free(strm->state); 374 free(s);
376} 375}
377#endif
378 376
379 377
380/*---------------------------------------------------*/ 378/*---------------------------------------------------*/
diff --git a/libbb/procps.c b/libbb/procps.c
index 792466048..33932a3a3 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -154,6 +154,7 @@ static unsigned long fast_strtoul_10(char **endptr)
154 return n; 154 return n;
155} 155}
156 156
157# if ENABLE_FEATURE_FAST_TOP
157static long fast_strtol_10(char **endptr) 158static long fast_strtol_10(char **endptr)
158{ 159{
159 if (**endptr != '-') 160 if (**endptr != '-')
@@ -162,6 +163,7 @@ static long fast_strtol_10(char **endptr)
162 (*endptr)++; 163 (*endptr)++;
163 return - (long)fast_strtoul_10(endptr); 164 return - (long)fast_strtoul_10(endptr);
164} 165}
166# endif
165 167
166static char *skip_fields(char *str, int count) 168static char *skip_fields(char *str, int count)
167{ 169{
@@ -448,7 +450,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
448//FIXME: is it safe to assume this field exists? 450//FIXME: is it safe to assume this field exists?
449 sp->last_seen_on_cpu = fast_strtoul_10(&cp); 451 sp->last_seen_on_cpu = fast_strtoul_10(&cp);
450# endif 452# endif
451#endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */ 453#endif /* FEATURE_FAST_TOP */
452 454
453#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS 455#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
454 sp->niceness = tasknice; 456 sp->niceness = tasknice;
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index ec3ddfb8f..f4f17e766 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -844,13 +844,15 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
844 void *map; 844 void *map;
845 845
846 len = MAXINT(ssize_t); 846 len = MAXINT(ssize_t);
847 map = xmalloc_xopen_read_close(*argv, &len); 847 map = xmalloc_open_zipped_read_close(*argv, &len);
848 if (init_module(map, len, 848 if (init_module(map, len,
849 IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "") 849 IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "")
850 IF_NOT_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("") 850 IF_NOT_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("")
851 ) != 0) 851 ) != 0
852 ) {
852 bb_error_msg_and_die("can't insert '%s': %s", 853 bb_error_msg_and_die("can't insert '%s': %s",
853 *argv, moderror(errno)); 854 *argv, moderror(errno));
855 }
854 return 0; 856 return 0;
855 } 857 }
856 858
diff --git a/networking/httpd.c b/networking/httpd.c
index fa42d9850..b8113a843 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1522,6 +1522,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what)
1522 struct stat sb; 1522 struct stat sb;
1523 fstat(fd, &sb); 1523 fstat(fd, &sb);
1524 file_size = sb.st_size; 1524 file_size = sb.st_size;
1525 last_mod = sb.st_mtime;
1525 } else { 1526 } else {
1526 IF_FEATURE_HTTPD_GZIP(content_gzip = 0;) 1527 IF_FEATURE_HTTPD_GZIP(content_gzip = 0;)
1527 fd = open(url, O_RDONLY); 1528 fd = open(url, O_RDONLY);
diff --git a/networking/tftp.c b/networking/tftp.c
index 04c8f0ebb..fcd933f6a 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -105,39 +105,22 @@ struct BUG_G_too_big {
105#define error_pkt_str (error_pkt + 4) 105#define error_pkt_str (error_pkt + 4)
106 106
107#if ENABLE_FEATURE_TFTP_PROGRESS_BAR 107#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
108/* SIGALRM logic nicked from the wget applet */ 108static void tftp_progress_update(void)
109static void progress_meter(int flag)
110{ 109{
111 /* We can be called from signal handler */
112 int save_errno = errno;
113
114 if (flag == -1) { /* first call to progress_meter */
115 bb_progress_init(&G.pmt);
116 }
117
118 bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size); 110 bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size);
119
120 if (flag == 0) {
121 /* last call to progress_meter */
122 alarm(0);
123 bb_putchar_stderr('\n');
124 } else {
125 if (flag == -1) { /* first call to progress_meter */
126 signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
127 }
128 alarm(1);
129 }
130
131 errno = save_errno;
132} 111}
133static void tftp_progress_init(void) 112static void tftp_progress_init(void)
134{ 113{
135 progress_meter(-1); 114 bb_progress_init(&G.pmt);
115 tftp_progress_update();
136} 116}
137static void tftp_progress_done(void) 117static void tftp_progress_done(void)
138{ 118{
139 if (G.pmt.inited) 119 if (G.pmt.inited) {
140 progress_meter(0); 120 tftp_progress_update();
121 bb_putchar_stderr('\n');
122 G.pmt.inited = 0;
123 }
141} 124}
142#else 125#else
143# define tftp_progress_init() ((void)0) 126# define tftp_progress_init() ((void)0)
@@ -460,9 +443,10 @@ static int tftp_protocol(
460 xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len); 443 xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len);
461 444
462#if ENABLE_FEATURE_TFTP_PROGRESS_BAR 445#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
463 if (ENABLE_TFTP && remote_file) { /* tftp */ 446 if (ENABLE_TFTP && remote_file) /* tftp */
464 G.pos = (block_nr - 1) * (uoff_t)blksize; 447 G.pos = (block_nr - 1) * (uoff_t)blksize;
465 } 448 if (G.pmt.inited)
449 tftp_progress_update();
466#endif 450#endif
467 /* Was it final ACK? then exit */ 451 /* Was it final ACK? then exit */
468 if (finished && (opcode == TFTP_ACK)) 452 if (finished && (opcode == TFTP_ACK))
@@ -479,6 +463,7 @@ static int tftp_protocol(
479 case 0: 463 case 0:
480 retries--; 464 retries--;
481 if (retries == 0) { 465 if (retries == 0) {
466 tftp_progress_done();
482 bb_error_msg("timeout"); 467 bb_error_msg("timeout");
483 goto ret; /* no err packet sent */ 468 goto ret; /* no err packet sent */
484 } 469 }
diff --git a/shell/hush.c b/shell/hush.c
index fa7e4f563..f9f815289 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -913,7 +913,7 @@ static const struct built_in_command bltins2[] = {
913 */ 913 */
914#if HUSH_DEBUG 914#if HUSH_DEBUG
915/* prevent disasters with G.debug_indent < 0 */ 915/* prevent disasters with G.debug_indent < 0 */
916# define indent() fprintf(stderr, "%*s", (G.debug_indent * 2) & 0xff, "") 916# define indent() fdprintf(2, "%*s", (G.debug_indent * 2) & 0xff, "")
917# define debug_enter() (G.debug_indent++) 917# define debug_enter() (G.debug_indent++)
918# define debug_leave() (G.debug_indent--) 918# define debug_leave() (G.debug_indent--)
919#else 919#else
@@ -923,56 +923,56 @@ static const struct built_in_command bltins2[] = {
923#endif 923#endif
924 924
925#ifndef debug_printf 925#ifndef debug_printf
926# define debug_printf(...) (indent(), fprintf(stderr, __VA_ARGS__)) 926# define debug_printf(...) (indent(), fdprintf(2, __VA_ARGS__))
927#endif 927#endif
928 928
929#ifndef debug_printf_parse 929#ifndef debug_printf_parse
930# define debug_printf_parse(...) (indent(), fprintf(stderr, __VA_ARGS__)) 930# define debug_printf_parse(...) (indent(), fdprintf(2, __VA_ARGS__))
931#endif 931#endif
932 932
933#ifndef debug_printf_exec 933#ifndef debug_printf_exec
934#define debug_printf_exec(...) (indent(), fprintf(stderr, __VA_ARGS__)) 934#define debug_printf_exec(...) (indent(), fdprintf(2, __VA_ARGS__))
935#endif 935#endif
936 936
937#ifndef debug_printf_env 937#ifndef debug_printf_env
938# define debug_printf_env(...) (indent(), fprintf(stderr, __VA_ARGS__)) 938# define debug_printf_env(...) (indent(), fdprintf(2, __VA_ARGS__))
939#endif 939#endif
940 940
941#ifndef debug_printf_jobs 941#ifndef debug_printf_jobs
942# define debug_printf_jobs(...) (indent(), fprintf(stderr, __VA_ARGS__)) 942# define debug_printf_jobs(...) (indent(), fdprintf(2, __VA_ARGS__))
943# define DEBUG_JOBS 1 943# define DEBUG_JOBS 1
944#else 944#else
945# define DEBUG_JOBS 0 945# define DEBUG_JOBS 0
946#endif 946#endif
947 947
948#ifndef debug_printf_expand 948#ifndef debug_printf_expand
949# define debug_printf_expand(...) (indent(), fprintf(stderr, __VA_ARGS__)) 949# define debug_printf_expand(...) (indent(), fdprintf(2, __VA_ARGS__))
950# define DEBUG_EXPAND 1 950# define DEBUG_EXPAND 1
951#else 951#else
952# define DEBUG_EXPAND 0 952# define DEBUG_EXPAND 0
953#endif 953#endif
954 954
955#ifndef debug_printf_varexp 955#ifndef debug_printf_varexp
956# define debug_printf_varexp(...) (indent(), fprintf(stderr, __VA_ARGS__)) 956# define debug_printf_varexp(...) (indent(), fdprintf(2, __VA_ARGS__))
957#endif 957#endif
958 958
959#ifndef debug_printf_glob 959#ifndef debug_printf_glob
960# define debug_printf_glob(...) (indent(), fprintf(stderr, __VA_ARGS__)) 960# define debug_printf_glob(...) (indent(), fdprintf(2, __VA_ARGS__))
961# define DEBUG_GLOB 1 961# define DEBUG_GLOB 1
962#else 962#else
963# define DEBUG_GLOB 0 963# define DEBUG_GLOB 0
964#endif 964#endif
965 965
966#ifndef debug_printf_list 966#ifndef debug_printf_list
967# define debug_printf_list(...) (indent(), fprintf(stderr, __VA_ARGS__)) 967# define debug_printf_list(...) (indent(), fdprintf(2, __VA_ARGS__))
968#endif 968#endif
969 969
970#ifndef debug_printf_subst 970#ifndef debug_printf_subst
971# define debug_printf_subst(...) (indent(), fprintf(stderr, __VA_ARGS__)) 971# define debug_printf_subst(...) (indent(), fdprintf(2, __VA_ARGS__))
972#endif 972#endif
973 973
974#ifndef debug_printf_clean 974#ifndef debug_printf_clean
975# define debug_printf_clean(...) (indent(), fprintf(stderr, __VA_ARGS__)) 975# define debug_printf_clean(...) (indent(), fdprintf(2, __VA_ARGS__))
976# define DEBUG_CLEAN 1 976# define DEBUG_CLEAN 1
977#else 977#else
978# define DEBUG_CLEAN 0 978# define DEBUG_CLEAN 0
@@ -982,9 +982,9 @@ static const struct built_in_command bltins2[] = {
982static void debug_print_strings(const char *prefix, char **vv) 982static void debug_print_strings(const char *prefix, char **vv)
983{ 983{
984 indent(); 984 indent();
985 fprintf(stderr, "%s:\n", prefix); 985 fdprintf(2, "%s:\n", prefix);
986 while (*vv) 986 while (*vv)
987 fprintf(stderr, " '%s'\n", *vv++); 987 fdprintf(2, " '%s'\n", *vv++);
988} 988}
989#else 989#else
990# define debug_print_strings(prefix, vv) ((void)0) 990# define debug_print_strings(prefix, vv) ((void)0)
@@ -1416,6 +1416,22 @@ static void hush_exit(int exitcode)
1416 builtin_eval(argv); 1416 builtin_eval(argv);
1417 } 1417 }
1418 1418
1419#if ENABLE_FEATURE_CLEAN_UP
1420 {
1421 struct variable *cur_var;
1422 if (G.cwd != bb_msg_unknown)
1423 free((char*)G.cwd);
1424 cur_var = G.top_var;
1425 while (cur_var) {
1426 struct variable *tmp = cur_var;
1427 if (!cur_var->max_len)
1428 free(cur_var->varstr);
1429 cur_var = cur_var->next;
1430 free(tmp);
1431 }
1432 }
1433#endif
1434
1419#if ENABLE_HUSH_JOB 1435#if ENABLE_HUSH_JOB
1420 fflush_all(); 1436 fflush_all();
1421 sigexit(- (exitcode & 0xff)); 1437 sigexit(- (exitcode & 0xff));
@@ -2158,22 +2174,22 @@ static void debug_print_list(const char *prefix, o_string *o, int n)
2158 int i = 0; 2174 int i = 0;
2159 2175
2160 indent(); 2176 indent();
2161 fprintf(stderr, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n", 2177 fdprintf(2, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d glob:%d quoted:%d escape:%d\n",
2162 prefix, list, n, string_start, o->length, o->maxlen, 2178 prefix, list, n, string_start, o->length, o->maxlen,
2163 !!(o->o_expflags & EXP_FLAG_GLOB), 2179 !!(o->o_expflags & EXP_FLAG_GLOB),
2164 o->has_quoted_part, 2180 o->has_quoted_part,
2165 !!(o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); 2181 !!(o->o_expflags & EXP_FLAG_ESC_GLOB_CHARS));
2166 while (i < n) { 2182 while (i < n) {
2167 indent(); 2183 indent();
2168 fprintf(stderr, " list[%d]=%d '%s' %p\n", i, (int)list[i], 2184 fdprintf(2, " list[%d]=%d '%s' %p\n", i, (int)(uintptr_t)list[i],
2169 o->data + (int)list[i] + string_start, 2185 o->data + (int)(uintptr_t)list[i] + string_start,
2170 o->data + (int)list[i] + string_start); 2186 o->data + (int)(uintptr_t)list[i] + string_start);
2171 i++; 2187 i++;
2172 } 2188 }
2173 if (n) { 2189 if (n) {
2174 const char *p = o->data + (int)list[n - 1] + string_start; 2190 const char *p = o->data + (int)(uintptr_t)list[n - 1] + string_start;
2175 indent(); 2191 indent();
2176 fprintf(stderr, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data)); 2192 fdprintf(2, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data));
2177 } 2193 }
2178} 2194}
2179#else 2195#else
@@ -2672,18 +2688,18 @@ static void debug_print_tree(struct pipe *pi, int lvl)
2672 2688
2673 pin = 0; 2689 pin = 0;
2674 while (pi) { 2690 while (pi) {
2675 fprintf(stderr, "%*spipe %d res_word=%s followup=%d %s\n", lvl*2, "", 2691 fdprintf(2, "%*spipe %d res_word=%s followup=%d %s\n", lvl*2, "",
2676 pin, RES[pi->res_word], pi->followup, PIPE[pi->followup]); 2692 pin, RES[pi->res_word], pi->followup, PIPE[pi->followup]);
2677 prn = 0; 2693 prn = 0;
2678 while (prn < pi->num_cmds) { 2694 while (prn < pi->num_cmds) {
2679 struct command *command = &pi->cmds[prn]; 2695 struct command *command = &pi->cmds[prn];
2680 char **argv = command->argv; 2696 char **argv = command->argv;
2681 2697
2682 fprintf(stderr, "%*s cmd %d assignment_cnt:%d", 2698 fdprintf(2, "%*s cmd %d assignment_cnt:%d",
2683 lvl*2, "", prn, 2699 lvl*2, "", prn,
2684 command->assignment_cnt); 2700 command->assignment_cnt);
2685 if (command->group) { 2701 if (command->group) {
2686 fprintf(stderr, " group %s: (argv=%p)%s%s\n", 2702 fdprintf(2, " group %s: (argv=%p)%s%s\n",
2687 CMDTYPE[command->cmd_type], 2703 CMDTYPE[command->cmd_type],
2688 argv 2704 argv
2689# if !BB_MMU 2705# if !BB_MMU
@@ -2697,10 +2713,10 @@ static void debug_print_tree(struct pipe *pi, int lvl)
2697 continue; 2713 continue;
2698 } 2714 }
2699 if (argv) while (*argv) { 2715 if (argv) while (*argv) {
2700 fprintf(stderr, " '%s'", *argv); 2716 fdprintf(2, " '%s'", *argv);
2701 argv++; 2717 argv++;
2702 } 2718 }
2703 fprintf(stderr, "\n"); 2719 fdprintf(2, "\n");
2704 prn++; 2720 prn++;
2705 } 2721 }
2706 pi = pi->next; 2722 pi = pi->next;
@@ -4106,7 +4122,16 @@ static struct pipe *parse_stream(char **pstring,
4106 if (IS_NULL_CMD(ctx.command) 4122 if (IS_NULL_CMD(ctx.command)
4107 && dest.length == 0 && !dest.has_quoted_part 4123 && dest.length == 0 && !dest.has_quoted_part
4108 ) { 4124 ) {
4109 continue; 4125 /* This newline can be ignored. But...
4126 * without the below check, interactive shell
4127 * will ignore even lines with bare <newline>,
4128 * and show the continuation prompt:
4129 * ps1_prompt$ <enter>
4130 * ps2> _ <=== wrong prompt, should be ps1
4131 */
4132 struct pipe *pi = ctx.list_head;
4133 if (pi->num_cmds != 0)
4134 continue;
4110 } 4135 }
4111 /* Treat newline as a command separator. */ 4136 /* Treat newline as a command separator. */
4112 done_pipe(&ctx, PIPE_SEQ); 4137 done_pipe(&ctx, PIPE_SEQ);
@@ -7445,7 +7470,7 @@ int hush_main(int argc, char **argv)
7445 unsigned builtin_argc; 7470 unsigned builtin_argc;
7446 char **e; 7471 char **e;
7447 struct variable *cur_var; 7472 struct variable *cur_var;
7448 struct variable shell_ver; 7473 struct variable *shell_ver;
7449 7474
7450 INIT_G(); 7475 INIT_G();
7451 if (EXIT_SUCCESS) /* if EXIT_SUCCESS == 0, it is already done */ 7476 if (EXIT_SUCCESS) /* if EXIT_SUCCESS == 0, it is already done */
@@ -7454,17 +7479,17 @@ int hush_main(int argc, char **argv)
7454 G.argv0_for_re_execing = argv[0]; 7479 G.argv0_for_re_execing = argv[0];
7455#endif 7480#endif
7456 /* Deal with HUSH_VERSION */ 7481 /* Deal with HUSH_VERSION */
7457 memset(&shell_ver, 0, sizeof(shell_ver)); 7482 shell_ver = xzalloc(sizeof(*shell_ver));
7458 shell_ver.flg_export = 1; 7483 shell_ver->flg_export = 1;
7459 shell_ver.flg_read_only = 1; 7484 shell_ver->flg_read_only = 1;
7460 /* Code which handles ${var<op>...} needs writable values for all variables, 7485 /* Code which handles ${var<op>...} needs writable values for all variables,
7461 * therefore we xstrdup: */ 7486 * therefore we xstrdup: */
7462 shell_ver.varstr = xstrdup(hush_version_str), 7487 shell_ver->varstr = xstrdup(hush_version_str);
7463 G.top_var = &shell_ver;
7464 /* Create shell local variables from the values 7488 /* Create shell local variables from the values
7465 * currently living in the environment */ 7489 * currently living in the environment */
7466 debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION"); 7490 debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION");
7467 unsetenv("HUSH_VERSION"); /* in case it exists in initial env */ 7491 unsetenv("HUSH_VERSION"); /* in case it exists in initial env */
7492 G.top_var = shell_ver;
7468 cur_var = G.top_var; 7493 cur_var = G.top_var;
7469 e = environ; 7494 e = environ;
7470 if (e) while (*e) { 7495 if (e) while (*e) {
@@ -7479,8 +7504,8 @@ int hush_main(int argc, char **argv)
7479 e++; 7504 e++;
7480 } 7505 }
7481 /* (Re)insert HUSH_VERSION into env (AFTER we scanned the env!) */ 7506 /* (Re)insert HUSH_VERSION into env (AFTER we scanned the env!) */
7482 debug_printf_env("putenv '%s'\n", shell_ver.varstr); 7507 debug_printf_env("putenv '%s'\n", shell_ver->varstr);
7483 putenv(shell_ver.varstr); 7508 putenv(shell_ver->varstr);
7484 7509
7485 /* Export PWD */ 7510 /* Export PWD */
7486 set_pwd_var(/*exp:*/ 1); 7511 set_pwd_var(/*exp:*/ 1);
@@ -7840,18 +7865,6 @@ int hush_main(int argc, char **argv)
7840 parse_and_run_file(stdin); 7865 parse_and_run_file(stdin);
7841 7866
7842 final_return: 7867 final_return:
7843#if ENABLE_FEATURE_CLEAN_UP
7844 if (G.cwd != bb_msg_unknown)
7845 free((char*)G.cwd);
7846 cur_var = G.top_var->next;
7847 while (cur_var) {
7848 struct variable *tmp = cur_var;
7849 if (!cur_var->max_len)
7850 free(cur_var->varstr);
7851 cur_var = cur_var->next;
7852 free(tmp);
7853 }
7854#endif
7855 hush_exit(G.last_exitcode); 7868 hush_exit(G.last_exitcode);
7856} 7869}
7857 7870
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 53537fcd9..2e9662b2b 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -15,7 +15,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
15 if (!is_selinux_enabled()) 15 if (!is_selinux_enabled())
16 return; 16 return;
17 17
18 xfstat(fd, &stbuf, argv[0]); 18 xfstat(fd, &stbuf, path);
19 if (S_ISREG(stbuf.st_mode)) { 19 if (S_ISREG(stbuf.st_mode)) {
20 security_context_t newcon; 20 security_context_t newcon;
21 security_context_t oldcon = NULL; 21 security_context_t oldcon = NULL;