int main(int argc, char *argv[]) { unsigned port = CPORT; /* Actual number of workers & routers */ int nworkers = 1; int nrouters = 1; /* Max number of clients */ int c; int level = 1; bool console = true; while ((c = getopt(argc, argv, "hv:p:r:w:c:C")) != -1) { switch (c) { case 'h': usage(argv[0]); break; case 'v': level = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'r': nrouters = atoi(optarg); break; case 'w': nworkers = atoi(optarg); break; case 'c': maxclients = atoi(optarg); break; case 'C': console = false; break; default: printf("Unknown option '%c'\n", c); usage(argv[0]); break; } } set_verblevel(level); if (signal(SIGTERM, sigterm_handler) == SIG_ERR) err(false, "Couldn't install signal handler"); init_controller(port, nrouters, nworkers); if (!console) block_console(); run_controller(NULL); mem_status(stdout); chunk_status(stdout); return 0; }
int main(int argc, char *argv[]) { arg_data *args = NULL; home_data *data = NULL; pid_t pid = 0; uid_t uid = 0; gid_t gid = 0; int res; /* Parse command line arguments */ args = arguments(argc, argv); if (args == NULL) return 1; /* Stop running jsvc if required */ if (args->stop == true) return (stop_child(args)); /* Let's check if we can switch user/group IDs */ if (checkuser(args->user, &uid, &gid) == false) return 1; /* Retrieve JAVA_HOME layout */ data = home(args->home); if (data == NULL) return 1; /* Check for help */ if (args->help == true) { help(data); return 0; } #ifdef OS_LINUX /* On some UNIX operating systems, we need to REPLACE this current process image with another one (thru execve) to allow the correct loading of VMs (notably this is for Linux). Set, replace, and go. */ if (strcmp(argv[0], args->procname) != 0) { char *oldpath = getenv("LD_LIBRARY_PATH"); char *libf = java_library(args, data); char *filename; char buf[2048]; int ret; char *tmp = NULL; char *p1 = NULL; char *p2 = NULL; /* * There is no need to change LD_LIBRARY_PATH * if we were not able to find a path to libjvm.so * (additionaly a strdup(NULL) cores dump on my machine). */ if (libf != NULL) { p1 = strdup(libf); tmp = strrchr(p1, '/'); if (tmp != NULL) tmp[0] = '\0'; p2 = strdup(p1); tmp = strrchr(p2, '/'); if (tmp != NULL) tmp[0] = '\0'; if (oldpath == NULL) snprintf(buf, 2048, "%s:%s", p1, p2); else snprintf(buf, 2048, "%s:%s:%s", oldpath, p1, p2); tmp = strdup(buf); setenv("LD_LIBRARY_PATH", tmp, 1); log_debug("Invoking w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH")); } /* execve needs a full path */ ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); if (ret <= 0) strcpy(buf, argv[0]); else buf[ret] = '\0'; filename = buf; argv[0] = args->procname; execve(filename, argv, environ); log_error("Cannot execute JSVC executor process (%s)", filename); return 1; } log_debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH")); #endif /* ifdef OS_LINUX */ /* If we have to detach, let's do it now */ if (args->dtch == true) { pid = fork(); if (pid == -1) { log_error("Cannot detach from parent process"); return 1; } /* If we're in the parent process */ if (pid != 0) { if (args->wait >= 10) return wait_child(args, pid); else return 0; } #ifndef NO_SETSID setsid(); #endif } /* * umask() uses inverse logic; bits are CLEAR for allowed access. */ if (~args->umask & 0022) { log_error("NOTICE: jsvc umask of %03o allows " "write permission to group and/or other", args->umask); } envmask = umask(args->umask); set_output(args->outfile, args->errfile, args->redirectstdin, args->procname); log_debug("Switching umask back to %03o from %03o", envmask, args->umask); res = run_controller(args, data, uid, gid); if (logger_pid != 0) { kill(logger_pid, SIGTERM); } return res; }