aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-09-22 13:26:23 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-09-22 13:26:23 +0000
commit1f0ac23c20a2a65c45bb75f5e0431c9b68b800ea (patch)
treeaa93249abd758ea2e36f51dfc47437b820864d59
parent24cca8d9589614d4a10916d482859f06865f5a43 (diff)
downloadbusybox-w32-1f0ac23c20a2a65c45bb75f5e0431c9b68b800ea.tar.gz
busybox-w32-1f0ac23c20a2a65c45bb75f5e0431c9b68b800ea.tar.bz2
busybox-w32-1f0ac23c20a2a65c45bb75f5e0431c9b68b800ea.zip
very small size reduce for nohup applet
-rw-r--r--coreutils/nohup.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index 407cf00ea..c457bfd93 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -40,12 +40,12 @@ static inline int set_cloexec_flag (int desc)
40#define set_cloexec_flag(desc) (0) 40#define set_cloexec_flag(desc) (0)
41#endif 41#endif
42 42
43static int fd_reopen (int desired_fd, char const *file, int flags, mode_t mode) 43static int fd_reopen (int desired_fd, char const *file, int flags)
44{ 44{
45 int fd; 45 int fd;
46 46
47 close (desired_fd); 47 close (desired_fd);
48 fd = open (file, flags, mode); 48 fd = open (file, flags | O_WRONLY, S_IRUSR | S_IWUSR);
49 if (fd == desired_fd || fd < 0) 49 if (fd == desired_fd || fd < 0)
50 return fd; 50 return fd;
51 else { 51 else {
@@ -115,27 +115,25 @@ int nohup_main (int argc, char **argv)
115 Note that it is deliberately opened for *writing*, 115 Note that it is deliberately opened for *writing*,
116 to ensure any read evokes an error. */ 116 to ensure any read evokes an error. */
117 if (isatty (STDIN_FILENO)) 117 if (isatty (STDIN_FILENO))
118 fd_reopen (STDIN_FILENO, "/dev/null", O_WRONLY, 0); 118 fd_reopen (STDIN_FILENO, "/dev/null", 0);
119 119
120 /* If standard output is a tty, redirect it (appending) to a file. 120 /* If standard output is a tty, redirect it (appending) to a file.
121 First try nohup.out, then $HOME/nohup.out. */ 121 First try nohup.out, then $HOME/nohup.out. */
122 if (isatty (STDOUT_FILENO)) { 122 if (isatty (STDOUT_FILENO)) {
123 char *in_home = NULL; 123 char *in_home = NULL;
124 char const *file = "nohup.out"; 124 char const *file = "nohup.out";
125 int fd = fd_reopen (STDOUT_FILENO, file, 125 int fd = fd_reopen (STDOUT_FILENO, file, O_CREAT | O_APPEND);
126 O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
127 126
128 if (fd < 0) { 127 if (fd < 0) {
129 if ((in_home = getenv ("HOME")) != NULL) { 128 if ((in_home = getenv ("HOME")) != NULL) {
130 in_home = concat_path_file(in_home, file); 129 in_home = concat_path_file(in_home, file);
131 fd = fd_reopen (STDOUT_FILENO, in_home, 130 fd = fd_reopen (STDOUT_FILENO, in_home, O_CREAT | O_APPEND);
132 O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
133 } 131 }
134 if (fd < 0) { 132 if (fd < 0) {
135 bb_perror_msg("failed to open '%s'", file); 133 bb_perror_msg("failed to open '%s'", file);
136 if (in_home) 134 if (in_home)
137 bb_perror_msg("failed to open '%s'",in_home); 135 bb_perror_msg("failed to open '%s'",in_home);
138 exit (NOHUP_FAILURE); 136 return (NOHUP_FAILURE);
139 } 137 }
140 file = in_home; 138 file = in_home;
141 } 139 }
@@ -185,4 +183,3 @@ int nohup_main (int argc, char **argv)
185 return (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE); 183 return (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE);
186 } 184 }
187} 185}
188