/** * @brief main function * * It is just a switch by which you chose to run server or client. * * @todo check ip address and port validity */ int main(int argc, char *argv[]) { char *ip_addr; unsigned short port; if (argc < 4) { fprintf(stderr, "usage: %s <server/client> <ip_addr> <port>\n", argv[0]); exit(1); } /* TODO: check ip address and port validity */ ip_addr = argv[2]; port = strtol(argv[3], NULL, 10); if (strcmp(argv[1], "server") == 0 || strcmp(argv[1], "s") == 0) { if (server_main(ip_addr, port) < 0) { fprintf(stderr, "start server_main failed\n"); exit(1); } } else if (strcmp(argv[1], "client") == 0 || strcmp(argv[1], "c") == 0) { if (client_main(ip_addr, port) < 0) { fprintf(stderr, "start server_main failed\n"); exit(1); } } else { fprintf(stderr, "usage: %s <server/client> <ip_addr> <port>\n", argv[0]); exit(1); } return 0; }
int main(int argc, const char *argv[]) { sigset_t oset, set; pid_t pid; int retval, status; const char *sockpath; if (argc < 2) return (1); sockpath = argv[1]; if (sigfillset(&set) == -1) return (2); if (sigprocmask(SIG_BLOCK, &set, &oset) == -1) return (3); pid = fork(); if (pid == -1) return (4); if (pid == 0) return (client_main(sockpath)); retval = server_main(sockpath, pid); if (wait4(pid, &status, 0, NULL) == -1) return (5); if (!WIFEXITED(status)) return (6); if (WEXITSTATUS(status) != 0) return (64 + WEXITSTATUS(status)); return (retval == 0 ? 0 : 32 + retval); }
static int main_client(char *home, char *dev, char *alias, int daemon) { int ret, udp; char *host, *port; check_config_exists_or_die(home); check_config_keypair_or_die(home); parse_userfile_and_generate_serv_store_or_die(home); get_serv_store_entry_by_alias(alias, alias ? strlen(alias) + 1 : 0, &host, &port, &udp); if (!host || !port || udp < 0) panic("Did not find alias/entry in configuration!\n"); printf("Using [%s] -> %s:%s via %s as endpoint!\n", alias ? : "default", host, port, udp ? "udp" : "tcp"); if (daemon) daemonize(NULL); ret = client_main(home, dev, host, port, udp); destroy_serv_store(); return ret; }
// do the actual work void version_main(void) { IO_put_string( FILE_TAG "\n" "; ToACME: Converted by ToACME, release " RELEASE_NUMBER ".\n" ); client_main(); }
int main(int argc, char **argv) { char * progName = NULL; SECStatus secStatus; PLOptState *optstate; PLOptStatus status; /* Call the NSPR initialization routines */ PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); progName = PL_strdup(argv[0]); hostName = NULL; optstate = PL_CreateOptState(argc, argv, "d:h:i:o:p:t:"); while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) { switch(optstate->option) { case 'd' : certDir = PL_strdup(optstate->value); break; case 'h' : hostName = PL_strdup(optstate->value); break; case 'i' : infileName = PL_strdup(optstate->value); break; case 'o' : outfileName = PL_strdup(optstate->value); break; case 'p' : port = PORT_Atoi(optstate->value); break; case 't' : trustNewServer_p = PL_strdup(optstate->value); break; case '?' : default : Usage(progName); } } if (port == 0 || hostName == NULL || infileName == NULL || outfileName == NULL || certDir == NULL) Usage(progName); #if 0 /* no client authentication */ /* Set our password function callback. */ PK11_SetPasswordFunc(myPasswd); #endif /* Initialize the NSS libraries. */ secStatus = NSS_InitReadWrite(certDir); if (secStatus != SECSuccess) { /* Try it again, readonly. */ secStatus = NSS_Init(certDir); if (secStatus != SECSuccess) exitErr("Error initializing NSS", GENERAL_ERROR); } /* All cipher suites except RSA_NULL_MD5 are enabled by Domestic Policy. */ NSS_SetDomesticPolicy(); client_main(port); NSS_Shutdown(); PR_Cleanup(); return 0; }
int main(int argc, char *argv[]){ commandline_t mode = { 0 , 0 } ; config_t config; //コンフィグ読み込み構造体 config_load(&config); error_message( mode_check( argv, &mode , argc) ); if ( mode.server != 0 ){ error_message(server_main()); //サーバーモードへ } else if ( mode.client != 0 ){ error_message(client_main(&config)); //クライアントモードへ } return 0; }
int main(int argc, CARGV argv) { multi_argv = argv; multi_argc = argc; if (!compare(basename((char*)*argv), "vlmcsd")) return server_main(argc, argv); if (!compare(basename((char*)*argv), "vlmcs")) return client_main(argc, argv); #ifdef _WIN32 if (!compare(basename((char*)*argv), "vlmcsd.exe")) return server_main(argc, argv); if (!compare(basename((char*)*argv), "vlmcs.exe")) return client_main(argc, argv); #endif // _WIN32 if (argc > 1) { if (!strcmp((char*)argv[1],"vlmcsd")) return server_main(argc - 1, argv + 1); if (!strcmp((char*)argv[1],"vlmcs")) return client_main(argc - 1, argv + 1); } errorout( "vlmcsdmulti %s\n\n" "Usage:\n" "\t%s vlmcsd [<vlmcsd command line>]\n" "\t%s vlmcs [<vlmcs command line>]\n\n", Version, *argv, *argv ); return !0; }
void *client_thread(void *arg) { CLI *c = arg; #ifdef DEBUG_STACK_SIZE stack_info(1); #endif client_main(c); #ifdef DEBUG_STACK_SIZE stack_info(0); #endif str_stats(); str_cleanup(); return NULL; }
int main(int ac, char **av) { if (ac != 2) { fprintf(stderr, "Usage: %s -s OR %s [-]serverhost\n", av[0], av[0]); exit(1); } if (!strcmp(av[1], "-s")) { if (fork() == 0) { server_main(ac, av); } exit(0); } else { client_main(ac, av); } return(0); }
static int main_unix(int argc, char* argv[]) { #if !defined(__vms) && !defined(USE_OS2) int fd; fd=open("/dev/null", O_RDWR); /* open /dev/null before chroot */ if(fd<0) fatal("Could not open /dev/null"); #endif /* standard Unix */ main_initialize(); if(main_configure(argc>1 ? argv[1] : NULL, argc>2 ? argv[2] : NULL)) return 1; if(service_options.next) { /* there are service sections -> daemon mode */ #if !defined(__vms) && !defined(USE_OS2) if(daemonize(fd)) return 1; close(fd); /* create_pid() must be called after drop_privileges() * or it won't be possible to remove the file on exit */ /* create_pid() must be called after daemonize() * since the final pid is not known beforehand */ if(create_pid()) return 1; #endif /* standard Unix */ signal(SIGCHLD, signal_handler); /* handle dead children */ signal(SIGHUP, signal_handler); /* configuration reload */ signal(SIGUSR1, signal_handler); /* log reopen */ signal(SIGPIPE, SIG_IGN); /* ignore broken pipe */ if(signal(SIGTERM, SIG_IGN)!=SIG_IGN) signal(SIGTERM, signal_handler); /* fatal */ if(signal(SIGQUIT, SIG_IGN)!=SIG_IGN) signal(SIGQUIT, signal_handler); /* fatal */ if(signal(SIGINT, SIG_IGN)!=SIG_IGN) signal(SIGINT, signal_handler); /* fatal */ daemon_loop(); } else { /* inetd mode */ #if !defined(__vms) && !defined(USE_OS2) close(fd); #endif /* standard Unix */ signal(SIGCHLD, SIG_IGN); /* ignore dead children */ signal(SIGPIPE, SIG_IGN); /* ignore broken pipe */ client_main(alloc_client_session(&service_options, 0, 1)); } return 0; }
// WinMain関数 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { ifstream ifs("../config/default.conf"); int tmp; ifs >> PORT; ifs >> tmp; SERVER_IP.d1 = tmp; ifs >> tmp; SERVER_IP.d2 = tmp; ifs >> tmp; SERVER_IP.d3 = tmp; ifs >> tmp; SERVER_IP.d4 = tmp; ifs >> CLIENT_NUM; // 画面モードの設定 ChangeWindowMode(true); SetGraphMode( WINDOW_WIDTH, WINDOW_HEIGHT, 16 ) ; // DXライブラリ初期化処理 if( DxLib_Init() == -1 ) return -1; // グラフィックの描画先を裏画面にセット SetDrawScreen( DX_SCREEN_BACK ); SetMainWindowText( "Bullet of the Chaos"); #ifdef SOLOPLAY_MODE soloplay_main(); #endif // SOLOPLAY_MODE #ifdef NETWORK_SOLOPLAY_MODE network_soloplay_main(); #endif // NETWORK_SOLOPLAY_MODE #ifdef SERVER_MODE server_main(); #endif // SERVER_MODE #ifdef CLIENT_MODE client_main(); #endif // CLIENT_MODE DxLib_End(); // DXライブラリ使用の終了処理 return 0; // ソフトの終了 }
int main_option_client(t_global *global, t_xtree *tree) { char *hostname; global->scene = NULL; my_putstr("[*] Raytracer: Creation of the window ..."); if ((global->window = obj_create_window(global, tree)) == NULL) return (my_puterror(" \033[31mFail !\033[0m\n")); my_putstr(" \033[32mDone !\033[00m\n"); my_putstr("[*] Raytracer: Creation of the scene ..."); if ((global->scene = obj_create_scene \ (tree, global->window->mlx_ptr)) == NULL) return (my_puterror(" \033[31mFail !\033[0m\n")); my_putstr(" \033[32mDone !\033[00m\n"); hostname = ((t_client_info *)global->info.arg)->hostname; init_box(global->scene->object); if ((client_main(hostname, global->info.port)) == EXIT_FAILURE) return (EXIT_FAILURE); return (EXIT_SUCCESS); }
void *client_thread(void *arg) { CLI *c=arg; #ifdef DEBUG_STACK_SIZE stack_info(1); /* initialize */ #endif client_main(c); #ifdef DEBUG_STACK_SIZE stack_info(0); /* display computed value */ #endif str_stats(); str_cleanup(); /* s_log() is not allowed after str_cleanup() */ #if defined(USE_WIN32) && !defined(_WIN32_WCE) _endthread(); #endif #ifdef USE_UCONTEXT s_poll_wait(NULL, 0, 0); /* wait on poll() */ #endif return NULL; }
int main(int argc, const char *argv[]) { sigset_t set; pid_t pid, ppid; int n, status; const char *sockpath; if (argc < 2) return (1); sockpath = argv[1]; if (sigfillset(&set) == -1) return (2); if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) return (3); ppid = getpid(); pid = fork(); switch (pid) { case -1: return (4); case 0: return (server_main(ppid, sockpath)); default: break; } n = client_main(pid, sockpath); if (wait4(pid, &status, 0, NULL) == -1) return (5); if (!WIFEXITED(status)) return (6); if (WEXITSTATUS(status) != 0) return (64 + WEXITSTATUS(status)); return (n + (n == 0 ? 0 : 32)); }
int main(int argc, char **argv) { int i; pid_t pid; gen_srvs_names(); for (i = 0; i < clients; i++) { pid = fork(); if (!pid) { id = i; client_main(srvs[i],iterations,id); exit(0); } else if (pid < 0) { fprintf(stderr, "server fork error\n"); return -1; } } signal(SIGCHLD, children_reaper); server_main(service,'B'); return 0; }
int main(int argc, char **argv) { struct passwd *pw; char *s, *path, *label, *home, **var; int opt, flags, quiet, keys; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; #endif flags = IDENTIFY_256COLOURS | IDENTIFY_UTF8; quiet = 0; label = path = NULL; login_shell = (**argv == '-'); while ((opt = getopt(argc, argv, "28c:Cdf:lL:qS:uUvV")) != -1) { switch (opt) { case '2': flags |= IDENTIFY_256COLOURS; flags &= ~IDENTIFY_88COLOURS; break; case '8': flags |= IDENTIFY_88COLOURS; flags &= ~IDENTIFY_256COLOURS; break; case 'c': free(shell_cmd); shell_cmd = xstrdup(optarg); break; case 'C': if (flags & IDENTIFY_CONTROL) flags |= IDENTIFY_TERMIOS; else flags |= IDENTIFY_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); exit(0); case 'f': free(cfg_file); cfg_file = xstrdup(optarg); break; case 'l': login_shell = 1; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': quiet = 1; break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= IDENTIFY_UTF8; break; case 'v': debug_level++; break; default: usage(); } } argc -= optind; argv += optind; if (shell_cmd != NULL && argc != 0) usage(); if (!(flags & IDENTIFY_UTF8)) { /* * If the user has set whichever of LC_ALL, LC_CTYPE or LANG * exist (in that order) to contain UTF-8, it is a safe * assumption that either they are using a UTF-8 terminal, or * if not they know that output from UTF-8-capable programs may * be wrong. */ if ((s = getenv("LC_ALL")) == NULL || *s == '\0') { if ((s = getenv("LC_CTYPE")) == NULL || *s == '\0') s = getenv("LANG"); } if (s != NULL && (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL)) flags |= IDENTIFY_UTF8; } environ_init(&global_environ); for (var = environ; *var != NULL; var++) environ_put(&global_environ, *var); options_init(&global_options, NULL); options_table_populate_tree(server_options_table, &global_options); options_set_number(&global_options, "quiet", quiet); options_init(&global_s_options, NULL); options_table_populate_tree(session_options_table, &global_s_options); options_set_string(&global_s_options, "default-shell", "%s", getshell()); options_init(&global_w_options, NULL); options_table_populate_tree(window_options_table, &global_w_options); /* Enable UTF-8 if the first client is on UTF-8 terminal. */ if (flags & IDENTIFY_UTF8) { options_set_number(&global_s_options, "status-utf8", 1); options_set_number(&global_s_options, "mouse-utf8", 1); options_set_number(&global_w_options, "utf8", 1); } /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(&global_s_options, "status-keys", keys); options_set_number(&global_w_options, "mode-keys", keys); } /* Locate the configuration file. */ if (cfg_file == NULL) { home = getenv("HOME"); if (home == NULL || *home == '\0') { pw = getpwuid(getuid()); if (pw != NULL) home = pw->pw_dir; } xasprintf(&cfg_file, "%s/%s", home, DEFAULT_CFG); if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { free(cfg_file); cfg_file = NULL; } } /* * Figure out the socket path. If specified on the command-line with -S * or -L, use it, otherwise try $TMUX or assume -L default. */ parseenvironment(); if (path == NULL) { /* If no -L, use the environment. */ if (label == NULL) { if (environ_path != NULL) path = xstrdup(environ_path); } /* -L or default set. */ if (!path) { if ((path = makesocketpath(label)) == NULL) { fprintf(stderr, "can't create socket\n"); exit(1); } } } free(label); strlcpy(socket_path, path, sizeof socket_path); free(path); #ifdef HAVE_SETPROCTITLE /* Set process title. */ setproctitle("%s (%s)", __progname, socket_path); #endif /* Pass control to the client. */ ev_base = osdep_event_init(); exit(client_main(argc, argv, flags)); }
int main(int argc, char **argv) { char *path, *label, **var, tmp[PATH_MAX], *shellcmd = NULL; const char *s; int opt, flags, keys; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; #endif setlocale(LC_TIME, ""); tzset(); if (**argv == '-') flags = CLIENT_LOGIN; else flags = 0; #ifdef TMATE tmate_catch_sigsegv(); flags |= CLIENT_256COLOURS | CLIENT_UTF8; #endif label = path = NULL; while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; break; case 'c': free(shellcmd); shellcmd = xstrdup(optarg); break; case 'C': if (flags & CLIENT_CONTROL) flags |= CLIENT_CONTROLCONTROL; else flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); exit(0); case 'f': set_cfg_file(optarg); break; case 'l': flags |= CLIENT_LOGIN; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= CLIENT_UTF8; break; case 'v': log_add_level(); break; default: usage(); } } argc -= optind; argv += optind; if (shellcmd != NULL && argc != 0) usage(); #ifdef __OpenBSD__ if (pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd " "recvfd proc exec tty ps", NULL) != 0) err(1, "pledge"); #endif /* * tmux is a UTF-8 terminal, so if TMUX is set, assume UTF-8. * Otherwise, if the user has set LC_ALL, LC_CTYPE or LANG to contain * UTF-8, it is a safe assumption that either they are using a UTF-8 * terminal, or if not they know that output from UTF-8-capable * programs may be wrong. */ if (getenv("TMUX") != NULL) flags |= CLIENT_UTF8; else { s = getenv("LC_ALL"); if (s == NULL || *s == '\0') s = getenv("LC_CTYPE"); if (s == NULL || *s == '\0') s = getenv("LANG"); if (s == NULL || *s == '\0') s = ""; if (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL) flags |= CLIENT_UTF8; } global_hooks = hooks_create(NULL); global_environ = environ_create(); for (var = environ; *var != NULL; var++) environ_put(global_environ, *var); if (getcwd(tmp, sizeof tmp) != NULL) environ_set(global_environ, "PWD", "%s", tmp); global_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_SERVER, global_options); global_s_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_SESSION, global_s_options); options_set_string(global_s_options, "default-shell", "%s", getshell()); global_w_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_WINDOW, global_w_options); /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(global_s_options, "status-keys", keys); options_set_number(global_w_options, "mode-keys", keys); } /* * If socket is specified on the command-line with -S or -L, it is * used. Otherwise, $TMUX is checked and if that fails "default" is * used. */ if (path == NULL && label == NULL) { s = getenv("TMUX"); if (s != NULL && *s != '\0' && *s != ',') { path = xstrdup(s); path[strcspn (path, ",")] = '\0'; } } if (path == NULL && (path = make_label(label)) == NULL) { fprintf(stderr, "can't create socket: %s\n", strerror(errno)); exit(1); } socket_path = path; free(label); /* Pass control to the client. */ exit(client_main(event_init(), argc, argv, flags, shellcmd)); }
int main( int argc, char * argv[]) { int rc; char * filename = NULL; char * contact = NULL; globus_bool_t server = GLOBUS_FALSE; char gets_buffer[1024]; while ((rc = getopt(argc, argv, "hf:cst:b:v:i:")) != EOF) { switch (rc) { case 'h': usage(argv[0]); exit(0); case 'f': filename = optarg; break; case 'c': server = GLOBUS_FALSE; contact = fgets(gets_buffer, sizeof(gets_buffer), stdin); break; case 's': server = GLOBUS_TRUE; contact = NULL; break; case 't': if ((strcmp(optarg, CHUNKED) == 0) || (strcmp(optarg, IDENTITY) == 0)) { transfer_encoding = optarg; } else { usage(argv[0]); exit(1); } break; case 'b': buffer_size = atoi(optarg); if (buffer_size < 0) { usage(argv[0]); exit(1); } break; case 'v': if (strcmp(optarg, HTTP_1_0) == 0) { version = GLOBUS_XIO_HTTP_VERSION_1_0; } else if (strcmp(optarg, HTTP_1_1) == 0) { version = GLOBUS_XIO_HTTP_VERSION_1_1; } else { usage(argv[0]); exit(1); } break; case 'i': iterations = atoi(optarg); if (iterations <= 0) { usage(argv[0]); exit(1); } break; default: usage(argv[0]); exit(1); } } if (((!server) && (contact == NULL)) || (filename == NULL)) { usage(argv[0]); exit(1); } if (iterations > 1 && version == GLOBUS_XIO_HTTP_VERSION_1_0) { fprintf(stderr, "Can't have multiple iterations with HTTP/1.0 server\n"); usage(argv[0]); exit(1); } rc = http_test_initialize(&tcp_driver, &http_driver, &stack); if (rc != 0) { goto error_exit; } if (server) { rc = server_main( filename); } else { rc = client_main( filename, contact, version); } globus_xio_stack_destroy(stack); globus_xio_driver_unload(http_driver); globus_xio_driver_unload(tcp_driver); globus_module_deactivate_all(); error_exit: return rc; }
int main( int argc, char *argv[] ) { sigset_t newmask; char c; extern char *optarg; extern int optind, opterr, optopt; char *cfgfile = HTUN_DEFAULT_CFGFILE; char *tunfile = NULL; char *logfile = NULL; unsigned short port=0; int foreground = 0; int dont_route = 0; int config_test_only = 0; int debug = 0; unsigned int logflags = 0; dropprivs(""); while( (c=getopt(argc, argv, "rdfc:vht:l:p:o")) != -1 ) { switch(c) { case 'r': dont_route = 1; break; /* #ifdef _DEBUG */ case 'd': debug = 1; break; /* #endif */ case 'o': debug = 1; config_test_only = 1; break; case 'f': foreground = 1; break; case 'c': cfgfile = optarg; break; case 'v': fprintf( stderr, "HTun " VERSION "\n" "(c) 2002 Moshe Jacobson <*****@*****.**>\n" " and Ola Nordstrom <*****@*****.**>\n" "This program is distributed under the GNU General Public License.\n" "for details, see the LICENSE file packaged with htun.\n"); return EXIT_SUCCESS; case 't': tunfile = optarg; break; case 'l': logfile = optarg; break; case 'p': port = htons((unsigned short)strtoul(optarg,NULL,0)); if(!port) { fprintf( stderr, "Invalid port specified: %s.\n", argv[optind] ); return EXIT_FAILURE; } break; case 'h': usage(); return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } /* Read the config */ if( (config=read_config(cfgfile)) == NULL ) { fprintf( stderr, "Fatal: Reading cfgfile \"%s\": %s\n", cfgfile, strerror(errno) ); return EXIT_FAILURE; } if( config_test_only == 1 ) { log = log_open("-", LOG_STDERR|LOG_NODATE|LOG_DEBUG|LOG_NOLVL|LOG_FUNC); print_config(config); log_close(log); return EXIT_SUCCESS; } /* Now override config values with cmdline values */ strcpy(config->cfgfile,cfgfile); if( tunfile ) strncpy(config->tunfile,tunfile,PATH_MAX); if( logfile ) strncpy(config->logfile,logfile,PATH_MAX); if( port ) { if( config->is_server ) config->u.s.server_ports[0] = htons(port); else config->u.c.proxy_port = (port); } if( dont_route ) config->u.c.do_routing = 0; if( debug ) config->debug = 1; /* Open the log file */ if( config->debug ) logflags |= LOG_DEBUG; logflags |= LOG_FUNC; getprivs("opening logfile"); if( !(log=log_open( config->logfile, logflags )) ) { fprintf( stderr, "Warning: Could not open logfile %s: %s\n", config->logfile, strerror(errno) ); } dropprivs("logfile opened"); /* Daemonize unless -f or -l - have been specified */ if( !foreground && strcmp(config->logfile,"-") ) daemonize(); lprintf( log, INFO, "HTun " VERSION " started." ); init_signames(); /* Ignore SIGPIPE. We will use errno=EPIPE instead. */ signal(SIGPIPE,SIG_IGN); signal(SIGWINCH,SIG_IGN); /* Mask TERM, HUP, INT, and USR1 */ sigemptyset(&newmask); sigaddset(&newmask, SIGINT); sigaddset(&newmask, SIGHUP); sigaddset(&newmask, SIGTERM); sigaddset(&newmask, SIGUSR1); sigaddset(&newmask, SIGUSR2); sigaddset(&newmask, SIGALRM); sigaddset(&newmask, SIGCONT); sigaddset(&newmask, SIGTSTP); sigaddset(&newmask, SIGWINCH); sigprocmask( SIG_BLOCK, &newmask, NULL ); return config->is_server ? server_main() : client_main(); }
/* * A new game process is needed. * Create the communication pipes, register them with epoll and fork the new * process. */ static int fork_client(struct client_data *client, int epfd) { int ret1, ret2, userid; int pipe_out_fd[2]; int pipe_in_fd[2]; struct epoll_event ev; ret1 = pipe2(pipe_out_fd, O_NONBLOCK); ret2 = pipe2(pipe_in_fd, O_NONBLOCK); if (ret1 == -1 || ret2 == -1) { if (!ret1) { close(pipe_out_fd[0]); close(pipe_out_fd[1]); } /* it's safe to use errno here, even though the second pipe2 call will erase the status from the first, because the second one will always fail with the same status as the first if the first call fails. */ log_msg("Failed to create communication pipes for new connection: %s", strerror(errno)); cleanup_game_process(client, epfd); return FALSE; } /* pipe[0] read side - pipe[1] write side */ fcntl(pipe_in_fd[0], F_SETFD, FD_CLOEXEC); fcntl(pipe_out_fd[1], F_SETFD, FD_CLOEXEC); /* client does not need to inherit this */ client->pipe_out = pipe_out_fd[1]; client->pipe_in = pipe_in_fd[0]; map_fd_to_client(client->pipe_out, client); map_fd_to_client(client->pipe_in, client); client->pid = fork(); if (client->pid > 0) { /* parent */ } else if (client->pid == 0) { /* child */ struct user_info info; userid = client->userid; db_get_user_info(userid, &info); setenv("NH4SERVERUSER", info.username, 1); post_fork_cleanup(); client_main(userid, pipe_out_fd[0], pipe_in_fd[1]); exit(0); /* shouldn't get here... client is done. */ } else if (client->pid == -1) { /* error */ /* can't proceed, so clean up. The client side of the pipes needs to be closed here, this end gets handled in cleanup_game_process */ close(pipe_out_fd[0]); close(pipe_in_fd[1]); cleanup_game_process(client, epfd); log_msg("Failed to fork a client process: %s", strerror(errno)); return FALSE; } client->state = CLIENT_CONNECTED; unlink_client_data(client); link_client_data(client, &connected_list_head); /* register the pipe fds for monitoring by epoll */ ev.data.ptr = NULL; ev.events = EPOLLIN | EPOLLRDHUP | EPOLLET; ev.data.fd = client->pipe_out; epoll_ctl(epfd, EPOLL_CTL_ADD, client->pipe_out, &ev); ev.data.fd = client->pipe_in; epoll_ctl(epfd, EPOLL_CTL_ADD, client->pipe_in, &ev); /* close the client side of the pipes */ close(pipe_out_fd[0]); close(pipe_in_fd[1]); return TRUE; }
NOEXPORT int main_unix(int argc, char* argv[]) { int configure_status; #if !defined(__vms) && !defined(USE_OS2) int fd; fd=open("/dev/null", O_RDWR); /* open /dev/null before chroot */ if(fd==INVALID_SOCKET) fatal("Could not open /dev/null"); #endif #ifdef WOLFSSL_DEBUG_ON wolfSSL_Debugging_ON(); wolfSSL_SetLoggingCb((wolfSSL_Logging_cb)&wolfSSL_s_log); #endif main_init(); configure_status=main_configure(argc>1 ? argv[1] : NULL, argc>2 ? argv[2] : NULL); switch(configure_status) { case 1: /* error -> exit with 1 to indicate error */ close(fd); return 1; case 2: /* information printed -> exit with 0 to indicate success */ close(fd); return 0; } if(service_options.next) { /* there are service sections -> daemon mode */ #if !defined(__vms) && !defined(USE_OS2) if(daemonize(fd)) { close(fd); return 1; } close(fd); /* create_pid() must be called after drop_privileges() * or it won't be possible to remove the file on exit */ /* create_pid() must be called after daemonize() * since the final pid is not known beforehand */ if(create_pid()) return 1; #endif #ifndef USE_OS2 signal(SIGCHLD, signal_handler); /* handle dead children */ signal(SIGHUP, signal_handler); /* configuration reload */ signal(SIGUSR1, signal_handler); /* log reopen */ signal(SIGPIPE, SIG_IGN); /* ignore broken pipe */ if(signal(SIGTERM, SIG_IGN)!=SIG_IGN) signal(SIGTERM, signal_handler); /* fatal */ if(signal(SIGQUIT, SIG_IGN)!=SIG_IGN) signal(SIGQUIT, signal_handler); /* fatal */ if(signal(SIGINT, SIG_IGN)!=SIG_IGN) signal(SIGINT, signal_handler); /* fatal */ #endif daemon_loop(); } else { /* inetd mode */ #if !defined(__vms) && !defined(USE_OS2) close(fd); #endif /* standard Unix */ #ifndef USE_OS2 signal(SIGCHLD, SIG_IGN); /* ignore dead children */ signal(SIGPIPE, SIG_IGN); /* ignore broken pipe */ #endif set_nonblock(0, 1); /* stdin */ set_nonblock(1, 1); /* stdout */ client_main(alloc_client_session(&service_options, 0, 1)); } return 0; }
int main(int argc, char **argv) { char *s, *path, *label, **var, tmp[PATH_MAX]; int opt, flags, keys; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; #endif setlocale(LC_TIME, ""); if (**argv == '-') flags = CLIENT_LOGIN; else flags = 0; label = path = NULL; while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; break; case 'c': free(shell_cmd); shell_cmd = xstrdup(optarg); break; case 'C': if (flags & CLIENT_CONTROL) flags |= CLIENT_CONTROLCONTROL; else flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); exit(0); case 'f': set_cfg_file(optarg); break; case 'l': flags |= CLIENT_LOGIN; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= CLIENT_UTF8; break; case 'v': debug_level++; break; default: usage(); } } argc -= optind; argv += optind; if (shell_cmd != NULL && argc != 0) usage(); if (!(flags & CLIENT_UTF8)) { /* * If the user has set whichever of LC_ALL, LC_CTYPE or LANG * exist (in that order) to contain UTF-8, it is a safe * assumption that either they are using a UTF-8 terminal, or * if not they know that output from UTF-8-capable programs may * be wrong. */ if ((s = getenv("LC_ALL")) == NULL || *s == '\0') { if ((s = getenv("LC_CTYPE")) == NULL || *s == '\0') s = getenv("LANG"); } if (s != NULL && (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL)) flags |= CLIENT_UTF8; } environ_init(&global_environ); for (var = environ; *var != NULL; var++) environ_put(&global_environ, *var); if (getcwd(tmp, sizeof tmp) != NULL) environ_set(&global_environ, "PWD", tmp); options_init(&global_options, NULL); options_table_populate_tree(server_options_table, &global_options); options_init(&global_s_options, NULL); options_table_populate_tree(session_options_table, &global_s_options); options_set_string(&global_s_options, "default-shell", "%s", getshell()); options_init(&global_w_options, NULL); options_table_populate_tree(window_options_table, &global_w_options); /* Enable UTF-8 if the first client is on UTF-8 terminal. */ if (flags & CLIENT_UTF8) { options_set_number(&global_s_options, "status-utf8", 1); options_set_number(&global_s_options, "mouse-utf8", 1); options_set_number(&global_w_options, "utf8", 1); } /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(&global_s_options, "status-keys", keys); options_set_number(&global_w_options, "mode-keys", keys); } /* * Figure out the socket path. If specified on the command-line with -S * or -L, use it, otherwise try $TMUX or assume -L default. */ if (path == NULL) { /* If no -L, use the environment. */ if (label == NULL) { s = getenv("TMUX"); if (s != NULL) { path = xstrdup(s); path[strcspn (path, ",")] = '\0'; if (*path == '\0') { free(path); label = xstrdup("default"); } } else label = xstrdup("default"); } /* -L or default set. */ if (label != NULL) { if ((path = makesocketpath(label)) == NULL) { fprintf(stderr, "can't create socket: %s\n", strerror(errno)); exit(1); } } } free(label); if (strlcpy(socket_path, path, sizeof socket_path) >= sizeof socket_path) { fprintf(stderr, "socket path too long: %s\n", path); exit(1); } free(path); #ifdef HAVE_SETPROCTITLE /* Set process title. */ setproctitle("%s (%s)", __progname, socket_path); #endif /* Pass control to the client. */ exit(client_main(event_init(), argc, argv, flags)); }
int main(int argc, char **argv) { if(client_main(service,iterations,id)!=0) fprintf(stderr,"%s exit with error\n",argv[0]); return 0; }
int main(int argc, char* argv[]) { int sockfd, numbytes; char buf[MAXDATASIZE]; struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; // Command line argument guard. if (argc != 2) { fprintf(stderr, "usage: client hostname\n"); exit(1); } // Preparing the IP address lookup struct. memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; // Get the IP address info. if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for (p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("ERROR: socket"); continue; } // connect() to use recv() if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("ERROR: connect"); continue; } break; } // Failed to connect to a listener. if (p == NULL) { fprintf(stderr, "ERROR: listener: failed to bind socket\n"); fprintf(stdout, "ERROR: Cannot connect to server\n"); return 2; } // Converts the IP address to a string. inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof(s)); // Now the IP address is in <s> // Print the IP address. printf("client connecting to %s\n", s); freeaddrinfo(servinfo); // all done with this structure /****************************************************************************** ******************************************************************************* ******************************************************************************/ /* ** client_main() is responsible for the main behavior of the program. */ int client_main_return = -1; if (client_main_return = client_main(sockfd, buf, MAXDATASIZE) != 0) { fprintf( stderr, "ERROR(%d): Abnormal termination of communication with server\n", client_main_return ); } else { fprintf( stdout, "OK: Terminated connection normally\n" ); } /****************************************************************************** ******************************************************************************* ******************************************************************************/ close(sockfd); return 0; }
int main(int argc, char **argv) { char * certDir = NULL; char * progName = NULL; int connections = 1; char * cipherString = NULL; char * respUrl = NULL; char * respCertName = NULL; SECStatus secStatus; PLOptState * optstate; PLOptStatus status; PRBool doOcspCheck = PR_FALSE; /* Call the NSPR initialization routines */ PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); progName = PORT_Strdup(argv[0]); hostName = NULL; optstate = PL_CreateOptState(argc, argv, "C:cd:f:l:n:p:ot:w:"); while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) { switch(optstate->option) { case 'C' : cipherString = PL_strdup(optstate->value); break; case 'c' : dumpChain = PR_TRUE; break; case 'd' : certDir = PL_strdup(optstate->value); break; case 'l' : respUrl = PL_strdup(optstate->value); break; case 'p' : port = PORT_Atoi(optstate->value); break; case 'o' : doOcspCheck = PR_TRUE; break; case 't' : respCertName = PL_strdup(optstate->value); break; case 'w': pwdata.source = PW_PLAINTEXT; pwdata.data = PORT_Strdup(optstate->value); break; case 'f': pwdata.source = PW_FROMFILE; pwdata.data = PORT_Strdup(optstate->value); break; case '\0': hostName = PL_strdup(optstate->value); break; default : Usage(progName); } } if (port == 0) { port = 443; } if (port == 0 || hostName == NULL) Usage(progName); if (doOcspCheck && ((respCertName != NULL && respUrl == NULL) || (respUrl != NULL && respCertName == NULL))) { SECU_PrintError (progName, "options -l <url> and -t " "<responder> must be used together"); Usage(progName); } PK11_SetPasswordFunc(SECU_GetModulePassword); /* Initialize the NSS libraries. */ if (certDir) { secStatus = NSS_Init(certDir); } else { secStatus = NSS_NoDB_Init(NULL); /* load the builtins */ SECMOD_AddNewModule("Builtins", DLL_PREFIX"nssckbi."DLL_SUFFIX, 0, 0); } if (secStatus != SECSuccess) { exitErr("NSS_Init"); } SECU_RegisterDynamicOids(); if (doOcspCheck == PR_TRUE) { SECStatus rv; CERTCertDBHandle *handle = CERT_GetDefaultCertDB(); if (handle == NULL) { SECU_PrintError (progName, "problem getting certdb handle"); goto cleanup; } rv = CERT_EnableOCSPChecking (handle); if (rv != SECSuccess) { SECU_PrintError (progName, "error enabling OCSP checking"); goto cleanup; } if (respUrl != NULL) { rv = CERT_SetOCSPDefaultResponder (handle, respUrl, respCertName); if (rv != SECSuccess) { SECU_PrintError (progName, "error setting default responder"); goto cleanup; } rv = CERT_EnableOCSPDefaultResponder (handle); if (rv != SECSuccess) { SECU_PrintError (progName, "error enabling default responder"); goto cleanup; } } } /* All cipher suites except RSA_NULL_MD5 are enabled by * Domestic Policy. */ NSS_SetDomesticPolicy(); SSL_CipherPrefSetDefault(SSL_RSA_WITH_NULL_MD5, PR_TRUE); /* all the SSL2 and SSL3 cipher suites are enabled by default. */ if (cipherString) { int ndx; /* disable all the ciphers, then enable the ones we want. */ disableAllSSLCiphers(); while (0 != (ndx = *cipherString++)) { int cipher; if (ndx == ':') { int ctmp; cipher = 0; HEXCHAR_TO_INT(*cipherString, ctmp) cipher |= (ctmp << 12); cipherString++; HEXCHAR_TO_INT(*cipherString, ctmp) cipher |= (ctmp << 8); cipherString++; HEXCHAR_TO_INT(*cipherString, ctmp) cipher |= (ctmp << 4); cipherString++; HEXCHAR_TO_INT(*cipherString, ctmp) cipher |= ctmp; cipherString++; } else { const int *cptr; if (! isalpha(ndx)) Usage(progName); cptr = islower(ndx) ? ssl3CipherSuites : ssl2CipherSuites; for (ndx &= 0x1f; (cipher = *cptr++) != 0 && --ndx > 0; ) /* do nothing */; } if (cipher > 0) { SSL_CipherPrefSetDefault(cipher, PR_TRUE); } else { Usage(progName); } } } client_main(port, connections, hostName); cleanup: if (doOcspCheck) { CERTCertDBHandle *handle = CERT_GetDefaultCertDB(); CERT_DisableOCSPDefaultResponder(handle); CERT_DisableOCSPChecking (handle); } if (NSS_Shutdown() != SECSuccess) { exit(1); } PR_Cleanup(); PORT_Free(progName); return 0; }
/************************************************************************** Entry point for whole freeciv client program. **************************************************************************/ int main(int argc, char **argv) { setup_gui_funcs(); return client_main(argc, argv); }
int main(int argc, char **argv) { struct client_ctx cctx; struct msg_command_data cmddata; struct buffer *b; struct cmd_list *cmdlist; struct cmd *cmd; struct pollfd pfd; struct hdr hdr; const char *shell; struct passwd *pw; char *path, *label, *cause, *home, *pass = NULL; char cwd[MAXPATHLEN]; int retcode, opt, flags, unlock, start_server; unlock = flags = 0; label = path = NULL; while ((opt = getopt(argc, argv, "28df:L:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= IDENTIFY_256COLOURS; flags &= ~IDENTIFY_88COLOURS; break; case '8': flags |= IDENTIFY_88COLOURS; flags &= ~IDENTIFY_256COLOURS; break; case 'f': cfg_file = xstrdup(optarg); break; case 'L': if (path != NULL) { log_warnx("-L and -S cannot be used together"); exit(1); } if (label != NULL) xfree(label); label = xstrdup(optarg); break; case 'S': if (label != NULL) { log_warnx("-L and -S cannot be used together"); exit(1); } if (path != NULL) xfree(path); path = xstrdup(optarg); break; case 'q': be_quiet = 1; break; case 'u': flags |= IDENTIFY_UTF8; break; case 'U': unlock = 1; break; case 'd': flags |= IDENTIFY_HASDEFAULTS; break; case 'v': debug_level++; break; case 'V': printf("%s " BUILD "\n", __progname); exit(0); default: usage(); } } argc -= optind; argv += optind; log_open_tty(debug_level); siginit(); options_init(&global_options, NULL); options_set_number(&global_options, "bell-action", BELL_ANY); options_set_number(&global_options, "buffer-limit", 9); options_set_number(&global_options, "display-time", 750); options_set_number(&global_options, "history-limit", 2000); options_set_number(&global_options, "message-bg", 3); options_set_number(&global_options, "message-fg", 0); options_set_number(&global_options, "message-attr", GRID_ATTR_REVERSE); options_set_number(&global_options, "prefix", META); options_set_number(&global_options, "repeat-time", 500); options_set_number(&global_options, "set-titles", 1); options_set_number(&global_options, "lock-after-time", 0); options_set_number(&global_options, "set-remain-on-exit", 0); options_set_number(&global_options, "status", 1); options_set_number(&global_options, "status-bg", 2); options_set_number(&global_options, "status-fg", 0); options_set_number(&global_options, "status-attr", GRID_ATTR_REVERSE); options_set_number(&global_options, "status-interval", 15); options_set_number(&global_options, "status-left-length", 10); options_set_number(&global_options, "status-right-length", 40); options_set_string(&global_options, "status-left", "[#S]"); options_set_string( &global_options, "status-right", "\"#24T\" %%H:%%M %%d-%%b-%%y"); options_set_number(&global_options, "status-keys", MODEKEY_EMACS); options_init(&global_window_options, NULL); options_set_number(&global_window_options, "aggressive-resize", 0); options_set_number(&global_window_options, "clock-mode-colour", 4); options_set_number(&global_window_options, "clock-mode-style", 1); options_set_number(&global_window_options, "force-height", 0); options_set_number(&global_window_options, "force-width", 0); options_set_number(&global_window_options, "automatic-rename", 1); options_set_number(&global_window_options, "mode-bg", 3); options_set_number(&global_window_options, "mode-fg", 0); options_set_number( &global_window_options, "mode-attr", GRID_ATTR_REVERSE); options_set_number(&global_window_options, "mode-keys", MODEKEY_EMACS); options_set_number(&global_window_options, "monitor-activity", 0); options_set_number(&global_window_options, "utf8", 0); options_set_number(&global_window_options, "xterm-keys", 0); options_set_number(&global_window_options, "remain-on-exit", 0); options_set_number(&global_window_options, "window-status-bg", 8); options_set_number(&global_window_options, "window-status-fg", 8); options_set_number(&global_window_options, "window-status-attr", 0); if (cfg_file == NULL) { home = getenv("HOME"); if (home == NULL || *home == '\0') { pw = getpwuid(getuid()); if (pw != NULL) home = pw->pw_dir; endpwent(); } xasprintf(&cfg_file, "%s/%s", home, DEFAULT_CFG); if (access(cfg_file, R_OK) != 0) { xfree(cfg_file); cfg_file = NULL; } } else { if (access(cfg_file, R_OK) != 0) { log_warn("%s", cfg_file); exit(1); } } if (label == NULL) label = xstrdup("default"); if (path == NULL && (path = makesockpath(label)) == NULL) { log_warn("can't create socket"); exit(1); } xfree(label); shell = getenv("SHELL"); if (shell == NULL || *shell == '\0') { pw = getpwuid(getuid()); if (pw != NULL) shell = pw->pw_shell; endpwent(); if (shell == NULL || *shell == '\0') shell = _PATH_BSHELL; } options_set_string( &global_options, "default-command", "exec %s", shell); if (getcwd(cwd, sizeof cwd) == NULL) { log_warn("getcwd"); exit(1); } options_set_string(&global_options, "default-path", "%s", cwd); if (unlock) { if (argc != 0) { log_warnx("can't specify a command when unlocking"); exit(1); } cmdlist = NULL; if ((pass = getpass("Password: "******"%s", cause); exit(1); } } start_server = 0; TAILQ_FOREACH(cmd, cmdlist, qentry) { if (cmd->entry->flags & CMD_STARTSERVER) { start_server = 1; break; } } } memset(&cctx, 0, sizeof cctx); if (client_init(path, &cctx, start_server, flags) != 0) exit(1); xfree(path); b = buffer_create(BUFSIZ); if (unlock) { cmd_send_string(b, pass); client_write_server( &cctx, MSG_UNLOCK, BUFFER_OUT(b), BUFFER_USED(b)); } else { cmd_list_send(cmdlist, b); cmd_list_free(cmdlist); client_fill_session(&cmddata); client_write_server2(&cctx, MSG_COMMAND, &cmddata, sizeof cmddata, BUFFER_OUT(b), BUFFER_USED(b)); } buffer_destroy(b); retcode = 0; for (;;) { pfd.fd = cctx.srv_fd; pfd.events = POLLIN; if (BUFFER_USED(cctx.srv_out) > 0) pfd.events |= POLLOUT; if (poll(&pfd, 1, INFTIM) == -1) { if (errno == EAGAIN || errno == EINTR) continue; fatal("poll failed"); } if (buffer_poll(&pfd, cctx.srv_in, cctx.srv_out) != 0) goto out; restart: if (BUFFER_USED(cctx.srv_in) < sizeof hdr) continue; memcpy(&hdr, BUFFER_OUT(cctx.srv_in), sizeof hdr); if (BUFFER_USED(cctx.srv_in) < (sizeof hdr) + hdr.size) continue; buffer_remove(cctx.srv_in, sizeof hdr); switch (hdr.type) { case MSG_EXIT: case MSG_SHUTDOWN: goto out; case MSG_ERROR: retcode = 1; /* FALLTHROUGH */ case MSG_PRINT: if (hdr.size > INT_MAX - 1) fatalx("bad MSG_PRINT size"); log_info("%.*s", (int) hdr.size, BUFFER_OUT(cctx.srv_in)); if (hdr.size != 0) buffer_remove(cctx.srv_in, hdr.size); goto restart; case MSG_READY: retcode = client_main(&cctx); goto out; default: fatalx("unexpected command"); } } out: options_free(&global_options); options_free(&global_window_options); close(cctx.srv_fd); buffer_destroy(cctx.srv_in); buffer_destroy(cctx.srv_out); #ifdef DEBUG xmalloc_report(getpid(), "client"); #endif return (retcode); }
int main(int argc, char **argv) { int i, c; pid_t pid; while ((c = getopt(argc, argv, "hKSc:n:o:t:s:")) != -1) { switch (c) { case 'K': inst_kernel = 0; break; case 'S': share_cpus = 0; break; case 's': data_SZ = atoi(optarg); if(data_SZ < 32 ) data_SZ = 32; break; case 'c': clients = atoi(optarg); if (clients < 1) clients = 1; break; case 'n': iterations = atoi(optarg); if (iterations < 1) iterations = 1; break; case 'o': output_file = strdup(optarg); break; case 't': time_ref = atoi(optarg); if (time_ref < 0 || time_ref > 2) time_ref = 1; break; default: fprintf(stderr, "Usage: binder_test [-hKS] [-c <clients>]\n" " [-n <iterations>]\n" " [-o <output file>]\n" " [-t <0: absolute | 1: relative-to-first | 2: relative-to-previous]\n"); exit(1); } } for (i = 0; i < clients; i++) { pid = fork(); if (!pid) { id = i; client_main(); exit(0); } else if (pid < 0) { fprintf(stderr, "server fork error\n"); return -1; } } signal(SIGCHLD, children_reaper); server_main(); return 0; }
/************************************************************************** Entry point for whole freeciv client program. **************************************************************************/ int main(int argc, char **argv) { return client_main(argc, argv); }
int main(int argc, char **argv) { char *path, *label, tmp[PATH_MAX]; char *shellcmd = NULL, **var; const char *s, *shell; int opt, flags, keys; const struct options_table_entry *oe; if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) { if (setlocale(LC_CTYPE, "") == NULL) errx(1, "invalid LC_ALL, LC_CTYPE or LANG"); s = nl_langinfo(CODESET); if (strcasecmp(s, "UTF-8") != 0 && strcasecmp(s, "UTF8") != 0) errx(1, "need UTF-8 locale (LC_CTYPE) but have %s", s); } setlocale(LC_TIME, ""); tzset(); if (**argv == '-') flags = CLIENT_LOGIN; else flags = 0; label = path = NULL; while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; break; case 'c': free(shellcmd); shellcmd = xstrdup(optarg); break; case 'C': if (flags & CLIENT_CONTROL) flags |= CLIENT_CONTROLCONTROL; else flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", getprogname(), VERSION); exit(0); case 'f': set_cfg_file(optarg); break; case 'l': flags |= CLIENT_LOGIN; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= CLIENT_UTF8; break; case 'v': log_add_level(); break; default: usage(); } } argc -= optind; argv += optind; if (shellcmd != NULL && argc != 0) usage(); if ((ptm_fd = getptmfd()) == -1) err(1, "getptmfd"); if (pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd " "recvfd proc exec tty ps", NULL) != 0) err(1, "pledge"); /* * tmux is a UTF-8 terminal, so if TMUX is set, assume UTF-8. * Otherwise, if the user has set LC_ALL, LC_CTYPE or LANG to contain * UTF-8, it is a safe assumption that either they are using a UTF-8 * terminal, or if not they know that output from UTF-8-capable * programs may be wrong. */ if (getenv("TMUX") != NULL) flags |= CLIENT_UTF8; else { s = getenv("LC_ALL"); if (s == NULL || *s == '\0') s = getenv("LC_CTYPE"); if (s == NULL || *s == '\0') s = getenv("LANG"); if (s == NULL || *s == '\0') s = ""; if (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL) flags |= CLIENT_UTF8; } global_hooks = hooks_create(NULL); global_environ = environ_create(); for (var = environ; *var != NULL; var++) environ_put(global_environ, *var); if (getcwd(tmp, sizeof tmp) != NULL) environ_set(global_environ, "PWD", "%s", tmp); global_options = options_create(NULL); global_s_options = options_create(NULL); global_w_options = options_create(NULL); for (oe = options_table; oe->name != NULL; oe++) { if (oe->scope == OPTIONS_TABLE_SERVER) options_default(global_options, oe); if (oe->scope == OPTIONS_TABLE_SESSION) options_default(global_s_options, oe); if (oe->scope == OPTIONS_TABLE_WINDOW) options_default(global_w_options, oe); } /* * The default shell comes from SHELL or from the user's passwd entry * if available. */ shell = getshell(); options_set_string(global_s_options, "default-shell", 0, "%s", shell); /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(global_s_options, "status-keys", keys); options_set_number(global_w_options, "mode-keys", keys); } /* * If socket is specified on the command-line with -S or -L, it is * used. Otherwise, $TMUX is checked and if that fails "default" is * used. */ if (path == NULL && label == NULL) { s = getenv("TMUX"); if (s != NULL && *s != '\0' && *s != ',') { path = xstrdup(s); path[strcspn(path, ",")] = '\0'; } } if (path == NULL && (path = make_label(label)) == NULL) { fprintf(stderr, "can't create socket: %s\n", strerror(errno)); exit(1); } socket_path = path; free(label); /* Pass control to the client. */ exit(client_main(osdep_event_init(), argc, argv, flags, shellcmd)); }