JNIEXPORT void JNICALL Java_net_hackcasual_freeciv_NativeHarness_startServer (JNIEnv *je, jobject o) { LOGI("Fake server start"); FILE *fp; if((fp=freopen("/data/data/net.hackcasual.freeciv/freeciv_out.log", "w" ,stdout))==NULL) { printf("Cannot open file.\n"); exit(1); } if((fp=freopen("/data/data/net.hackcasual.freeciv/freeciv_err.log", "w" ,stderr))==NULL) { printf("Cannot open file.\n"); exit(1); } setenv ("HOME", "/data/data/net.hackcasual.freeciv/Freeciv", 0); srv_init(); srvarg.log_filename="/data/data/net.hackcasual.freeciv/log.out"; srvarg.loglevel=LOG_DEBUG; init_our_capability(); srv_main(); /* test */ return; }
int main() { srv_t srv; rcli_t cli; rdr_t rdr; eudp_start(); rdr_init(&rdr,"127.0.0.1",65002,514,rcli_collect); rdr_conn(&rdr); rcli_init(&cli,&rdr); srv_init(&srv,"127.0.0.1",60606,&cli); srv_open(&srv); srv_start(&srv); srv_close(&srv); rcli_deinit(&cli); rdr_disconn(&rdr); rdr_deinit(&rdr); eudp_finish(); return 0; }
int main(int argc, char **argv) { setlinebuf(stdout); set_sig_handlers(); srv_init(); option_parse(argc, argv); srv_serve(); srv_destroy(); exit(0); }
int core_run(void) { int s_server = 0, s_listener = 0; bool running = true; struct pollfd fds[MAX_SOCKETS]; store_init(); net_init(); state_init(); if((s_server = srv_init()) < 0) return EXIT_FAILURE; if(srv_connect() == -1){ ERR("srv_connect() failed. Exiting..."); return EXIT_FAILURE; } if((s_listener = clt_init()) == -1){ ERR("clt_init() failed. Exiting..."); return EXIT_FAILURE; } memset(fds, 0 , sizeof(fds)); net_poll_add(s_server, POLLIN); net_poll_add_listener(s_listener, POLLIN); while(running){ net_poll(POLLTIMEOUT); proc_tick(); for(int i = 0; i < net_nfds(); i++){ while(net_socket_avail(i)){ char msg[513] = ""; net_socket_msg(i, msg, sizeof msg); proc_proc(i, msg); } } while(proc_wqueue_length()){ wqueue_entry_t ent = proc_wqueue_head(); net_socket_write(ENT_GET(ent, target), ENT_GET(ent, data), ENT_GET(ent, datasz)); proc_wqueue_next(); } } return EXIT_SUCCESS; }
int main(int argc, char **argv) { int run_srv, run_cli; if (argc < 2) { printf("Not enough arguments provided.\n%s", netcom_usage_string); return -1; } char *host_addr; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0) { printf("NETCOM HELP\n%s%s", netcom_usage_string, netcom_cmd_string); return 0; } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { printf("%s", netcom_ver_string); return 0; } else if (strcmp(argv[i], "-c") == 0) { if (i < argc-1) { host_addr = argv[i+1]; run_cli = 1; } else { printf("Not enough arguments to call -c. You need to enter a destination address.\n"); return -1; } } else if (strcmp(argv[i], "-s") == 0) { run_srv = 1; } } if (run_srv && !run_cli) { srv_init(); } else if (run_srv && run_cli) { pthread_t srv_thread; if (pthread_create(&srv_thread, NULL, &srv_thread_init, &srv_thread) != 0) { printf("Server thread could not be created.\n"); return -1; } } if (run_cli) { if (cli_init(host_addr) != 0) { srv_close(); return -1; } } return 0; }
int main(int argc, char **argv){ create_user_file(); signal(SIGINT, quit); i18n_init(); plugin_init(); #ifndef UI_TEST srv_init(); #endif #ifndef IRC_TEST ui_init(argc, argv); #endif quit(); return 0; }
int main(int argc, char **argv) { int debug = 0, conftest = 0, nodaemon = 0; int i = 0; unsigned int clilen; struct sockaddr_in cliaddr; struct timeval start, end; char *cnfg = DEF_CNFG; char localhost[MAXNAMLEN + 1], path[MAXNAMLEN + 1]; FILE *pidfp; octet_t oct; ruleset_t *rs; /* * Who am I running as ? */ uname(&myname); /* * spocp_err = 0 ; */ memset(&srv, 0, sizeof(srv_t)); pthread_mutex_init(&(srv.mutex), NULL); pthread_mutex_init(&(srv.mlock), NULL); gethostname(localhost, MAXNAMLEN); #ifdef HAVE_GETDOMAINNAME getdomainname(path, MAXNAMLEN); #else { char *pos; if(pos = strstr(localhost, ".")) strncpy(path, pos+1, MAXNAMLEN); else strcpy(path, ""); } #endif if (0) printf("Domain: %s\n", path); srv.hostname = Strdup(localhost); /* * truncating input strings to reasonable length */ for (i = 0; i < argc; i++) if (strlen(argv[i]) > 512) argv[i][512] = '\0'; while ((i = getopt(argc, argv, "Dhrtf:d:")) != EOF) { switch (i) { case 'D': nodaemon = 1; break; case 'f': cnfg = Strdup(optarg); break; case 'd': debug = atoi(optarg); if (debug < 0) debug = 0; break; case 't': conftest = 1; break; case 'r': srv.readonly = 1; case 'h': default: fprintf(stderr, "Usage: %s [-t] ", argv[0]); fprintf(stderr, "[-f configfile] "); fprintf(stderr, "[-D] [-d debuglevel]\n"); exit(0); } } srv.root = ruleset_new(0); if (srv_init(&srv, cnfg) < 0) exit(1); if (srv.port && srv.uds) { fprintf(stderr, "Sorry are not allowed to listen on both a unix domain socket and a port\n"); exit(1); } if (srv.logfile) spocp_open_log(srv.logfile, debug); else if (debug) spocp_open_log(0, debug); if (srv.name){ localcontext = (char *) Calloc(strlen(srv.name) + strlen("//") + 1, sizeof(char)); /* Flawfinder: ignore */ sprintf(localcontext, "//%s", srv.name); } else { localcontext = (char *) Calloc(strlen(localhost) + strlen("//") + 1, sizeof(char)); /* Flawfinder: ignore */ sprintf(localcontext, "//%s", localhost); } /* * where I put the access rules for access to this server and its * rules */ snprintf(path, MAXNAMLEN, "%s/server", localcontext); oct_assign(&oct, path); if ((rs = ruleset_create(&oct, srv.root)) == 0) exit(1); rs->db = db_new(); /* * access rules for operations */ snprintf(path, MAXNAMLEN, "%s/operation", localcontext); oct_assign(&oct, path); if ((rs = ruleset_create(&oct, srv.root)) == 0) exit(1); rs->db = db_new(); LOG(SPOCP_INFO) { traceLog(LOG_INFO, "Local context: \"%s\"", localcontext); traceLog(LOG_INFO, "initializing backends"); if (srv.root->db) plugin_display(srv.plugin); } if (srv.plugin) { run_plugin_init(&srv); } if ( get_rules( &srv ) != SPOCP_SUCCESS ) exit(1); /*ruleset_tree( srv.root, 0);*/ /* If only testing configuration and rulefile this is as far as I go */ if (conftest) { traceLog(LOG_INFO,"Configuration was OK"); exit(0); } gettimeofday(&start, NULL); if (srv.port || srv.uds) { /* * stdin and stdout will not be used from here on, close to * save file descriptors */ fclose(stdin); fclose(stdout); #ifdef HAVE_SSL /* * ---------------------------------------------------------- */ /* * build our SSL context, whether it will ever be used or not */ /* * mutex'es for openSSL to use */ THREAD_setup(); if (srv.certificateFile && srv.privateKey && srv.caList) { traceLog(LOG_INFO,"Initializing the TLS/SSL environment"); if (!(srv.ctx = tls_init(&srv))) { return FALSE; } } /* * ---------------------------------------------------------- */ #endif #ifdef HAVE_SASL { int r = sasl_server_init(sasl_cb, "spocp"); if (r != SASL_OK) { traceLog( LOG_ERR, "Unable to initialized SASL library: %s", sasl_errstring(r, NULL, NULL)); return FALSE; } } #endif saci_init(); if( nodaemon == 0 ) { #ifdef HAVE_DAEMON if (daemon(1, 1) < 0) { fprintf(stderr, "couldn't go daemon\n"); exit(1); } #else daemon_init("spocp", 0); #endif } if (srv.pidfile) { /* * Write the PID file. */ pidfp = fopen(srv.pidfile, "w"); if (pidfp == (FILE *) 0) { fprintf(stderr, "Couldn't open pidfile \"%s\"\n", srv.pidfile); exit(1); } fprintf(pidfp, "%d\n", (int) getpid()); fclose(pidfp); } if (srv.port) { LOG(SPOCP_INFO) traceLog( LOG_INFO, "Asked to listen on port %d", srv.port); if ((srv.listen_fd = spocp_stream_socket(srv.port)) < 0) exit(1); srv.id = (char *) Malloc(16); sprintf(srv.id, "spocp-%d", srv.port); srv.type = AF_INET; } else { LOG(SPOCP_INFO) traceLog(LOG_INFO,"Asked to listen on unix domain socket"); if ((srv.listen_fd = spocp_unix_domain_socket(srv.uds)) < 0) exit(1); srv.id = (char *) Malloc(7 + strlen(srv.uds)); /* Flawfinder: ignore */ sprintf(srv.id, "spocp-%s", srv.uds); srv.type = AF_UNIX; } xsignal(SIGCHLD, sig_chld); xsignal(SIGPIPE, sig_pipe); xsignal(SIGINT, sig_int); xsignal(SIGTERM, sig_term); xsignal(SIGUSR1, sig_usr1); clilen = sizeof(cliaddr); DEBUG(SPOCP_DSRV) traceLog(LOG_DEBUG,"Creating threads"); /* * returns the pool the threads are picking work from */ srv.work = tpool_init(srv.threads, 64, 1); spocp_srv_run(&srv); } else { conn_t *conn; saci_init(); DEBUG(SPOCP_DSRV) traceLog(LOG_DEBUG,"---->"); LOG(SPOCP_INFO) traceLog(LOG_INFO,"Reading STDIN"); /* * If I want to use this I have to do init_server() first * conn = spocp_open_connection( STDIN_FILENO, &srv ) ; */ /* * this is much simpler */ conn = conn_new(); conn_setup(conn, &srv, STDIN_FILENO, "localhost", "127.0.0.1"); LOG(SPOCP_INFO) traceLog(LOG_INFO,"Running server"); spocp_server((void *) conn); gettimeofday(&end, NULL); print_elapsed("query time:", start, end); conn_free( conn ); } srv_free( &srv ); if (cnfg != DEF_CNFG) Free( cnfg ); exit(0); }
static void *srv_thread_init(void *arg) { srv_init(); return NULL; }