int main( int argc, char **argv_init, char **envp_init) { int pid,i; /* * This keeps serial console MUCH cleaner, but does assume * the console driver checks there really is a video device * attached (Sparc effectively does). */ if ((open("/dev/tty1",O_RDWR,0) < 0) && (open("/dev/ttyS0",O_RDWR,0) < 0)) printf("Unable to open an initial console.\n"); (void) dup(0); (void) dup(0); execve("/etc/init",argv_init,envp_init); execve("/bin/init",argv_init,envp_init); execve("/sbin/init",argv_init,envp_init); /* if this fails, fall through to original stuff */ if (!(pid=fork())) { do_rc("/etc/rc"); } if (pid>0) while (pid != wait(&i)) /* nothing */; while (1) { if ((pid = fork()) < 0) { printf("Fork failed in mach_init\n\r"); continue; } if (!pid) { do_shell("/bin/sh"); } while (1) if (pid == wait(&i)) break; printf("\n\rchild %d died with code %04x\n\r",pid,i); sync(); } _exit(0); }
int main(int argc, char *argv[]) { int i; struct sigaction sa; /* * setup all the signal handlers here */ memset(&sa, 0, sizeof(sa)); /* sa.sa_flags = SA_RESETHAND we want to keep the handlers armed */ sa.sa_handler = tstp_handler; sigaction(SIGTSTP, &sa, NULL); sa.sa_handler = cont_handler; sigaction(SIGCONT, &sa, NULL); sa.sa_handler = int_handler; sigaction(SIGINT, &sa, NULL); sa.sa_handler = respawn_children; sigaction(SIGALRM, &sa, NULL); sa.sa_handler = hup_handler; sigaction(SIGHUP, &sa, NULL); #if defined(CONSOLE_BAUD_RATE) && LINUX_VERSION_CODE < 0x020100 set_console_baud(CONSOLE_BAUD_RATE); #endif /* * start up in single user mode if /etc/singleboot exists or if * argv[1] is "single". */ if(boot_single(0, argc, argv)) enter_single(); #ifdef CONFIG_RTL865X for(i = 1; i < argc; i++) { if(argv[i] && !strcmp(argv[i], "uart1")) boot_uart1=1;; } #endif #ifdef RUN_RC /* Register console if defined by boot */ #if LINUX_VERSION_CODE < 0x020100 if ((console_device = getenv("CONSOLE"))) { char *sp; unsetenv("CONSOLE"); if ((sp = strchr(console_device, ','))) { *sp++ = 0; set_console_baud(atoi(sp)); } } make_ascii_tty(); #else { struct stat st; if (isatty(1)) { have_console = 1; make_ascii_tty(); } else if (fstat(1, &st) == -1 && errno == EBADF) { close(0); close(1); close(2); open("/dev/null", O_RDWR); dup(0); dup(0); } } #endif /*If we get a SIGTSTP before multi-user mode, do nothing*/ while(stopped) pause(); if(do_rc() != 0 && boot_single(1, argc, argv) && !stopped) enter_single(); while(stopped) /*Also if /etc/rc fails & we get SIGTSTP*/ pause(); #endif write_wtmp(); /* write boottime record */ read_inittab(); #ifdef DEBUGGING for(i = 0; i < numcmd; i++) { char **p; p = inittab[i].toks; printf("toks= %s %s %s %s\n",p[0], p[1], p[2], p[3]); printf("tty= %s\n", inittab[i].tty); printf("termcap= %s\n", inittab[i].termcap); } /*exit(0);*/ #endif #if LINUX_VERSION_CODE < 0x020100 for(i = 0; i < getdtablesize(); i++) close(i); #else i = 0; if (have_console) i = 3; for(; i < getdtablesize(); i++) close(i); #endif for (;;) { pid_t pid; int vec; if (run_sigint_processing) { run_sigint_processing = 0; sigint_processing(); } respawn_children(); if (reload) { reload = 0; reload_inittab(); continue; /* process all reloads before waiting */ } pid = wait(&vec); alarm(0); /* clear utmp entry, and append to wtmp if possible */ #if 0 /* DAVIDM */ { struct utmp *ut; int ut_fd; utmpname(_PATH_UTMP); setutent(); while((ut = getutent())) { if(ut->ut_pid == pid) { time(&ut->ut_time); bzero(&ut->ut_user, UT_NAMESIZE); bzero(&ut->ut_host, sizeof(ut->ut_host)); ut->ut_type = DEAD_PROCESS; ut->ut_pid = 0; ut->ut_addr = 0; endutent(); pututline(ut); if((ut_fd = open(_PATH_WTMP, O_APPEND|O_WRONLY)) >= 0) { flock(ut_fd, LOCK_EX|LOCK_NB); write(ut_fd, (const void *)ut, sizeof(struct utmp)); flock(ut_fd, LOCK_UN|LOCK_NB); close(ut_fd); } break; } } endutent(); } #endif for(i = 0; i < numcmd; i++) { if(pid == inittab[i].pid) { inittab[i].pid = -1; } } } }
void read_rc_file(void) { /** this routine does all the actual work of reading in the .rc file... **/ FILE *file; char buffer[SLEN], filename[SLEN], *cp; /* Establish some defaults in case elmrc is incomplete or not there. * Defaults for other elmrc options were established in their * declaration - in elm.h. And defaults for sent_mail and recvd_mail * are established after the elmrc is read in since these default * are based on the folders directory name, which may be given * in the emrc. * Also establish alternative_editor here since it is based on * the default editor and not on the one that might be given in the * elmrc. */ default_weedlist(); errors = 0; alternative_addresses = NULL; /* none yet! */ raw_local_signature[0] = raw_remote_signature[0] = local_signature[0] = remote_signature[0] = raw_recvdmail[0] = raw_sentmail[0] = allowed_precedences[0] = '\0'; /* no defaults for those */ strncpy(raw_shell, (( (cp = getenv("SHELL")) == NULL)? default_shell : cp ), SLEN); do_expand_env("shell", shell, raw_shell, sizeof(shell)); if (shell[0] != '/') { sprintf(buffer, "/bin/%s", shell); strcpy(shell, buffer); } strncpy(raw_pager, (((cp = getenv("PAGER")) == NULL)? default_pager : cp), SLEN); do_expand_env("pager", pager, raw_pager, sizeof(pager)); strncpy(raw_temp_dir, ((cp = getenv("TMPDIR")) ? cp : default_temp), SLEN); do_expand_env("temp_dir", temp_dir, raw_temp_dir, sizeof(temp_dir)); if (temp_dir[strlen (temp_dir)-1] != '/') strcat(temp_dir, "/"); strncpy(raw_editor, (((cp = getenv("EDITOR")) == NULL)? default_editor:cp), SLEN); strcpy(alternative_editor, raw_editor); do_expand_env("editor", editor, raw_editor, sizeof(editor)); strcpy(raw_printout, default_printout); do_expand_env("printout", printout, raw_printout, sizeof(printout)); sprintf(raw_folders, "~/%s", default_folders); do_expand_env("folders", folders, raw_folders, sizeof(folders)); strcpy(e_editor, emacs_editor); strcpy(v_editor, default_editor); strcpy(raw_printout, default_printout); strcpy(printout, raw_printout); sprintf(raw_folders, "%s/%s", user_home, default_folders); strncpy(folders, raw_folders, SLEN); strcpy(to_chars, default_to_chars); strcpy(charset, default_charset); #ifdef MIME_RECV strcpy(charset_compatlist, COMPAT_CHARSETS); strcpy(display_charset, default_display_charset); #endif /* try system-wide rc file */ if ((file = fopen(system_rc_file, "r")) != NULL) { do_rc(file, SYSTEM_RC); fclose(file); } /* Look for the elmrc file */ /* sprintf(filename, "%s/%s", user_home, elmrcfile); */ getelmrcName(filename,SLEN); if ((file = fopen(filename, "r")) == NULL) { dprint(2, (debugfile, "Warning:User has no \".elm/elmrc\" file\n\n")); } else { do_rc(file, LOCAL_RC); fclose(file); } /* validate/correct config_options string */ if (config_options[0]) { char *s, *t; opts_menu *o; s = shift_lower(config_options); for (t = config_options; *s; ++s) { if (*s == '_' || *s == '^') { *t++ = *s; continue; } o = find_cfg_opts(*s); if (o != NULL) *t++ = *s; /* silently remove invalid options */ } *t = '\0'; } do_expand_env("folders", folders, raw_folders, sizeof(folders)); do_expand_env("temp_dir", temp_dir, raw_temp_dir, sizeof(temp_dir)); if (temp_dir[strlen (temp_dir)-1] != '/') strcat(temp_dir, "/"); do_expand_env("shell", shell, raw_shell, sizeof(shell)); do_expand_env("editor", editor, raw_editor, sizeof(editor)); do_expand_env("calendar_file", calendar_file, raw_calendar_file, sizeof(calendar_file)); do_expand_env("printout", printout, raw_printout, sizeof(printout)); do_expand_env("pager", pager, raw_pager, sizeof(pager)); if (streq(pager, "builtin+") || streq(pager, "internal+")) clear_pages++; do_expand_env("local_signature", local_signature, raw_local_signature, sizeof(local_signature)); do_expand_env("remote_signature", remote_signature, raw_remote_signature, sizeof(remote_signature)); if (streq(local_signature, remote_signature) && (streq(shift_lower(local_signature), "on") || streq(shift_lower(local_signature), "off"))) { errors++; fprintf(stderr, catgets(elm_msg_cat, ElmSet, ElmSignatureObsolete, "\"signature\" used in obsolete way in .elm/elmrc file. Ignored!\n\r\ \t(Signature should specify the filename to use rather than on/off.)\n\r\n")); raw_local_signature[0] = raw_remote_signature[0] = local_signature[0] = remote_signature[0] = '\0'; }