summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-27 02:31:32 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-27 02:31:32 +0000
commita745606df39d10664080c857dea6fd3583a8743a (patch)
treef926d4c44909df191f42d38ae9be47512caa15a8 /init
parentc8fdb5638952993dcfe7950e4e2513811e8e9137 (diff)
downloadbusybox-w32-a745606df39d10664080c857dea6fd3583a8743a.tar.gz
busybox-w32-a745606df39d10664080c857dea6fd3583a8743a.tar.bz2
busybox-w32-a745606df39d10664080c857dea6fd3583a8743a.zip
Stuf
Diffstat (limited to 'init')
-rw-r--r--init/init.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/init/init.c b/init/init.c
index 2834a4a05..83fc9519a 100644
--- a/init/init.c
+++ b/init/init.c
@@ -52,6 +52,7 @@
52#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin" 52#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
53 53
54static char *console = CONSOLE; 54static char *console = CONSOLE;
55static char *first_terminal = "/dev/tty1";
55static char *second_terminal = "/dev/tty2"; 56static char *second_terminal = "/dev/tty2";
56static char *log = "/dev/tty3"; 57static char *log = "/dev/tty3";
57 58
@@ -87,8 +88,13 @@ void message(char *device, char *fmt, ...)
87 vdprintf(fd, fmt, arguments); 88 vdprintf(fd, fmt, arguments);
88 va_end(arguments); 89 va_end(arguments);
89 close(fd); 90 close(fd);
90 } else 91 } else {
91 vprintf(fmt, arguments); 92 fprintf(stderr, "Bummer, can't print: ");
93 va_start(arguments, fmt);
94 vfprintf(stderr, fmt, arguments);
95 fflush(stderr);
96 va_end(arguments);
97 }
92} 98}
93 99
94/* Set terminal settings to reasonable defaults */ 100/* Set terminal settings to reasonable defaults */
@@ -164,6 +170,7 @@ static void set_free_pages()
164static void console_init() 170static void console_init()
165{ 171{
166 int fd; 172 int fd;
173 struct stat statbuf;
167 int tried_devcons = 0; 174 int tried_devcons = 0;
168 int tried_vtmaster = 0; 175 int tried_vtmaster = 0;
169 char *s; 176 char *s;
@@ -174,6 +181,10 @@ static void console_init()
174 console = CONSOLE; 181 console = CONSOLE;
175 tried_devcons++; 182 tried_devcons++;
176 } 183 }
184
185 if ( stat(CONSOLE, &statbuf) && S_ISLNK(statbuf.st_mode)) {
186 fprintf(stderr, "/dev/console does not exist, or is a symlink.\n");
187 }
177 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) { 188 while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
178 if (!tried_devcons) { 189 if (!tried_devcons) {
179 tried_devcons++; 190 tried_devcons++;
@@ -191,6 +202,7 @@ static void console_init()
191 console = "/dev/null"; 202 console = "/dev/null";
192 else 203 else
193 close(fd); 204 close(fd);
205 fprintf(stderr, "console=%s\n", console);
194} 206}
195 207
196static int waitfor(int pid) 208static int waitfor(int pid)
@@ -205,6 +217,7 @@ static int waitfor(int pid)
205 return wpid; 217 return wpid;
206} 218}
207 219
220
208static int run(const char *command, char *terminal, int get_enter) 221static int run(const char *command, char *terminal, int get_enter)
209{ 222{
210 int f, pid; 223 int f, pid;
@@ -248,13 +261,21 @@ static int run(const char *command, char *terminal, int get_enter)
248 close(2); 261 close(2);
249 setsid(); 262 setsid();
250 263
251 if ((f = device_open(terminal, O_RDWR | O_NOCTTY)) < 0) { 264#if 1
252 message(log, "open(%s) failed: %s\n", terminal, strerror(errno)); 265 //if ((f = device_open(terminal, O_RDWR | O_NOCTTY)) < 0) {
266 if ((f = device_open(terminal, O_RDWR )) < 0) {
267 message(log, "open(%s) failed: %s\n",
268 terminal, strerror(errno));
253 return -1; 269 return -1;
254 } 270 }
255 dup(f); 271 dup(f);
256 dup(f); 272 dup(f);
257 tcsetpgrp(0, getpgrp()); 273#else
274 open(terminal, O_RDWR);
275 dup(0);
276 dup(0);
277 //tcsetpgrp(0, getpgrp());
278#endif
258 set_term(); 279 set_term();
259 280
260 if (get_enter) { 281 if (get_enter) {
@@ -273,11 +294,11 @@ static int run(const char *command, char *terminal, int get_enter)
273 } 294 }
274 295
275 /* Log the process name and args */ 296 /* Log the process name and args */
276 message(console, "Executing "); 297 message(console, "Executing '%s'\r\n", command);
277 message(console, "'%s'\r\n", command); 298 message(log, "Executing '%s'\r\n", command);
278 299
279 /* Now run it. This should take over the PID, so nothing 300 /* Now run it. This program should take over this PID,
280 * further in init.c should be run by this PID. */ 301 * so nothing further in init.c should be run. */
281 execvp(args[1], args + 1); 302 execvp(args[1], args + 1);
282 303
283 message(console, "Hmm. Trying as a script.\r\n"); 304 message(console, "Hmm. Trying as a script.\r\n");
@@ -298,6 +319,7 @@ static int run(const char *command, char *terminal, int get_enter)
298 return pid; 319 return pid;
299} 320}
300 321
322
301#ifndef DEBUG_INIT 323#ifndef DEBUG_INIT
302static void shutdown_system(void) 324static void shutdown_system(void)
303{ 325{
@@ -350,8 +372,8 @@ extern int init_main(int argc, char **argv)
350 int pid1 = 0; 372 int pid1 = 0;
351 int pid2 = 0; 373 int pid2 = 0;
352 struct stat statbuf; 374 struct stat statbuf;
353 const char *init_commands = SHELL "-c exec " INITSCRIPT; 375 const char *init_commands = SHELL " -c exec " INITSCRIPT;
354 const char *shell_commands = SHELL; 376 const char *shell_commands = SHELL " -";
355 const char *tty0_commands = init_commands; 377 const char *tty0_commands = init_commands;
356 const char *tty1_commands = shell_commands; 378 const char *tty1_commands = shell_commands;
357 char *hello_msg_format = 379 char *hello_msg_format =
@@ -397,10 +419,11 @@ extern int init_main(int argc, char **argv)
397 419
398 /* Mount /proc */ 420 /* Mount /proc */
399 if (mount("/proc", "/proc", "proc", 0, 0)) { 421 if (mount("/proc", "/proc", "proc", 0, 0)) {
400 message(log, "Mounting /proc: failed!\n");
401 message(console, "Mounting /proc: failed!\r\n"); 422 message(console, "Mounting /proc: failed!\r\n");
423 message(log, "Mounting /proc: failed!\n");
402 } else { 424 } else {
403 message(console, "Mounting /proc: done.\r\n"); 425 message(console, "Mounting /proc: done.\r\n");
426 message(log, "Mounting /proc: done.\n");
404 } 427 }
405 428
406 /* Make sure there is enough memory to do something useful */ 429 /* Make sure there is enough memory to do something useful */
@@ -430,7 +453,7 @@ extern int init_main(int argc, char **argv)
430 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) { 453 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
431 run_rc = FALSE; 454 run_rc = FALSE;
432 tty0_commands = shell_commands; 455 tty0_commands = shell_commands;
433 tty1_commands = 0; 456 tty1_commands = shell_commands;
434 } 457 }
435 458
436 /* Make sure an init script exists before trying to run it */ 459 /* Make sure an init script exists before trying to run it */
@@ -447,13 +470,13 @@ extern int init_main(int argc, char **argv)
447 int status; 470 int status;
448 471
449 if (pid1 == 0 && tty0_commands) { 472 if (pid1 == 0 && tty0_commands) {
450 pid1 = run(tty0_commands, console, 1); 473 pid1 = run(tty0_commands, first_terminal, 1);
451 } 474 }
452 if (pid2 == 0 && tty1_commands) { 475 if (pid2 == 0 && tty1_commands) {
453 pid2 = run(tty1_commands, second_terminal, 1); 476 pid2 = run(tty1_commands, second_terminal, 1);
454 } 477 }
455 wpid = wait(&status); 478 wpid = wait(&status);
456 if (wpid > 0 && wpid != pid1) { 479 if (wpid > 0 ) {
457 message(log, "pid %d exited, status=%x.\n", wpid, status); 480 message(log, "pid %d exited, status=%x.\n", wpid, status);
458 } 481 }
459 /* Don't respawn an init script if it exits */ 482 /* Don't respawn an init script if it exits */