diff options
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 57 |
1 files changed, 27 insertions, 30 deletions
@@ -106,11 +106,11 @@ struct initActionTag { | |||
106 | initAction* initActionList = NULL; | 106 | initAction* initActionList = NULL; |
107 | 107 | ||
108 | 108 | ||
109 | static char *console = _PATH_CONSOLE; | ||
110 | static char *secondConsole = VT_SECONDARY; | 109 | static char *secondConsole = VT_SECONDARY; |
111 | static char *log = VT_LOG; | 110 | static char *log = VT_LOG; |
112 | static int kernelVersion = 0; | 111 | static int kernelVersion = 0; |
113 | static char *termType = NULL; | 112 | static char termType[32] = "TERM=ansi"; |
113 | static char console[32] = _PATH_CONSOLE; | ||
114 | 114 | ||
115 | 115 | ||
116 | /* try to open up the specified device */ | 116 | /* try to open up the specified device */ |
@@ -258,41 +258,37 @@ static void console_init() | |||
258 | struct serial_struct sr; | 258 | struct serial_struct sr; |
259 | char *s; | 259 | char *s; |
260 | 260 | ||
261 | if ((s = getenv("CONSOLE")) != NULL) { | 261 | if ((s = getenv("TERM")) != NULL) { |
262 | termType = s; | 262 | snprintf(termType,sizeof(termType)-1,"TERM=%s",s); |
263 | } else { | ||
264 | termType = "TERM=vt100"; | ||
265 | } | 263 | } |
266 | 264 | ||
267 | if ((s = getenv("CONSOLE")) != NULL) { | 265 | if ((s = getenv("CONSOLE")) != NULL) { |
268 | console = s; | 266 | snprintf(console, sizeof(console)-1, "%s",s); |
269 | } | 267 | } |
270 | #if #cpu(sparc) | 268 | #if #cpu(sparc) |
271 | /* sparc kernel supports console=tty[ab] parameter which is also | 269 | /* sparc kernel supports console=tty[ab] parameter which is also |
272 | * passed to init, so catch it here */ | 270 | * passed to init, so catch it here */ |
273 | else if ((s = getenv("console")) != NULL) { | 271 | else if ((s = getenv("console")) != NULL) {*/ |
274 | /* remap tty[ab] to /dev/ttyS[01] */ | 272 | /* remap tty[ab] to /dev/ttyS[01] */ |
275 | if (strcmp( s, "ttya" )==0) | 273 | if (strcmp( s, "ttya" )==0) |
276 | console = SERIAL_CON0; | 274 | snprintf(console, sizeof(console)-1, "%s", SERIAL_CON0); |
277 | else if (strcmp( s, "ttyb" )==0) | 275 | else if (strcmp( s, "ttyb" )==0) |
278 | console = SERIAL_CON1; | 276 | snprintf(console, sizeof(console)-1, "%s", SERIAL_CON1); |
279 | } | 277 | } |
280 | #endif | 278 | #endif |
281 | else { | 279 | else { |
282 | struct vt_stat vt; | 280 | struct vt_stat vt; |
283 | static char the_console[13]; | ||
284 | 281 | ||
285 | console = the_console; | ||
286 | /* 2.2 kernels: identify the real console backend and try to use it */ | 282 | /* 2.2 kernels: identify the real console backend and try to use it */ |
287 | if (ioctl(0, TIOCGSERIAL, &sr) == 0) { | 283 | if (ioctl(0, TIOCGSERIAL, &sr) == 0) { |
288 | /* this is a serial console */ | 284 | /* this is a serial console */ |
289 | snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line ); | 285 | snprintf(console, sizeof(console)-1, "/dev/ttyS%d", sr.line); |
290 | } | 286 | } |
291 | else if (ioctl(0, VT_GETSTATE, &vt) == 0) { | 287 | else if (ioctl(0, VT_GETSTATE, &vt) == 0) { |
292 | /* this is linux virtual tty */ | 288 | /* this is linux virtual tty */ |
293 | snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active ); | 289 | snprintf(console, sizeof(console)-1, "/dev/tty%d", vt.v_active); |
294 | } else { | 290 | } else { |
295 | console = _PATH_CONSOLE; | 291 | snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE); |
296 | tried_devcons++; | 292 | tried_devcons++; |
297 | } | 293 | } |
298 | } | 294 | } |
@@ -301,25 +297,25 @@ static void console_init() | |||
301 | /* Can't open selected console -- try /dev/console */ | 297 | /* Can't open selected console -- try /dev/console */ |
302 | if (!tried_devcons) { | 298 | if (!tried_devcons) { |
303 | tried_devcons++; | 299 | tried_devcons++; |
304 | console = _PATH_CONSOLE; | 300 | snprintf(console, sizeof(console)-1, "%s", _PATH_CONSOLE); |
305 | continue; | 301 | continue; |
306 | } | 302 | } |
307 | /* Can't open selected console -- try vt1 */ | 303 | /* Can't open selected console -- try vt1 */ |
308 | if (!tried_vtprimary) { | 304 | if (!tried_vtprimary) { |
309 | tried_vtprimary++; | 305 | tried_vtprimary++; |
310 | console = VT_PRIMARY; | 306 | snprintf(console, sizeof(console)-1, "%s", VT_PRIMARY); |
311 | continue; | 307 | continue; |
312 | } | 308 | } |
313 | break; | 309 | break; |
314 | } | 310 | } |
315 | if (fd < 0) | 311 | if (fd < 0) { |
316 | /* Perhaps we should panic here? */ | 312 | /* Perhaps we should panic here? */ |
317 | console = "/dev/null"; | 313 | snprintf(console, sizeof(console)-1, "/dev/null"); |
318 | else { | 314 | } else { |
319 | /* check for serial console and disable logging to tty3 & running a | 315 | /* check for serial console and disable logging to tty3 & running a |
320 | * shell to tty2 */ | 316 | * shell to tty2 */ |
321 | if (ioctl(0,TIOCGSERIAL,&sr) == 0) { | 317 | if (ioctl(0,TIOCGSERIAL,&sr) == 0) { |
322 | message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n", console ); | 318 | message(LOG|CONSOLE, "serial console detected. Disabling virtual terminals.\r\n" ); |
323 | log = NULL; | 319 | log = NULL; |
324 | secondConsole = NULL; | 320 | secondConsole = NULL; |
325 | } | 321 | } |
@@ -337,15 +333,14 @@ static pid_t run(char* command, | |||
337 | char* cmd[255]; | 333 | char* cmd[255]; |
338 | static const char press_enter[] = | 334 | static const char press_enter[] = |
339 | "\nPlease press Enter to activate this console. "; | 335 | "\nPlease press Enter to activate this console. "; |
340 | static char * environment[] = { | 336 | char* environment[] = { |
341 | "HOME=/", | 337 | "HOME=/", |
342 | "PATH=/usr/bin:/bin:/usr/sbin:/sbin", | 338 | "PATH=/usr/bin:/bin:/usr/sbin:/sbin", |
343 | "SHELL=/bin/sh", | 339 | "SHELL=/bin/sh", |
344 | 0, | 340 | termType, |
345 | "USER=root", | 341 | "USER=root", |
346 | 0 | 342 | 0 |
347 | }; | 343 | }; |
348 | environment[3]=termType; | ||
349 | 344 | ||
350 | 345 | ||
351 | if ((pid = fork()) == 0) { | 346 | if ((pid = fork()) == 0) { |
@@ -389,24 +384,23 @@ static pid_t run(char* command, | |||
389 | } | 384 | } |
390 | 385 | ||
391 | /* Log the process name and args */ | 386 | /* Log the process name and args */ |
392 | message(LOG|CONSOLE, "Starting pid %d, console %s: '", | 387 | message(LOG, "Starting pid %d, console %s: '", |
393 | shell_pgid, terminal, command); | 388 | shell_pgid, terminal, command); |
394 | 389 | ||
395 | /* Convert command (char*) into cmd (char**, one word per string) */ | 390 | /* Convert command (char*) into cmd (char**, one word per string) */ |
396 | for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { | 391 | for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { |
397 | if (*tmpCmd != '\0') { | 392 | if (*tmpCmd != '\0') { |
398 | cmd[i] = tmpCmd; | 393 | cmd[i] = tmpCmd; |
399 | message(LOG|CONSOLE, "%s ", tmpCmd); | 394 | message(LOG, "%s ", tmpCmd); |
400 | tmpCmd++; | 395 | tmpCmd++; |
401 | i++; | 396 | i++; |
402 | } | 397 | } |
403 | } | 398 | } |
404 | cmd[i] = NULL; | 399 | cmd[i] = NULL; |
405 | message(LOG|CONSOLE, "'\r\n"); | 400 | message(LOG, "'\r\n"); |
406 | 401 | ||
407 | /* Now run it. The new program will take over this PID, | 402 | /* Now run it. The new program will take over this PID, |
408 | * so nothing further in init.c should be run. */ | 403 | * so nothing further in init.c should be run. */ |
409 | //execvp(cmd[0], cmd); | ||
410 | execve(cmd[0], cmd, environment); | 404 | execve(cmd[0], cmd, environment); |
411 | 405 | ||
412 | /* We're still here? Some error happened. */ | 406 | /* We're still here? Some error happened. */ |
@@ -541,8 +535,8 @@ void new_initAction (initActionEnum action, | |||
541 | } else | 535 | } else |
542 | strncpy(newAction->console, console, 255); | 536 | strncpy(newAction->console, console, 255); |
543 | newAction->pid = 0; | 537 | newAction->pid = 0; |
544 | message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", | 538 | // message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", |
545 | newAction->process, newAction->action, newAction->console); | 539 | // newAction->process, newAction->action, newAction->console); |
546 | } | 540 | } |
547 | 541 | ||
548 | void delete_initAction (initAction *action) | 542 | void delete_initAction (initAction *action) |
@@ -673,6 +667,9 @@ extern int init_main(int argc, char **argv) | |||
673 | usage( "init\n\nInit is the parent of all processes.\n\n" | 667 | usage( "init\n\nInit is the parent of all processes.\n\n" |
674 | "This version of init is designed to be run only by the kernel\n"); | 668 | "This version of init is designed to be run only by the kernel\n"); |
675 | } | 669 | } |
670 | /* Fix up argv[0] to be certain we claim to be init */ | ||
671 | strncpy(argv[0], "init", strlen(argv[0])); | ||
672 | |||
676 | /* Set up sig handlers -- be sure to | 673 | /* Set up sig handlers -- be sure to |
677 | * clear all of these in run() */ | 674 | * clear all of these in run() */ |
678 | signal(SIGUSR1, halt_signal); | 675 | signal(SIGUSR1, halt_signal); |