aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-12-18 14:06:03 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-12-18 14:06:03 +0000
commit418ff464c5dcdfa8411ac3a67b1a9c8cd8b27e46 (patch)
tree661b06aed50c423157b9f39bd40aba6e5dd46ad0 /init
parent0b31c54b61af762d574892427a6dfeebbd07dc63 (diff)
downloadbusybox-w32-418ff464c5dcdfa8411ac3a67b1a9c8cd8b27e46.tar.gz
busybox-w32-418ff464c5dcdfa8411ac3a67b1a9c8cd8b27e46.tar.bz2
busybox-w32-418ff464c5dcdfa8411ac3a67b1a9c8cd8b27e46.zip
Vodz' last_patch31
Very minimal last corrections: 1) busybox.c: fix warining 2) docs/: add applets for list from pwd_grp 3) usage.h: add -n option for route 4) run_parts.c: many todo fix for busybox style 5) addgroup.c: add #ifdef CONFIG_FEATURE_SHADOWPASSWDS, reduce one perror_msg 6) adduser.c: fix bug "variable i not initialize" and add #ifdef CONFIG_FEATURE_SHADOWPASSWDS git-svn-id: svn://busybox.net/trunk/busybox@3900 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r--init/run_parts.c89
1 files changed, 23 insertions, 66 deletions
diff --git a/init/run_parts.c b/init/run_parts.c
index 258afb4db..3ec4b9d10 100644
--- a/init/run_parts.c
+++ b/init/run_parts.c
@@ -45,9 +45,9 @@
45 * done - convert calls to error in perror... and remove error() 45 * done - convert calls to error in perror... and remove error()
46 * done - convert malloc/realloc to their x... counterparts 46 * done - convert malloc/realloc to their x... counterparts
47 * done - remove catch_sigchld 47 * done - remove catch_sigchld
48 * use bb's isdirectory() ? It seems that no applet use it.
49 * done - use bb's concat_path_file() 48 * done - use bb's concat_path_file()
50 * declare run_parts_main() as extern and any other function as static? */ 49 * done - declare run_parts_main() as extern and any other function as static?
50 */
51 51
52#include <stdio.h> 52#include <stdio.h>
53#include <stdarg.h> 53#include <stdarg.h>
@@ -61,17 +61,14 @@
61#include <string.h> 61#include <string.h>
62#include <errno.h> 62#include <errno.h>
63#include <ctype.h> 63#include <ctype.h>
64/* #include <signal.h>
65 #include <sys/time.h> */
66 64
67#include "busybox.h" 65#include "busybox.h"
68 66
69int test_mode = 0; 67static int test_mode = 0;
70int verbose_mode = 0; 68static int exitstatus = 0;
71int exitstatus = 0;
72 69
73int argcount = 0, argsize = 0; 70static int argcount = 0, argsize = 0;
74char **args = 0; 71static char **args = 0;
75 72
76 73
77/* set_umask */ 74/* set_umask */
@@ -80,7 +77,7 @@ char **args = 0;
80 * 8 and 9 digits under some circumstances. We'll just have to live with it. 77 * 8 and 9 digits under some circumstances. We'll just have to live with it.
81 */ 78 */
82 79
83void set_umask (void) 80static void set_umask (void)
84{ 81{
85 int mask, result; 82 int mask, result;
86 83
@@ -97,14 +94,14 @@ void set_umask (void)
97/* add_argument */ 94/* add_argument */
98/* Add an argument to the commands that we will call. Called once for 95/* Add an argument to the commands that we will call. Called once for
99 every argument. */ 96 every argument. */
100void add_argument (char *newarg) 97static void add_argument (char *newarg)
101{ 98{
102 if (argcount+1 >= argsize) { 99 if (argcount+1 >= argsize) {
103 argsize = argsize ? argsize*2 : 4; 100 argsize = argsize ? argsize*2 : 4;
104 /*TODO if we convert to xrealloc we lose the verbose error message */ 101 /*TODO if we convert to xrealloc we lose the verbose error message */
105 args = realloc(args, argsize * (sizeof(char*))); 102 args = realloc(args, argsize * (sizeof(char*)));
106 if (!args) { 103 if (!args) {
107 perror_msg_and_die ("failed to reallocate memory for arguments: %s", strerror(errno)); 104 perror_msg_and_die ("failed to reallocate memory for arguments");
108 } 105 }
109 } 106 }
110 args[argcount++] = newarg; 107 args[argcount++] = newarg;
@@ -116,7 +113,7 @@ void add_argument (char *newarg)
116 * underscores, and hyphens only?) 113 * underscores, and hyphens only?)
117 */ 114 */
118 115
119int valid_name (const struct dirent *d) 116static int valid_name (const struct dirent *d)
120{ 117{
121 char *c = d->d_name; 118 char *c = d->d_name;
122 while (*c) { 119 while (*c) {
@@ -132,19 +129,19 @@ int valid_name (const struct dirent *d)
132/* run_part */ 129/* run_part */
133/* Execute a file */ 130/* Execute a file */
134 131
135void run_part (char *progname) 132static void run_part (char *progname)
136{ 133{
137 int result; 134 int result;
138 int pid; 135 int pid;
139 136
140 137
141 if ((pid=fork()) < 0) { 138 if ((pid=fork()) < 0) {
142 perror_msg_and_die ("failed to fork: %s", strerror(errno)); 139 perror_msg_and_die ("failed to fork");
143 } 140 }
144 else if (!pid) { 141 else if (!pid) {
145 args[0] = progname; 142 args[0] = progname;
146 execv (progname, args); 143 execv (progname, args);
147 perror_msg_and_die ("failed to exec %s: %s", progname, strerror (errno)); 144 perror_msg_and_die ("failed to exec %s", progname);
148 } 145 }
149 146
150 if (0) { 147 if (0) {
@@ -168,70 +165,30 @@ void run_part (char *progname)
168/* run_parts */ 165/* run_parts */
169/* Find the parts to run & call run_part() */ 166/* Find the parts to run & call run_part() */
170 167
171void run_parts (char *dir_name) 168static void run_parts (char *dir_name)
172{ 169{
173 struct dirent **namelist; 170 struct dirent **namelist = 0;
174 char *filename = NULL; 171 char *filename;
175 size_t filename_length, dir_name_length; 172 int entries, i;
176 int entries, i, result;
177 struct stat st; 173 struct stat st;
178 174
179 /* dir_name + "/" */
180 dir_name_length = strlen(dir_name) + 1;
181
182 /* dir_name + "/" + ".." + "\0" (This will save one realloc.) */
183 filename_length = dir_name_length + 2 + 1;
184
185 /* --
186 * Removed this part because I want try to use concat_path_file() */
187
188/* if (! (filename = malloc(filename_length))) {
189 error ("failed to allocate memory for path: %s", strerror(errno));
190 exit (1);
191 } */
192
193 /* -- */ 175 /* -- */
194 176
195 /* scandir() isn't POSIX, but it makes things easy. */ 177 /* scandir() isn't POSIX, but it makes things easy. */
196 entries = scandir (dir_name, &namelist, valid_name, alphasort); 178 entries = scandir (dir_name, &namelist, valid_name, alphasort);
197 179
198 if (entries < 0) { 180 if (entries < 0) {
199 perror_msg_and_die ("failed to open directory %s: %s", dir_name, strerror (errno)); 181 perror_msg_and_die ("failed to open directory %s", dir_name);
200 } 182 }
201 183
202 for (i = 0; i < entries; i++) { 184 for (i = 0; i < entries; i++) {
203 185
204 /* --
205 * Removed this part because I want try to use concat_path_file() */
206
207 /* if (filename_length < dir_name_length + strlen(namelist[i]->d_name) + 1) {
208 filename_length = dir_name_length + strlen(namelist[i]->d_name) + 1;
209 if (!(filename = realloc(filename, filename_length))) {
210 error ("failed to reallocate memory for path: %s", strerror(errno));
211 exit (1);
212 }
213 }
214
215 */
216
217 /* -- */
218
219
220 /* --
221 * Removed for concat_path_file() */
222
223/* strcpy (filename, dir_name);
224 strcat (filename, "/");
225 strcat (filename, namelist[i]->d_name); */
226
227 /* -- */ 186 /* -- */
228 187
229 filename = concat_path_file (dir_name, namelist[i]->d_name); 188 filename = concat_path_file (dir_name, namelist[i]->d_name);
230 189
231 result = stat (filename, &st); 190 if (stat (filename, &st) < 0) {
232 if (result < 0) { 191 perror_msg_and_die ("failed to stat component %s", filename);
233 perror_msg_and_die ("failed to stat component %s: %s", filename,
234 strerror (errno));
235 } 192 }
236 if (S_ISREG(st.st_mode) && !access (filename, X_OK)) { 193 if (S_ISREG(st.st_mode) && !access (filename, X_OK)) {
237 if (test_mode) 194 if (test_mode)
@@ -240,17 +197,17 @@ void run_parts (char *dir_name)
240 run_part (filename); 197 run_part (filename);
241 } 198 }
242 } 199 }
243 /*TODO convert to isdirectory() */ 200
244 else if (!S_ISDIR(st.st_mode)) { 201 else if (!S_ISDIR(st.st_mode)) {
245 printf ("run-parts: component %s is not an executable plain file\n", 202 error_msg ("component %s is not an executable plain file",
246 filename); 203 filename);
247 exitstatus = 1; 204 exitstatus = 1;
248 } 205 }
249 206
250 free (namelist[i]); 207 free (namelist[i]);
208 free (filename);
251 } 209 }
252 free (namelist); 210 free (namelist);
253 free (filename);
254} 211}
255 212
256/* run_parts_main */ 213/* run_parts_main */