aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-13 19:55:50 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-13 19:55:50 +0000
commitf03dbeda90784fd9ac9ff4ed01f1257f6568d157 (patch)
tree400266d998f2d31feed37a82563d925ee2653d97 /shell
parentb636d8c18c8eb0a723ad7110fbfc2155e3cdb883 (diff)
downloadbusybox-w32-f03dbeda90784fd9ac9ff4ed01f1257f6568d157.tar.gz
busybox-w32-f03dbeda90784fd9ac9ff4ed01f1257f6568d157.tar.bz2
busybox-w32-f03dbeda90784fd9ac9ff4ed01f1257f6568d157.zip
hush: comment out and replace bug in set_local_var:
- if (value == 0 && ++value == 0) { + /*if (value == 0 && ++value == 0) ??? -vda */ + if (value == NULL || value[1] == '\0') { Style fixes.
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/shell/hush.c b/shell/hush.c
index eae0e10f5..458664ff2 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -629,7 +629,6 @@ static int builtin_jobs(struct child_prog *child ATTRIBUTE_UNUSED)
629 return EXIT_SUCCESS; 629 return EXIT_SUCCESS;
630} 630}
631 631
632
633/* built-in 'pwd' handler */ 632/* built-in 'pwd' handler */
634static int builtin_pwd(struct child_prog *dummy ATTRIBUTE_UNUSED) 633static int builtin_pwd(struct child_prog *dummy ATTRIBUTE_UNUSED)
635{ 634{
@@ -693,9 +692,8 @@ static int builtin_shift(struct child_prog *child)
693 global_argc -= n; 692 global_argc -= n;
694 global_argv += n; 693 global_argv += n;
695 return EXIT_SUCCESS; 694 return EXIT_SUCCESS;
696 } else {
697 return EXIT_FAILURE;
698 } 695 }
696 return EXIT_FAILURE;
699} 697}
700 698
701/* Built-in '.' handler (read-in and execute commands from file) */ 699/* Built-in '.' handler (read-in and execute commands from file) */
@@ -950,13 +948,12 @@ static int file_peek(struct in_str *i)
950{ 948{
951 if (i->p && *i->p) { 949 if (i->p && *i->p) {
952 return *i->p; 950 return *i->p;
953 } else {
954 i->peek_buf[0] = fgetc(i->file);
955 i->peek_buf[1] = '\0';
956 i->p = i->peek_buf;
957 debug_printf("b_peek: got a %d\n", *i->p);
958 return *i->p;
959 } 951 }
952 i->peek_buf[0] = fgetc(i->file);
953 i->peek_buf[1] = '\0';
954 i->p = i->peek_buf;
955 debug_printf("b_peek: got a %d\n", *i->p);
956 return *i->p;
960} 957}
961 958
962static void setup_file_in_str(struct in_str *i, FILE *f) 959static void setup_file_in_str(struct in_str *i, FILE *f)
@@ -1019,7 +1016,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
1019 } 1016 }
1020 if (redir->dup == -1) { 1017 if (redir->dup == -1) {
1021 mode = redir_table[redir->type].mode; 1018 mode = redir_table[redir->type].mode;
1022 openfd = open3_or_warn(redir->word.gl_pathv[0], mode, 0666); 1019 openfd = open_or_warn(redir->word.gl_pathv[0], mode);
1023 if (openfd < 0) { 1020 if (openfd < 0) {
1024 /* this could get lost if stderr has been redirected, but 1021 /* this could get lost if stderr has been redirected, but
1025 bash and ash both lose it as well (though zsh doesn't!) */ 1022 bash and ash both lose it as well (though zsh doesn't!) */
@@ -1038,7 +1035,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
1038 } else { 1035 } else {
1039 dup2(openfd, redir->fd); 1036 dup2(openfd, redir->fd);
1040 if (redir->dup == -1) 1037 if (redir->dup == -1)
1041 close (openfd); 1038 close(openfd);
1042 } 1039 }
1043 } 1040 }
1044 } 1041 }
@@ -1128,18 +1125,20 @@ static void pseudo_exec(struct child_prog *child)
1128 execvp(child->argv[0], child->argv); 1125 execvp(child->argv[0], child->argv);
1129 bb_perror_msg("cannot exec: %s", child->argv[0]); 1126 bb_perror_msg("cannot exec: %s", child->argv[0]);
1130 _exit(1); 1127 _exit(1);
1131 } else if (child->group) { 1128 }
1129
1130 if (child->group) {
1132 debug_printf("runtime nesting to group\n"); 1131 debug_printf("runtime nesting to group\n");
1133 interactive = 0; /* crucial!!!! */ 1132 interactive = 0; /* crucial!!!! */
1134 rcode = run_list_real(child->group); 1133 rcode = run_list_real(child->group);
1135 /* OK to leak memory by not calling free_pipe_list, 1134 /* OK to leak memory by not calling free_pipe_list,
1136 * since this process is about to exit */ 1135 * since this process is about to exit */
1137 _exit(rcode); 1136 _exit(rcode);
1138 } else {
1139 /* Can happen. See what bash does with ">foo" by itself. */
1140 debug_printf("trying to pseudo_exec null command\n");
1141 _exit(EXIT_SUCCESS);
1142 } 1137 }
1138
1139 /* Can happen. See what bash does with ">foo" by itself. */
1140 debug_printf("trying to pseudo_exec null command\n");
1141 _exit(EXIT_SUCCESS);
1143} 1142}
1144 1143
1145static void insert_bg_job(struct pipe *pi) 1144static void insert_bg_job(struct pipe *pi)
@@ -1157,7 +1156,7 @@ static void insert_bg_job(struct pipe *pi)
1157 thejob = job_list = xmalloc(sizeof(*thejob)); 1156 thejob = job_list = xmalloc(sizeof(*thejob));
1158 } else { 1157 } else {
1159 for (thejob = job_list; thejob->next; thejob = thejob->next) 1158 for (thejob = job_list; thejob->next; thejob = thejob->next)
1160 /* nothing */; 1159 continue;
1161 thejob->next = xmalloc(sizeof(*thejob)); 1160 thejob->next = xmalloc(sizeof(*thejob));
1162 thejob = thejob->next; 1161 thejob = thejob->next;
1163 } 1162 }
@@ -1320,9 +1319,11 @@ static int run_pipe_real(struct pipe *pi)
1320 rcode = run_list_real(child->group); 1319 rcode = run_list_real(child->group);
1321 restore_redirects(squirrel); 1320 restore_redirects(squirrel);
1322 return rcode; 1321 return rcode;
1323 } else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) { 1322 }
1323
1324 if (pi->num_progs == 1 && pi->progs[0].argv != NULL) {
1324 for (i = 0; is_assignment(child->argv[i]); i++) 1325 for (i = 0; is_assignment(child->argv[i]); i++)
1325 /* nothing */; 1326 continue;
1326 if (i != 0 && child->argv[i] == NULL) { 1327 if (i != 0 && child->argv[i] == NULL) {
1327 /* assignments, but no command: set the local environment */ 1328 /* assignments, but no command: set the local environment */
1328 for (i = 0; child->argv[i] != NULL; i++) { 1329 for (i = 0; child->argv[i] != NULL; i++) {
@@ -1359,7 +1360,7 @@ static int run_pipe_real(struct pipe *pi)
1359 } 1360 }
1360 } 1361 }
1361 if (child->sp) { 1362 if (child->sp) {
1362 char *str = NULL; 1363 char *str;
1363 1364
1364 str = make_string((child->argv + i)); 1365 str = make_string((child->argv + i));
1365 parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING); 1366 parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
@@ -1372,7 +1373,7 @@ static int run_pipe_real(struct pipe *pi)
1372 int rcode; 1373 int rcode;
1373 if (x->function == builtin_exec && child->argv[i+1] == NULL) { 1374 if (x->function == builtin_exec && child->argv[i+1] == NULL) {
1374 debug_printf("magic exec\n"); 1375 debug_printf("magic exec\n");
1375 setup_redirects(child,NULL); 1376 setup_redirects(child, NULL);
1376 return EXIT_SUCCESS; 1377 return EXIT_SUCCESS;
1377 } 1378 }
1378 debug_printf("builtin inline %s\n", child->argv[0]); 1379 debug_printf("builtin inline %s\n", child->argv[0]);
@@ -1404,7 +1405,7 @@ static int run_pipe_real(struct pipe *pi)
1404 } 1405 }
1405 1406
1406 /* XXX test for failed fork()? */ 1407 /* XXX test for failed fork()? */
1407#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__) 1408#if BB_MMU
1408 child->pid = fork(); 1409 child->pid = fork();
1409#else 1410#else
1410 child->pid = vfork(); 1411 child->pid = vfork();
@@ -1435,7 +1436,7 @@ static int run_pipe_real(struct pipe *pi)
1435 1436
1436 /* Like bash, explicit redirects override pipes, 1437 /* Like bash, explicit redirects override pipes,
1437 * and the pipe fd is available for dup'ing. */ 1438 * and the pipe fd is available for dup'ing. */
1438 setup_redirects(child,NULL); 1439 setup_redirects(child, NULL);
1439 1440
1440 if (interactive && pi->followup != PIPE_BG) { 1441 if (interactive && pi->followup != PIPE_BG) {
1441 /* If we (the child) win the race, put ourselves in the process 1442 /* If we (the child) win the race, put ourselves in the process
@@ -1803,11 +1804,12 @@ static int set_local_var(const char *s, int flg_export)
1803 * NAME=VALUE format. So the first order of business is to 1804 * NAME=VALUE format. So the first order of business is to
1804 * split 's' on the '=' into 'name' and 'value' */ 1805 * split 's' on the '=' into 'name' and 'value' */
1805 value = strchr(name, '='); 1806 value = strchr(name, '=');
1806 if (value == 0 && ++value == 0) { 1807 /*if (value == 0 && ++value == 0) ??? -vda */
1808 if (value == NULL || value[1] == '\0') {
1807 free(name); 1809 free(name);
1808 return -1; 1810 return -1;
1809 } 1811 }
1810 *value++ = 0; 1812 *value++ = '\0';
1811 1813
1812 for (cur = top_vars; cur; cur = cur->next) { 1814 for (cur = top_vars; cur; cur = cur->next) {
1813 if (strcmp(cur->name, name) == 0) 1815 if (strcmp(cur->name, name) == 0)
@@ -1820,17 +1822,15 @@ static int set_local_var(const char *s, int flg_export)
1820 cur->flg_export = flg_export; 1822 cur->flg_export = flg_export;
1821 else 1823 else
1822 result++; 1824 result++;
1825 } else if (cur->flg_read_only) {
1826 bb_error_msg("%s: readonly variable", name);
1827 result = -1;
1823 } else { 1828 } else {
1824 if (cur->flg_read_only) { 1829 if (flg_export > 0 || cur->flg_export > 1)
1825 bb_error_msg("%s: readonly variable", name); 1830 cur->flg_export = 1;
1826 result = -1; 1831 free((char*)cur->value);
1827 } else {
1828 if (flg_export > 0 || cur->flg_export > 1)
1829 cur->flg_export = 1;
1830 free((char*)cur->value);
1831 1832
1832 cur->value = strdup(value); 1833 cur->value = strdup(value);
1833 }
1834 } 1834 }
1835 } else { 1835 } else {
1836 cur = malloc(sizeof(struct variables)); 1836 cur = malloc(sizeof(struct variables));
@@ -2213,7 +2213,7 @@ static FILE *generate_stream_from_list(struct pipe *head)
2213 FILE *pf; 2213 FILE *pf;
2214 int pid, channel[2]; 2214 int pid, channel[2];
2215 if (pipe(channel) < 0) bb_perror_msg_and_die("pipe"); 2215 if (pipe(channel) < 0) bb_perror_msg_and_die("pipe");
2216#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__) 2216#if BB_MMU
2217 pid = fork(); 2217 pid = fork();
2218#else 2218#else
2219 pid = vfork(); 2219 pid = vfork();
@@ -2576,14 +2576,15 @@ int parse_stream(o_string *dest, struct p_context *ctx,
2576 * one before the EOF. Can't use the standard "syntax error" return code, 2576 * one before the EOF. Can't use the standard "syntax error" return code,
2577 * so that parse_stream_outer can distinguish the EOF and exit smoothly. */ 2577 * so that parse_stream_outer can distinguish the EOF and exit smoothly. */
2578 debug_printf("leaving parse_stream (EOF)\n"); 2578 debug_printf("leaving parse_stream (EOF)\n");
2579 if (end_trigger != '\0') return -1; 2579 if (end_trigger != '\0')
2580 return -1;
2580 return 0; 2581 return 0;
2581} 2582}
2582 2583
2583static void mapset(const char *set, int code) 2584static void mapset(const char *set, int code)
2584{ 2585{
2585 const unsigned char *s; 2586 while (*s)
2586 for (s = (const unsigned char *)set; *s; s++) map[(int)*s] = code; 2587 map[(unsigned char)*s++] = code;
2587} 2588}
2588 2589
2589static void update_ifs_map(void) 2590static void update_ifs_map(void)
@@ -2607,7 +2608,6 @@ static void update_ifs_map(void)
2607 * from builtin_source() */ 2608 * from builtin_source() */
2608int parse_stream_outer(struct in_str *inp, int flag) 2609int parse_stream_outer(struct in_str *inp, int flag)
2609{ 2610{
2610
2611 struct p_context ctx; 2611 struct p_context ctx;
2612 o_string temp = NULL_O_STRING; 2612 o_string temp = NULL_O_STRING;
2613 int rcode; 2613 int rcode;
@@ -2729,7 +2729,8 @@ int hush_main(int argc, char **argv)
2729 2729
2730 if (argv[0] && argv[0][0] == '-') { 2730 if (argv[0] && argv[0][0] == '-') {
2731 debug_printf("\nsourcing /etc/profile\n"); 2731 debug_printf("\nsourcing /etc/profile\n");
2732 if ((input = fopen("/etc/profile", "r")) != NULL) { 2732 input = fopen("/etc/profile", "r");
2733 if (input != NULL) {
2733 mark_open(fileno(input)); 2734 mark_open(fileno(input));
2734 parse_file_outer(input); 2735 parse_file_outer(input);
2735 mark_closed(fileno(input)); 2736 mark_closed(fileno(input));
@@ -2816,7 +2817,7 @@ int hush_main(int argc, char **argv)
2816 } 2817 }
2817#endif 2818#endif
2818 2819
2819final_return: 2820 final_return:
2820 return opt ? opt : last_return_code; 2821 return opt ? opt : last_return_code;
2821} 2822}
2822 2823
@@ -2877,7 +2878,8 @@ static char **make_list_in(char **inp, char *name)
2877 p1++; 2878 p1++;
2878 continue; 2879 continue;
2879 } 2880 }
2880 if ((p2 = strchr(p1, ' '))) { 2881 p2 = strchr(p1, ' ');
2882 if (p2) {
2881 len = p2 - p1; 2883 len = p2 - p1;
2882 } else { 2884 } else {
2883 len = strlen(p1); 2885 len = strlen(p1);
@@ -2920,7 +2922,7 @@ static char* make_string(char ** inp)
2920 if (p != inp[n]) free(p); 2922 if (p != inp[n]) free(p);
2921 } 2923 }
2922 len = strlen(str); 2924 len = strlen(str);
2923 *(str + len) = '\n'; 2925 str[len] = '\n';
2924 *(str + len + 1) = '\0'; 2926 str[len+1] = '\0';
2925 return str; 2927 return str;
2926} 2928}