int main(int argc, char *argv[], char *envp[]) { nextopt_t nopt = nextopt_INIT(argc, argv, "hV"); char opt; pid_t pid; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(argc < 1){ fatal_usage("missing required program argument"); } if((pid = fork()) == -1){ fatal_syserr("failure to detach"); } if(pid != 0){ /* parent exits: */ _exit(0); } setsid(); /* execvx() provides path search for prog */ execvx(argv[0], argv, envp, NULL); /* uh oh: */ fatal_syserr("unable to run ", argv[0]); /* not reached: */ return 0; }
int main(int argc, char *argv[], char *envp[]) { nextopt_t nopt = nextopt_INIT(argc, argv, "hV"); char opt; const char *prog = NULL; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(argc < 2){ fatal_usage("missing required argument(s)"); } /* our real executable: */ prog = argv[0]; /* ratchet alias into argv[0]: */ ++argv; /* execvx() provides path search for prog */ execvx(prog, argv, envp, NULL); /* uh oh: */ fatal_syserr("unable to run ", prog); /* not reached: */ return 0; }
int main(int argc, char *argv[], char *envp[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVb:ek:p:s:v"); char opt; const char *prog = NULL; uint32_t pid = 0; const char *z; size_t n; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'V': version(); die(0); break; case 'h': usage(); die(0); break; case 'b': arg_base = nopt.opt_arg; break; case 'e': ++opt_e; break; case 'k': arg_key = nopt.opt_arg; break; case 'p': z = nuscan_uint32(&pid, nopt.opt_arg); if(*z != '\0'){ fatal_usage("bad numeric argument for -", optc, ": ", nopt.opt_arg); } break; case 's': arg_set = nopt.opt_arg; break; case 'v': ++opt_v; break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(argc > 0) prog = argv[0]; if(prog == NULL){ fatal_usage("missing required program argument"); } if(arg_base == NULL) arg_base = getenv("CHOOM_BASE"); if(arg_base == NULL) arg_base = CHOOM_BASE_DEFAULT; if(arg_base[0] != '/'){ fatal_usage("path base is not absolute (must begin with `/'): ", arg_base); } if(arg_key == NULL) arg_key = getenv("CHOOM_KEY"); if(arg_key == NULL) arg_key = CHOOM_KEY_DEFAULT; if(arg_set == NULL) arg_set = getenv("CHOOM_SET"); if(arg_set == NULL) arg_set = CHOOM_SET_DEFAULT; nfmt_uint32(pidfmt, (pid == 0) ? (uint32_t)getpid() : pid); n = cstr_vlen(arg_base, "/", pidfmt, "/", arg_key); if((sizeof pathbuf) - n < 5){ errno = ENAMETOOLONG; fatal_syserr("path too long: ", arg_base, "/", pidfmt, "/", arg_key); } cstr_vcopy(pathbuf, arg_base, "/", pidfmt, "/", arg_key); n = cstr_vlen(arg_set, "\n"); if((sizeof setbuf) - n < 1){ fatal_usage("setting too long: ", arg_set); } cstr_vcopy(setbuf, arg_set, "\n"); do_choom(); execvx(prog, argv, envp, NULL); fatal_syserr("unable to run ", prog); /* not reached: */ return 0; }
int main(int argc, char *argv[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVdL:S:x"); char opt; int opt_detach = 0; char *arg_sep = "::"; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case 'd': opt_detach = 1; break; case 'L': /* label string ignored */ break; case 'S': arg_sep = nopt.opt_arg; break; case 'x': opt_super = 0; break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(argc < 3){ fatal_usage("missing required arguments"); } deux_init(); /* proggy: */ deux[1].argv = argv; ++argv; while(argv){ if(cstr_cmp(*argv, arg_sep) == 0){ /* logger argv follows separator: */ deux[0].argv = &argv[1]; /* progger argv terminator: */ *argv = NULL; break; } ++argv; } if(deux[0].argv == NULL){ fatal_usage("missing required logger argument"); } if(opt_detach){ pid_t pid = fork(); switch(pid){ case -1: fatal_syserr("unable to detach"); break; case 0: /* child continues daemonized in new session: */ setsid(); break; default: /* parent exits: */ exit(0); } } /* initialize sigpipe[], etc: */ setup(); main_loop(); return 0; }
int main(int argc, char *argv[], char *envp[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVL:"); char opt; uint32_t secs; const char *z; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case 'L': /* label string ignored */ break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(argc < 2){ fatal_usage("missing required argument(s)"); } z = nuscan_uint32(&secs, argv[0]); if(*z != '\0'){ fatal_usage("bad numeric argument for secs: ", argv[0]); } ++argv; /* catch SIGALRM on pause()/sleep() without termination: */ sig_catch(SIGALRM, sig_trap); if(secs == 0) pause(); else sleep(secs); sig_uncatch(SIGALRM); errno = 0; /* execvx() provides path search for prog */ execvx(argv[0], argv, envp, NULL); /* uh oh: */ fatal_syserr("unable to run ", argv[0]); /* not reached: */ return 0; }
int main(int argc,char *argv[]) { csPrintf("maya2spr version 0.1\n" "A Maya Ascii (.MA) convertor for Crystal Space.\n" "By Keith Fulton\n\n"); if (argc < 6) fatal_usage(); else { int parm = 3; while (parm < argc-1) { parm = proc_arg(argc,argv,parm); if (!parm) fatal_usage(); } } if (!anims.GetSize() ) // no anims means we need to specify a default one { csPrintf("Warning: Only default action being generated!\n"); Animation *anim = new Animation; anim->name = "default"; anim->startframe = 1; DisplacementGroup dg; dg.startframe=0; dg.stopframe =0; dg.vertex=0; anim->displacements.Push(dg); // dummy displacement group anims.Push(anim); } const char* mdlfile = argv[1]; MayaModel* mdl = 0; if (Maya4Model::IsFileMayaModel(mdlfile)) mdl = new Maya4Model(mdlfile); else { csFPrintf(stderr, "Not a recognized Maya 4.0 Ascii model file: %s\n", mdlfile); exit(-1); } if (mdl->getError()) { csFPrintf(stderr, "\nError: %s\n", mdl->getErrorString()); delete mdl; exit(-1); } mdl->dumpstats(stdout); putchar('\n'); mdl->WriteSPR(argv[2],anims); delete mdl; csPrintf("maya2spr completed successfully.\n"); return 0; }
int main(int argc, char *argv[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVdx"); char opt; int opt_detach = 0; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'V': version(); die(0); break; case 'h': usage(); die(0); break; case 'd': opt_detach = 1; break; case 'x': opt_super = 0; break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; perp_base = argv[0]; /* perp_base: default is "/etc/perp": */ if((perp_base == NULL) || (perp_base[0] == '\0')){ perp_base = getenv("PERP_BASE"); } if((perp_base == NULL) || (perp_base[0] == '\0')){ perp_base = PERP_BASE_DEFAULT; } /* initialize sigpipe[], etc: */ setup(); if(opt_detach){ pid_t pid = fork(); switch(pid){ case -1: fatal_syserr("failure fork(): unable to detach"); break; case 0: /* child continues daemonized in new session: */ setsid(); break; default: /* parent exits: */ exit(0); } } if(chdir(perp_base) == -1){ fatal_syserr("failure chdir() to ", perp_base); } if(chdir(PERP_BOOT) == -1){ fatal_syserr("failure chdir() to ", perp_base, "/", PERP_BOOT); } deux_init(); main_loop(); return 0; }
int main(int argc, char *argv[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVb:gLq"); char opt; int opt_g = 0; int opt_L = 0; int flag_sticky = 0; uchar_t cmd[2] = {'\0', '\0'}; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case 'b': basedir = nopt.opt_arg; break; case 'g': ++opt_g; break; case 'L': ++opt_L; break; case 'q': ++opt_q; break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option: -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(!*argv){ eputs(progname, ": usage error: missing arguments"); die_usage(); } /* next argv is the control command (can be taken from first letter): */ switch(cmd[0] = *argv[0]){ case 'A': flag_sticky = +1; break; case 'X': flag_sticky = -1; break; case 'd': case 'u': case 'o': case 'p': case 'c': case 'a': case 'h': case 'i': case 'k': case 'q': case 't': case 'w': case '1': case '2': if(opt_L){ /* control command for log service: */ cmd[1] |= SVCMD_FLAG_LOG; } break; case 'D': case 'U': if(opt_L){ fatal_usage("meta-command '", *argv, "' may not be used with option -L"); } break; default: fatal_usage("unknown control command '", *argv, "'"); break; } --argc; ++argv; if(!*argv){ fatal_usage("missing argument: no service(s) specified"); } if(basedir == NULL) basedir = getenv("PERP_BASE"); if((basedir == NULL) || (basedir[0] == '\0')) basedir = "."; if(chdir(basedir) != 0){ fatal_syserr("unable to chdir() to ", basedir); } /* ** service activation/deactivation command (A or X): */ if(flag_sticky != 0){ do_sticky(flag_sticky, argv); die((errs ? 111 : 0)); } /* ** else: service control command */ /* killpg() flag: */ if(opt_g){ cmd[1] |= SVCMD_FLAG_KILLPG; } do_control(cmd, argv); die((errs ? 111 : 0)); }
int main(int argc, char *argv[]) { nextopt_t nopt = nextopt_INIT(argc, argv, ":hVb:"); char opt; const char *basedir = NULL; char pathbuf[256]; tain_t now; size_t n; int fd_conn; progname = nextopt_progname(&nopt); while((opt = nextopt(&nopt))){ char optc[2] = {nopt.opt_got, '\0'}; switch(opt){ case 'h': usage(); die(0); break; case 'V': version(); die(0); break; case 'b': basedir = nopt.opt_arg; break; case ':': fatal_usage("missing argument for option -", optc); break; case '?': if(nopt.opt_got != '?'){ fatal_usage("invalid option -", optc); } /* else fallthrough: */ default : die_usage(); break; } } argc -= nopt.arg_ndx; argv += nopt.arg_ndx; if(!*argv){ fatal_usage("missing argument"); } if(!basedir) basedir = getenv("PERP_BASE"); if(!basedir) basedir = "."; if(chdir(basedir) != 0){ fatal_syserr("fail chdir() to ", basedir); } /* connect to control socket: */ n = cstr_vlen(basedir, "/", PERP_CONTROL, "/", PERPD_SOCKET); if(!(n < sizeof pathbuf)){ errno = ENAMETOOLONG; fatal_syserr("failure locating perpd control socket ", basedir, "/", PERP_CONTROL, "/", PERPD_SOCKET); } cstr_vcopy(pathbuf, basedir, "/", PERP_CONTROL, "/", PERPD_SOCKET); fd_conn = domsock_connect(pathbuf); if(fd_conn == -1){ if(errno == ECONNREFUSED){ fatal_syserr("perpd not running on control socket ", pathbuf); }else{ fatal_syserr("failure connecting to perpd control socket ", pathbuf); } } /* uptimes compared to now: */ tain_now(&now); /* loop through service directory arguments and display report: */ for(; *argv != NULL; ++argv){ pkt_t pkt = pkt_INIT(2, 'Q', 16); struct stat st; if(stat(*argv, &st) == -1){ eputs(*argv, ": error: service directory not found"); continue; } if(! S_ISDIR(st.st_mode)){ eputs(*argv, ": error: not a directory"); continue; } if(!(S_ISVTX & st.st_mode)){ vputs(*argv, ": not activated\n"); continue; } upak_pack(pkt_data(pkt), "LL", (uint64_t)st.st_dev, (uint64_t)st.st_ino); if(pkt_write(fd_conn, pkt, 0) == -1){ eputs_syserr("error: ", *argv, ": error writing query"); continue; } if(pkt_read(fd_conn, pkt, 0) == -1){ eputs_syserr("error: ", *argv, ": error reading response"); continue; } if(pkt[0] != 2){ eputs("error: ", *argv, ": unknown packet protocol in reply"); continue; } if(pkt[1] != 'S'){ if(pkt[1] == 'E'){ errno = (int)upak32_unpack(&pkt[3]); eputs_syserr("error: ", *argv, ": error reported in reply"); } else { eputs("error: ", *argv, ": unknown packet type in reply"); } continue; } report(*argv, pkt_data(pkt), &now); } vputs_flush(); die(0); }