summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-30 23:50:48 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-30 23:50:48 +0000
commit96e1b38586e80a0f014038bf4fdf4689c668fbd6 (patch)
treed7f6a7866700601598cfcc006b7dcb6cb4a7c07e /shell
parentdeabacdf91c6d1c3cfcdb4cd06780807193de81d (diff)
downloadbusybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.tar.gz
busybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.tar.bz2
busybox-w32-96e1b38586e80a0f014038bf4fdf4689c668fbd6.zip
introduce and use close_on_exec_on(fd). -50 bytes.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c4
-rw-r--r--shell/hush.c8
-rw-r--r--shell/lash.c2
3 files changed, 8 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 183911ccc..9d8b83c18 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -3469,7 +3469,7 @@ setjobctl(int on)
3469 close(ofd); 3469 close(ofd);
3470 if (fd < 0) 3470 if (fd < 0)
3471 goto out; 3471 goto out;
3472 fcntl(fd, F_SETFD, FD_CLOEXEC); 3472 close_on_exec_on(fd);
3473 do { /* while we are in the background */ 3473 do { /* while we are in the background */
3474 pgrp = tcgetpgrp(fd); 3474 pgrp = tcgetpgrp(fd);
3475 if (pgrp < 0) { 3475 if (pgrp < 0) {
@@ -8830,7 +8830,7 @@ closescript(void)
8830static void 8830static void
8831setinputfd(int fd, int push) 8831setinputfd(int fd, int push)
8832{ 8832{
8833 fcntl(fd, F_SETFD, FD_CLOEXEC); 8833 close_on_exec_on(fd);
8834 if (push) { 8834 if (push) {
8835 pushfile(); 8835 pushfile();
8836 parsefile->buf = 0; 8836 parsefile->buf = 0;
diff --git a/shell/hush.c b/shell/hush.c
index 5f9f2c5c1..9c705568d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -760,9 +760,11 @@ static int builtin_eval(char **argv)
760static int builtin_cd(char **argv) 760static int builtin_cd(char **argv)
761{ 761{
762 const char *newdir; 762 const char *newdir;
763 if (argv[1] == NULL) 763 if (argv[1] == NULL) {
764 // bash does nothing (exitcode 0) if HOME is ""; if it's unset,
765 // bash says "bash: cd: HOME not set" and does nothing (exitcode 1)
764 newdir = getenv("HOME") ? : "/"; 766 newdir = getenv("HOME") ? : "/";
765 else 767 } else
766 newdir = argv[1]; 768 newdir = argv[1];
767 if (chdir(newdir)) { 769 if (chdir(newdir)) {
768 printf("cd: %s: %s\n", newdir, strerror(errno)); 770 printf("cd: %s: %s\n", newdir, strerror(errno));
@@ -3629,7 +3631,7 @@ static void setup_job_control(void)
3629 3631
3630 saved_task_pgrp = shell_pgrp = getpgrp(); 3632 saved_task_pgrp = shell_pgrp = getpgrp();
3631 debug_printf_jobs("saved_task_pgrp=%d\n", saved_task_pgrp); 3633 debug_printf_jobs("saved_task_pgrp=%d\n", saved_task_pgrp);
3632 fcntl(interactive_fd, F_SETFD, FD_CLOEXEC); 3634 close_on_exec_on(interactive_fd);
3633 3635
3634 /* If we were ran as 'hush &', 3636 /* If we were ran as 'hush &',
3635 * sleep until we are in the foreground. */ 3637 * sleep until we are in the foreground. */
diff --git a/shell/lash.c b/shell/lash.c
index 5ba490f2a..af3a8f80b 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -576,7 +576,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
576 if (openfd != redir->fd) { 576 if (openfd != redir->fd) {
577 if (squirrel && redir->fd < 3) { 577 if (squirrel && redir->fd < 3) {
578 squirrel[redir->fd] = dup(redir->fd); 578 squirrel[redir->fd] = dup(redir->fd);
579 fcntl(squirrel[redir->fd], F_SETFD, FD_CLOEXEC); 579 close_on_exec_on(squirrel[redir->fd]);
580 } 580 }
581 dup2(openfd, redir->fd); 581 dup2(openfd, redir->fd);
582 close(openfd); 582 close(openfd);