aboutsummaryrefslogtreecommitdiff
path: root/shell/lash.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /shell/lash.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'shell/lash.c')
-rw-r--r--shell/lash.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/shell/lash.c b/shell/lash.c
index 35929898e..8f864b355 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -246,7 +246,7 @@ static int builtin_cd(struct child_prog *child)
246 } 246 }
247 cwd = xgetcwd((char *)cwd); 247 cwd = xgetcwd((char *)cwd);
248 if (!cwd) 248 if (!cwd)
249 cwd = unknown; 249 cwd = bb_msg_unknown;
250 return EXIT_SUCCESS; 250 return EXIT_SUCCESS;
251} 251}
252 252
@@ -284,12 +284,12 @@ static int builtin_fg_bg(struct child_prog *child)
284 } 284 }
285 } 285 }
286 if (!job) { 286 if (!job) {
287 error_msg("%s: no current job", child->argv[0]); 287 bb_error_msg("%s: no current job", child->argv[0]);
288 return EXIT_FAILURE; 288 return EXIT_FAILURE;
289 } 289 }
290 } else { 290 } else {
291 if (sscanf(child->argv[1], "%%%d", &jobnum) != 1) { 291 if (sscanf(child->argv[1], "%%%d", &jobnum) != 1) {
292 error_msg("%s: bad argument '%s'", child->argv[0], child->argv[1]); 292 bb_error_msg("%s: bad argument '%s'", child->argv[0], child->argv[1]);
293 return EXIT_FAILURE; 293 return EXIT_FAILURE;
294 } 294 }
295 for (job = child->family->job_list->head; job; job = job->next) { 295 for (job = child->family->job_list->head; job; job = job->next) {
@@ -298,7 +298,7 @@ static int builtin_fg_bg(struct child_prog *child)
298 } 298 }
299 } 299 }
300 if (!job) { 300 if (!job) {
301 error_msg("%s: %d: no such job", child->argv[0], jobnum); 301 bb_error_msg("%s: %d: no such job", child->argv[0], jobnum);
302 return EXIT_FAILURE; 302 return EXIT_FAILURE;
303 } 303 }
304 } 304 }
@@ -320,7 +320,7 @@ static int builtin_fg_bg(struct child_prog *child)
320 if (i == ESRCH) { 320 if (i == ESRCH) {
321 remove_job(&job_list, job); 321 remove_job(&job_list, job);
322 } else { 322 } else {
323 perror_msg("kill (SIGCONT)"); 323 bb_perror_msg("kill (SIGCONT)");
324 } 324 }
325 } 325 }
326 326
@@ -371,7 +371,7 @@ static int builtin_pwd(struct child_prog *dummy)
371{ 371{
372 cwd = xgetcwd((char *)cwd); 372 cwd = xgetcwd((char *)cwd);
373 if (!cwd) 373 if (!cwd)
374 cwd = unknown; 374 cwd = bb_msg_unknown;
375 puts(cwd); 375 puts(cwd);
376 return EXIT_SUCCESS; 376 return EXIT_SUCCESS;
377} 377}
@@ -489,7 +489,7 @@ static void mark_closed(int fd)
489{ 489{
490 struct close_me *tmp; 490 struct close_me *tmp;
491 if (close_me_head == NULL || close_me_head->fd != fd) 491 if (close_me_head == NULL || close_me_head->fd != fd)
492 error_msg_and_die("corrupt close_me"); 492 bb_error_msg_and_die("corrupt close_me");
493 tmp = close_me_head; 493 tmp = close_me_head;
494 close_me_head = close_me_head->next; 494 close_me_head = close_me_head->next;
495 free(tmp); 495 free(tmp);
@@ -599,7 +599,7 @@ static void checkjobs(struct jobset *j_list)
599 } 599 }
600 600
601 if (childpid == -1 && errno != ECHILD) 601 if (childpid == -1 && errno != ECHILD)
602 perror_msg("waitpid"); 602 bb_perror_msg("waitpid");
603} 603}
604 604
605/* squirrel != NULL means we squirrel away copies of stdin, stdout, 605/* squirrel != NULL means we squirrel away copies of stdin, stdout,
@@ -628,7 +628,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
628 if (openfd < 0) { 628 if (openfd < 0) {
629 /* this could get lost if stderr has been redirected, but 629 /* this could get lost if stderr has been redirected, but
630 bash and ash both lose it as well (though zsh doesn't!) */ 630 bash and ash both lose it as well (though zsh doesn't!) */
631 perror_msg("error opening %s", redir->filename); 631 bb_perror_msg("error opening %s", redir->filename);
632 return 1; 632 return 1;
633 } 633 }
634 634
@@ -803,7 +803,7 @@ static int expand_arguments(char *command)
803 while( command && command[ix]) { 803 while( command && command[ix]) {
804 if (command[ix] == '\\') { 804 if (command[ix] == '\\') {
805 const char *tmp = command+ix+1; 805 const char *tmp = command+ix+1;
806 command[ix] = process_escape_sequence( &tmp ); 806 command[ix] = bb_process_escape_sequence( &tmp );
807 memmove(command+ix + 1, tmp, strlen(tmp)+1); 807 memmove(command+ix + 1, tmp, strlen(tmp)+1);
808 } 808 }
809 ix++; 809 ix++;
@@ -816,7 +816,7 @@ static int expand_arguments(char *command)
816 816
817 /* We need a clean copy, so strsep can mess up the copy while 817 /* We need a clean copy, so strsep can mess up the copy while
818 * we write stuff into the original (in a minute) */ 818 * we write stuff into the original (in a minute) */
819 cmd = cmd_copy = xstrdup(command); 819 cmd = cmd_copy = bb_xstrdup(command);
820 *command = '\0'; 820 *command = '\0';
821 for (ix = 0, tmpcmd = cmd; 821 for (ix = 0, tmpcmd = cmd;
822 (tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) { 822 (tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) {
@@ -829,13 +829,13 @@ static int expand_arguments(char *command)
829 if (retval == GLOB_NOSPACE) { 829 if (retval == GLOB_NOSPACE) {
830 /* Mem may have been allocated... */ 830 /* Mem may have been allocated... */
831 globfree (&expand_result); 831 globfree (&expand_result);
832 error_msg(out_of_space); 832 bb_error_msg(out_of_space);
833 return FALSE; 833 return FALSE;
834 } else if (retval != 0) { 834 } else if (retval != 0) {
835 /* Some other error. GLOB_NOMATCH shouldn't 835 /* Some other error. GLOB_NOMATCH shouldn't
836 * happen because of the GLOB_NOCHECK flag in 836 * happen because of the GLOB_NOCHECK flag in
837 * the glob call. */ 837 * the glob call. */
838 error_msg("syntax error"); 838 bb_error_msg("syntax error");
839 return FALSE; 839 return FALSE;
840 } else { 840 } else {
841 /* Convert from char** (one word per string) to a simple char*, 841 /* Convert from char** (one word per string) to a simple char*,
@@ -843,7 +843,7 @@ static int expand_arguments(char *command)
843 for (i=0; i < expand_result.gl_pathc; i++) { 843 for (i=0; i < expand_result.gl_pathc; i++) {
844 length=strlen(expand_result.gl_pathv[i]); 844 length=strlen(expand_result.gl_pathv[i]);
845 if (total_length+length+1 >= BUFSIZ) { 845 if (total_length+length+1 >= BUFSIZ) {
846 error_msg(out_of_space); 846 bb_error_msg(out_of_space);
847 return FALSE; 847 return FALSE;
848 } 848 }
849 strcat(command+total_length, " "); 849 strcat(command+total_length, " ");
@@ -930,7 +930,7 @@ static int expand_arguments(char *command)
930 int subst_len = strlen(var); 930 int subst_len = strlen(var);
931 int trail_len = strlen(src); 931 int trail_len = strlen(src);
932 if (dst+subst_len+trail_len >= command+BUFSIZ) { 932 if (dst+subst_len+trail_len >= command+BUFSIZ) {
933 error_msg(out_of_space); 933 bb_error_msg(out_of_space);
934 return FALSE; 934 return FALSE;
935 } 935 }
936 /* Move stuff to the end of the string to accommodate 936 /* Move stuff to the end of the string to accommodate
@@ -1006,7 +1006,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
1006 if (*src == '\\') { 1006 if (*src == '\\') {
1007 src++; 1007 src++;
1008 if (!*src) { 1008 if (!*src) {
1009 error_msg("character expected after \\"); 1009 bb_error_msg("character expected after \\");
1010 free_job(job); 1010 free_job(job);
1011 return 1; 1011 return 1;
1012 } 1012 }
@@ -1090,7 +1090,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
1090 chptr++; 1090 chptr++;
1091 1091
1092 if (!*chptr) { 1092 if (!*chptr) {
1093 error_msg("file name expected after %c", *(src-1)); 1093 bb_error_msg("file name expected after %c", *(src-1));
1094 free_job(job); 1094 free_job(job);
1095 job->num_progs=0; 1095 job->num_progs=0;
1096 return 1; 1096 return 1;
@@ -1109,7 +1109,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
1109 if (*prog->argv[argc_l] || saw_quote) 1109 if (*prog->argv[argc_l] || saw_quote)
1110 argc_l++; 1110 argc_l++;
1111 if (!argc_l) { 1111 if (!argc_l) {
1112 error_msg("empty command in pipe"); 1112 bb_error_msg("empty command in pipe");
1113 free_job(job); 1113 free_job(job);
1114 job->num_progs=0; 1114 job->num_progs=0;
1115 return 1; 1115 return 1;
@@ -1136,7 +1136,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
1136 src++; 1136 src++;
1137 1137
1138 if (!*src) { 1138 if (!*src) {
1139 error_msg("empty command in pipe"); 1139 bb_error_msg("empty command in pipe");
1140 free_job(job); 1140 free_job(job);
1141 job->num_progs=0; 1141 job->num_progs=0;
1142 return 1; 1142 return 1;
@@ -1155,7 +1155,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
1155 case '\\': 1155 case '\\':
1156 src++; 1156 src++;
1157 if (!*src) { 1157 if (!*src) {
1158 error_msg("character expected after \\"); 1158 bb_error_msg("character expected after \\");
1159 free_job(job); 1159 free_job(job);
1160 return 1; 1160 return 1;
1161 } 1161 }
@@ -1217,7 +1217,7 @@ static int pseudo_exec(struct child_prog *child)
1217 /* Check if the command matches any of the forking builtins. */ 1217 /* Check if the command matches any of the forking builtins. */
1218 for (x = bltins_forking; x->cmd; x++) { 1218 for (x = bltins_forking; x->cmd; x++) {
1219 if (strcmp(child->argv[0], x->cmd) == 0) { 1219 if (strcmp(child->argv[0], x->cmd) == 0) {
1220 applet_name=x->cmd; 1220 bb_applet_name=x->cmd;
1221 _exit (x->function(child)); 1221 _exit (x->function(child));
1222 } 1222 }
1223 } 1223 }
@@ -1225,7 +1225,7 @@ static int pseudo_exec(struct child_prog *child)
1225 /* Check if the command matches any busybox internal 1225 /* Check if the command matches any busybox internal
1226 * commands ("applets") here. Following discussions from 1226 * commands ("applets") here. Following discussions from
1227 * November 2000 on busybox@busybox.net, don't use 1227 * November 2000 on busybox@busybox.net, don't use
1228 * get_last_path_component(). This way explicit (with 1228 * bb_get_last_path_component(). This way explicit (with
1229 * slashes) filenames will never be interpreted as an 1229 * slashes) filenames will never be interpreted as an
1230 * applet, just like with builtins. This way the user can 1230 * applet, just like with builtins. This way the user can
1231 * override an applet with an explicit filename reference. 1231 * override an applet with an explicit filename reference.
@@ -1241,7 +1241,7 @@ static int pseudo_exec(struct child_prog *child)
1241 * /bin/cat exists on the filesystem and is _not_ busybox. 1241 * /bin/cat exists on the filesystem and is _not_ busybox.
1242 * Some systems want this, others do not. Choose wisely. :-) 1242 * Some systems want this, others do not. Choose wisely. :-)
1243 */ 1243 */
1244 name = get_last_path_component(name); 1244 name = bb_get_last_path_component(name);
1245#endif 1245#endif
1246 1246
1247 { 1247 {
@@ -1255,7 +1255,7 @@ static int pseudo_exec(struct child_prog *child)
1255 1255
1256 execvp(child->argv[0], child->argv); 1256 execvp(child->argv[0], child->argv);
1257 1257
1258 /* Do not use perror_msg_and_die() here, since we must not 1258 /* Do not use bb_perror_msg_and_die() here, since we must not
1259 * call exit() but should call _exit() instead */ 1259 * call exit() but should call _exit() instead */
1260 fprintf(stderr, "%s: %m\n", child->argv[0]); 1260 fprintf(stderr, "%s: %m\n", child->argv[0]);
1261 _exit(EXIT_FAILURE); 1261 _exit(EXIT_FAILURE);
@@ -1299,7 +1299,7 @@ static void insert_job(struct job *newjob, int inbg)
1299 /* move the new process group into the foreground */ 1299 /* move the new process group into the foreground */
1300 /* suppress messages when run from /linuxrc mag@sysgo.de */ 1300 /* suppress messages when run from /linuxrc mag@sysgo.de */
1301 if (tcsetpgrp(shell_terminal, newjob->pgrp) && errno != ENOTTY) 1301 if (tcsetpgrp(shell_terminal, newjob->pgrp) && errno != ENOTTY)
1302 perror_msg("tcsetpgrp"); 1302 bb_perror_msg("tcsetpgrp");
1303 } 1303 }
1304} 1304}
1305 1305
@@ -1317,7 +1317,7 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2])
1317 child = & (newjob->progs[i]); 1317 child = & (newjob->progs[i]);
1318 1318
1319 if ((i + 1) < newjob->num_progs) { 1319 if ((i + 1) < newjob->num_progs) {
1320 if (pipe(pipefds)<0) perror_msg_and_die("pipe"); 1320 if (pipe(pipefds)<0) bb_perror_msg_and_die("pipe");
1321 nextout = pipefds[1]; 1321 nextout = pipefds[1];
1322 } else { 1322 } else {
1323 if (outpipe[1]!=-1) { 1323 if (outpipe[1]!=-1) {
@@ -1464,7 +1464,7 @@ static int busy_loop(FILE * input)
1464 1464
1465 if (waitpid(job_list.fg->progs[i].pid, &status, WUNTRACED)<0) { 1465 if (waitpid(job_list.fg->progs[i].pid, &status, WUNTRACED)<0) {
1466 if (errno != ECHILD) { 1466 if (errno != ECHILD) {
1467 perror_msg_and_die("waitpid(%d)",job_list.fg->progs[i].pid); 1467 bb_perror_msg_and_die("waitpid(%d)",job_list.fg->progs[i].pid);
1468 } 1468 }
1469 } 1469 }
1470 1470
@@ -1496,7 +1496,7 @@ static int busy_loop(FILE * input)
1496 /* move the shell to the foreground */ 1496 /* move the shell to the foreground */
1497 /* suppress messages when run from /linuxrc mag@sysgo.de */ 1497 /* suppress messages when run from /linuxrc mag@sysgo.de */
1498 if (tcsetpgrp(shell_terminal, getpgrp()) && errno != ENOTTY) 1498 if (tcsetpgrp(shell_terminal, getpgrp()) && errno != ENOTTY)
1499 perror_msg("tcsetpgrp"); 1499 bb_perror_msg("tcsetpgrp");
1500 } 1500 }
1501 } 1501 }
1502 } 1502 }
@@ -1504,7 +1504,7 @@ static int busy_loop(FILE * input)
1504 1504
1505 /* return controlling TTY back to parent process group before exiting */ 1505 /* return controlling TTY back to parent process group before exiting */
1506 if (tcsetpgrp(shell_terminal, parent_pgrp) && errno != ENOTTY) 1506 if (tcsetpgrp(shell_terminal, parent_pgrp) && errno != ENOTTY)
1507 perror_msg("tcsetpgrp"); 1507 bb_perror_msg("tcsetpgrp");
1508 1508
1509 /* return exit status if called with "-c" */ 1509 /* return exit status if called with "-c" */
1510 if (input == NULL && WIFEXITED(status)) 1510 if (input == NULL && WIFEXITED(status))
@@ -1517,7 +1517,7 @@ static int busy_loop(FILE * input)
1517#ifdef CONFIG_FEATURE_CLEAN_UP 1517#ifdef CONFIG_FEATURE_CLEAN_UP
1518void free_memory(void) 1518void free_memory(void)
1519{ 1519{
1520 if (cwd && cwd!=unknown) { 1520 if (cwd && cwd!=bb_msg_unknown) {
1521 free((char*)cwd); 1521 free((char*)cwd);
1522 } 1522 }
1523 if (local_pending_command) 1523 if (local_pending_command)
@@ -1594,8 +1594,8 @@ int lash_main(int argc_l, char **argv_l)
1594 case 'c': 1594 case 'c':
1595 input = NULL; 1595 input = NULL;
1596 if (local_pending_command != 0) 1596 if (local_pending_command != 0)
1597 error_msg_and_die("multiple -c arguments"); 1597 bb_error_msg_and_die("multiple -c arguments");
1598 local_pending_command = xstrdup(argv[optind]); 1598 local_pending_command = bb_xstrdup(argv[optind]);
1599 optind++; 1599 optind++;
1600 argv = argv+optind; 1600 argv = argv+optind;
1601 break; 1601 break;
@@ -1603,7 +1603,7 @@ int lash_main(int argc_l, char **argv_l)
1603 interactive = TRUE; 1603 interactive = TRUE;
1604 break; 1604 break;
1605 default: 1605 default:
1606 show_usage(); 1606 bb_show_usage();
1607 } 1607 }
1608 } 1608 }
1609 /* A shell is interactive if the `-i' flag was given, or if all of 1609 /* A shell is interactive if the `-i' flag was given, or if all of
@@ -1627,14 +1627,14 @@ int lash_main(int argc_l, char **argv_l)
1627#endif 1627#endif
1628 } else if (local_pending_command==NULL) { 1628 } else if (local_pending_command==NULL) {
1629 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1629 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1630 input = xfopen(argv[optind], "r"); 1630 input = bb_xfopen(argv[optind], "r");
1631 mark_open(fileno(input)); /* be lazy, never mark this closed */ 1631 mark_open(fileno(input)); /* be lazy, never mark this closed */
1632 } 1632 }
1633 1633
1634 /* initialize the cwd -- this is never freed...*/ 1634 /* initialize the cwd -- this is never freed...*/
1635 cwd = xgetcwd(0); 1635 cwd = xgetcwd(0);
1636 if (!cwd) 1636 if (!cwd)
1637 cwd = unknown; 1637 cwd = bb_msg_unknown;
1638 1638
1639#ifdef CONFIG_FEATURE_CLEAN_UP 1639#ifdef CONFIG_FEATURE_CLEAN_UP
1640 atexit(free_memory); 1640 atexit(free_memory);