void libinit(char *imod) { struct passwd *pw; Proc *p; void *tos; char sys[64]; setsid(); gethostname(sys, sizeof(sys)); kstrdup(&ossysname, sys); getnobody(); if(dflag == 0) termset(); setsigs(); p = newproc(); p->kstack = stackalloc(p, &tos); pw = getpwuid(getuid()); if(pw != nil) kstrdup(&eve, pw->pw_name); else print("cannot getpwuid\n"); p->env->uid = getuid(); p->env->gid = getgid(); executeonnewstack(tos, emuinit, imod); }
void host_init() { char sys[64]; struct passwd *pw; trace(TRACE_DEBUG, "node9/kernel: becoming host os process leader "); /* init system stack */ setsid(); trace(TRACE_DEBUG, "node9/kernel: collecting system info"); /* setup base system personality and user details */ gethostname(sys, sizeof(sys)); kstrdup(&ossysname, sys); getnobody(); /* initialize signals and eventing system */ /* if not a daemon, initialize the terminal */ if(dflag == 0) { trace(TRACE_INFO, "node9/kernel: initializing terminal"); termset(); } trace(TRACE_DEBUG, "node9/kernel: initializing signals"); setsigs(); trace(TRACE_DEBUG, "node9/kernel: initializing event and req watchers"); setwatchers(); trace(TRACE_DEBUG, "node9/kernel: establishing host username, uid, pid"); pw = getpwuid(getuid()); if(pw != nil) kstrdup(&eve, pw->pw_name); else print("cannot getpwuid\n"); /* and record the current host user uid/gid */ hostuid = getuid(); hostgid = getgid(); }
int main(int argc, char *argv[], char *envp[]) { struct stat histstat; if (modfind(VINUMMOD) < 0) { /* need to load the vinum module */ if (kldload(VINUMMOD) < 0 || modfind(VINUMMOD) < 0) { perror(VINUMMOD ": Kernel module not available"); return 1; } } dateformat = getenv("VINUM_DATEFORMAT"); if (dateformat == NULL) dateformat = "%e %b %Y %H:%M:%S"; historyfile = getenv("VINUM_HISTORY"); if (historyfile == NULL) historyfile = DEFAULT_HISTORYFILE; if (stat(historyfile, &histstat) == 0) { /* history file exists */ if ((histstat.st_mode & S_IFMT) != S_IFREG) { fprintf(stderr, "Vinum history file %s must be a regular file\n", historyfile); exit(1); } } else if ((errno != ENOENT) /* not "not there", */ &&(errno != EROFS)) { /* and not read-only file system */ fprintf(stderr, "Can't open %s: %s (%d)\n", historyfile, strerror(errno), errno); exit(1); } hist = fopen(historyfile, "a+"); if (hist != NULL) { timestamp(); fprintf(hist, "*** " VINUMMOD " started ***\n"); fflush(hist); /* before we start the daemon */ } superdev = open(VINUM_SUPERDEV_NAME, O_RDWR); /* open vinum superdevice */ if (superdev < 0) { /* no go */ if (errno == ENODEV) { /* not configured, */ superdev = open(VINUM_WRONGSUPERDEV_NAME, O_RDWR); /* do we have a debug mismatch? */ if (superdev >= 0) { /* yup! */ #if VINUMDEBUG fprintf(stderr, "This program is compiled with debug support, but the kernel module does\n" "not have debug support. This program must be matched with the kernel\n" "module. Please alter /usr/src/sbin/" VINUMMOD "/Makefile and remove\n" "the option -DVINUMDEBUG from the CFLAGS definition, or alternatively\n" "edit /usr/src/sys/modules/" VINUMMOD "/Makefile and add the option\n" "-DVINUMDEBUG to the CFLAGS definition. Then rebuild the component\n" "of your choice with 'make clean all install'. If you rebuild the kernel\n" "module, you must stop " VINUMMOD " and restart it\n"); #else fprintf(stderr, "This program is compiled without debug support, but the kernel module\n" "includes debug support. This program must be matched with the kernel\n" "module. Please alter /usr/src/sbin/" VINUMMOD "/Makefile and add\n" "the option -DVINUMDEBUG to the CFLAGS definition, or alternatively\n" "edit /usr/src/sys/modules/" VINUMMOD "/Makefile and remove the option\n" "-DVINUMDEBUG from the CFLAGS definition. Then rebuild the component\n" "of your choice with 'make clean all install'. If you rebuild the kernel\n" "module, you must stop " VINUMMOD " and restart it\n"); #endif return 1; } } else if (errno == ENOENT) /* we don't have our node, */ make_devices(); /* create them first */ if (superdev < 0) { perror("Can't open " VINUM_SUPERDEV_NAME); return 1; } } /* Check if the dæmon is running. If not, start it in the * background */ start_daemon(); if (argc > 1) { /* we have a command on the line */ if (setjmp(command_fail) != 0) /* long jumped out */ return -1; parseline(argc - 1, &argv[1]); /* do it */ } else { /* * Catch a possible race condition which could cause us to * longjmp() into nowhere if we receive a SIGINT in the next few * lines. */ if (setjmp(command_fail)) /* come back here on catastrophic failure */ return 1; setsigs(); /* set signal handler */ for (;;) { /* ugh */ char *c; int childstatus; /* from wait4 */ if (setjmp(command_fail) == 2) /* come back here on catastrophic failure */ fprintf(stderr, "*** interrupted ***\n"); /* interrupted */ while (wait4(-1, &childstatus, WNOHANG, NULL) > 0); /* wait for all dead children */ c = readline(VINUMMOD " -> "); /* get an input */ if (c == NULL) { /* EOF or error */ if (ferror(stdin)) { fprintf(stderr, "Can't read input: %s (%d)\n", strerror(errno), errno); return 1; } else { /* EOF */ printf("\n"); return 0; } } else if (*c) { /* got something there */ add_history(c); /* save it in the history */ strcpy(buffer, c); /* put it where we can munge it */ free(c); line++; /* count the lines */ tokens = tokenize(buffer, token); /* got something potentially worth parsing */ if (tokens) parseline(tokens, token); /* and do what he says */ } if (hist) fflush(hist); } } return 0; /* normal completion */ }
/* int main(int argc, char *argv[], char *environ[]) */ int main(int argc, char *argv[]) { char tmpbuf[MAX_OBJNAMELEN + 1]; obj_t *tobj; int i; char *p; char c; short intstatus = 0; short preload = 1; char *fn=NULL; setvbuf(stdout, NULL, _IONBF, 0); if (argc < 2) { do_banner(); do_help(argv[0]); return -1; } if ((N = nsp_newstate()) == NULL) return -1; setsigs(); N->debug = 0; //nspbase_register_all(N); /* add env */ tobj = nsp_settable(N, &N->g, "_ENV"); for (i = 0;environ[i] != NULL;i++) { strncpy(tmpbuf, environ[i], MAX_OBJNAMELEN); p = strchr(tmpbuf, '='); if (!p) continue; *p = '\0'; p = strchr(environ[i], '=') + 1; nsp_setstr(N, tobj, tmpbuf, p, -1); } /* add args */ tobj = nsp_settable(N, &N->g, "_ARGS"); for (i = 0;i < argc;i++) { n_ntoa(N, tmpbuf, i, 10, 0); nsp_setstr(N, tobj, tmpbuf, argv[i], -1); } tobj = nsp_settable(N, &N->g, "io"); nsp_setcfunc(N, tobj, "gets", (NSP_CFUNC)neslib_io_gets); for (i = 1;i < argc;i++) { if (argv[i] == NULL) break; if (argv[i][0] == '-') { c = argv[i][1]; if (!c) { break; } else if ((c == 'd') || (c == 'D')) { N->debug = 1; } else if ((c == 's') || (c == 'S')) { intstatus = 1; } else if ((c == 'b') || (c == 'B')) { preload = 0; } else if ((c == 'e') || (c == 'E')) { if (++i < argc) { if (preload) do_preload(N); nsp_exec(N, argv[i]); if (N->err) goto err; } } else if ((c == 'f') || (c == 'F')) { if (++i < argc) { preppath(N, argv[i]); set_console_title(N); if (preload) do_preload(N); fn=argv[i]; nsp_execfile(N, fn); if (N->err) goto err; } } else if ((c == 'v') || (c == 'V')) { printf(NSP_VERSION "\r\n"); return 0; } else { do_help(argv[0]); return -1; } } else { preppath(N, argv[i]); set_console_title(N); if (preload) do_preload(N); fn=argv[i]; nsp_execfile(N, fn); if (N->err) goto err; } } err: if (N->err) printf("%s\r\n", N->errbuf); nsp_freestate(N); if (intstatus || N->allocs != N->frees) printstate(N, fn); nsp_endstate(N); return 0; }
static void mainloop(struct PCP *pcp) { int c; struct pcpdtimer inactivity_timeout; int my_acl_flags=PCP_ACL_MODIFY|PCP_ACL_CONFLICT| PCP_ACL_LIST|PCP_ACL_RETR; deleted_eventid=NULL; memset(&new_commit, 0, sizeof(new_commit)); new_commit_times=NULL; new_commit_participants=NULL; new_commit_participants_buf=NULL; termsig=0; setsigs(); inp_ptr=0; inp_left=0; need_rset=0; time(&prev_time); pcpdtimer_init(&inactivity_timeout); inactivity_timeout.handler=inactive; if (proxy_userid) { struct get_acl ga; ga.who=proxy_userid; ga.flags=0; if (pcp_has_acl(pcp)) { if (pcp_list_acl(pcp, get_acl_callback, &ga) == 0) { if (ga.flags == 0) { ga.who="public"; if (pcp_list_acl(pcp, get_acl_callback, &ga)) ga.flags=0; } } else ga.flags=0; } my_acl_flags=ga.flags; } do { char *p; input_line_len=0; pcpdtimer_install(&inactivity_timeout, 30 * 60); for (;;) { c=inputchar(pcp); if (termsig || c == '\n') break; input_buffer[input_line_len++]=c; } if (termsig) break; input_buffer[input_line_len]=0; for (p=input_buffer; *p; p++) if (isspace((int)(unsigned char)*p)) *p=' '; pcpdtimer_triggered(&inactivity_timeout); /* Cancel inactivity_timeout for the duration of the command */ } while (doline(pcp, input_buffer, my_acl_flags) == 0 && !termsig); alarm(0); free(input_buffer); rset(pcp); }