int main() { int i = 0; int is_main = 1; int ret; // fork ipc helper for (i = 1; i < IPC_HELPER_NUM; ++i) { pid_t pid = fork(); if (pid == 0) { // child is_main = 0; } else if (pid < 0) { fprintf(stderr, "Failed to fork IPC helper, exiting\n"); return -1; } } if ((ret = init_binder_ipc())) { fprintf(stderr, "Cannot intialize binder IPC channel, ret=%d\n", ret); return 1; } if ((ret = init_glue())) { fprintf(stderr, "Cannot initialize glue, ret=%d\n", ret); return 1; } if ((ret = init_workers())) { fprintf(stderr, "Cannot initialize worker threads, ret=%d\n", ret); return 1; } printf("[%d] Venus ready\n", getpid()); dispatcher_loop(); printf("Venus exited.\n"); return 0; }
int main(int argc, char *argv[]) { int arg; int Fails ; char *str; int level; char *error_file = NULL; extern char *optarg; extern int optind; int opt; error_init(argv[0], application_end); optind = 1; { char domain_path[MAXPATHLEN]; setlocale(LC_ALL, ""); sprintf(domain_path, SEA_LOCALE_PATH); bindtextdomain(DOMAIN_MGET, domain_path); bindtextdomain(DOMAIN_SGET, domain_path); bindtextdomain(DOMAIN_LIBGET, domain_path); bindtextdomain(DOMAIN_LGET, domain_path); bindtextdomain(DOMAIN_FGET, domain_path); /* formatting string */ } /* parse arguments */ while((opt = getopt(argc,argv,"c:i:hr:m:o:p:a:d:yf:n:?"))!=EOF){ switch(opt){ case 'h': case '?': print_usage(); break; case 'f': Fails = strtol (optarg, &str, 10) ; if (optarg == str) { fprintf (stderr, "Invalid number following the -t option: %s\n", optarg ) ; print_usage () ; } else { SetFailThreshold (Fails) ; } break ; case 'y': recovery_on=TRUE; break; case 'p': port = strtol(optarg, &str, 10); if(optarg == str) { fprintf(stderr, "Not a valid integer following the -p option: %s\n", optarg); print_usage(); } break; case 'n': relay_agent_name = strdup(optarg); if(relay_agent_name == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'o': if(optind > argc) { fprintf(stderr, "must have the enterprise name-oid file\n"); print_usage(); } name_oid_file= strdup(optarg); if(name_oid_file == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'c': if(optind > argc) { fprintf(stderr, "Must have a configuration directory name following the -c option\n"); print_usage(); } config_dir = strdup(optarg); if(config_dir == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'a': if(optind > argc) { fprintf(stderr, "Must have a access control filename following the -a option\n"); print_usage(); } sec_config_file = strdup(optarg); if(sec_config_file == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'r': if(optind > argc) { fprintf(stderr, "Must have a resource file name following the -r option\n"); print_usage(); } resource_file = strdup(optarg); if(resource_file == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'i': if(optind > argc) { fprintf(stderr, "Must have a pid file name following the -i option\n"); print_usage(); } pid_file = strdup(optarg); if(pid_file == NULL) { fprintf(stderr, "%s\n", ERR_MSG_ALLOC); exit(1); } break; case 'd': if(optind> argc) { fprintf(stderr, "Must have a trace-level following the -d option\n"); print_usage(); } level = strtol(optarg, &str, 10); if(optarg == str) { fprintf(stderr, "Not a valid integer following the -d option: %s\n", optarg); print_usage(); } if(trace_set(level, error_label)) { print_usage(); } break; case 'm': if(optind > argc) { fprintf(stderr, "Must have GROUP or SPLIT following the -m option\n"); print_usage(); } if(strcmp(optarg, "GROUP") == 0) { mode = MODE_GROUP; } else if(strcmp(optarg, "SPLIT") == 0) { mode = MODE_SPLIT; } else { fprintf(stderr, "Invalid mode: %s\n", optarg); print_usage(); } break; default: fprintf(stderr, "Invalid Option: -%c\n", optarg); print_usage(); break; } } /* if(error_file == NULL) { error_file = default_error_file; } error_open(error_file); */ if(trace_level == 0) { /* run the daemon in backgound */ int pid; pid = fork(); switch(pid) { case -1: error_exit(ERR_MSG_FORK, errno_string()); break; case 0: /* child process */ break; default: /* parent process */ exit(0); break; } } if(fclose(stdin) == EOF) { error(ERR_MSG_FCLOSE, "stdin", errno_string()); } dispatcher_init(); if(signals_init(signals_sighup, signals_exit, error_label)) { error_exit("signals_init() failed: %s", error_label); } if(trace_level == 0) { if(fclose(stdout) == EOF) { error(ERR_MSG_FCLOSE, "stdout", errno_string()); } } if(trace_level == 0) { /* background */ if(chdir("/") == -1) { error(ERR_MSG_CHDIR, "/", errno_string()); } /* set process group ID */ setpgrp(); error_close_stderr(); } dispatcher_loop(); return (0); }