/* this is the heart of the beast */ void server_process (void) { INFO1 ("%s server started", ICECAST_VERSION_STRING); global.running = ICE_RUNNING; /* Do this after logging init */ auth_initialise (); if (background) { fclose (stdin); fclose (stdout); fclose (stderr); } slave_initialize(); INFO0("Shutting down"); auth_shutdown(); }
int main(int argc, char **argv) { int res, ret; char filename[512]; char pbuf[1024]; kitsune_do_automigrate(); /**DSU data */ if (!kitsune_is_updating()) { /**DSU control */ /* parse the '-c icecast.xml' option ** only, so that we can read a configfile */ res = _parse_config_opts(argc, argv, filename, 512); if (res == 1) { /* startup all the modules */ _initialize_subsystems(); /* parse the config file */ config_get_config(); ret = config_initial_parse_file(filename); config_release_config(); if (ret < 0) { memset(pbuf, '\000', sizeof(pbuf)); snprintf(pbuf, sizeof(pbuf)-1, "FATAL: error parsing config file (%s)", filename); _fatal_error(pbuf); switch (ret) { case CONFIG_EINSANE: _fatal_error("filename was null or blank"); break; case CONFIG_ENOROOT: _fatal_error("no root element found"); break; case CONFIG_EBADROOT: _fatal_error("root element is not <icecast>"); break; default: _fatal_error("XML config parsing error"); break; } _shutdown_subsystems(); return 1; } } else if (res == -1) { _print_usage(); return 1; } /* override config file options with commandline options */ config_parse_cmdline(argc, argv); /* Bind socket, before we change userid */ if(!_server_proc_init()) { _fatal_error("Server startup failed. Exiting"); _shutdown_subsystems(); return 1; } _ch_root_uid_setup(); /* Change user id and root if requested/possible */ stats_initialize(); /* We have to do this later on because of threading */ fserve_initialize(); /* This too */ #ifdef CHUID /* We'll only have getuid() if we also have setuid(), it's reasonable to * assume */ if(!getuid()) /* Running as root! Don't allow this */ { fprintf(stderr, "ERROR: You should not run icecast2 as root\n"); fprintf(stderr, "Use the changeowner directive in the config file\n"); _shutdown_subsystems(); return 1; } #endif /* setup default signal handlers */ sighandler_initialize(); if (!_start_logging()) { _fatal_error("FATAL: Could not start logging"); _shutdown_subsystems(); return 1; } INFO0 (ICECAST_VERSION_STRING " server started"); /* REM 3D Graphics */ /* let her rip */ global.running = ICE_RUNNING; /* Startup yp thread */ yp_initialize(); /* Do this after logging init */ slave_initialize(); auth_initialise (); } else { /**DSU control 2 */ /* setup default signal handlers */ sighandler_initialize(); } /* END EKIDEN INIT BLOCK */ _server_proc(); INFO0("Shutting down"); _shutdown_subsystems(); if (pidfile) { remove (pidfile); free (pidfile); } return 0; }
int main(int argc, char **argv) { int res, ret; ice_config_t *config; char *pidfile = NULL; char filename[512]; char pbuf[1024]; /* parse the '-c icecast.xml' option ** only, so that we can read a configfile */ res = _parse_config_file(argc, argv, filename, 512); if (res == 1) { /* startup all the modules */ _initialize_subsystems(); /* parse the config file */ config_get_config(); ret = config_initial_parse_file(filename); config_release_config(); if (ret < 0) { memset(pbuf, '\000', sizeof(pbuf)); snprintf(pbuf, sizeof(pbuf)-1, "FATAL: error parsing config file (%s)", filename); _fatal_error(pbuf); switch (ret) { case CONFIG_EINSANE: _fatal_error("filename was null of blank"); break; case CONFIG_ENOROOT: _fatal_error("no root element found"); break; case CONFIG_EBADROOT: _fatal_error("root element is not <icecast>"); break; default: _fatal_error("XML config parsing error"); break; } _shutdown_subsystems(); return 1; } } else if (res == -1) { _print_usage(); return 1; } /* override config file options with commandline options */ config_parse_cmdline(argc, argv); /* Bind socket, before we change userid */ if(!_server_proc_init()) { _fatal_error("Server startup failed. Exiting"); _shutdown_subsystems(); return 1; } _ch_root_uid_setup(); /* Change user id and root if requested/possible */ stats_initialize(); /* We have to do this later on because of threading */ fserve_initialize(); /* This too */ #ifdef CHUID /* We'll only have getuid() if we also have setuid(), it's reasonable to * assume */ if(!getuid()) /* Running as root! Don't allow this */ { fprintf(stderr, "WARNING: You should not run icecast2 as root\n"); fprintf(stderr, "Use the changeowner directive in the config file\n"); _shutdown_subsystems(); return 1; } #endif /* setup default signal handlers */ sighandler_initialize(); if (!_start_logging()) { _fatal_error("FATAL: Could not start logging"); _shutdown_subsystems(); return 1; } config = config_get_config_unlocked(); /* recreate the pid file */ if (config->pidfile) { FILE *f; pidfile = strdup (config->pidfile); if (pidfile && (f = fopen (config->pidfile, "w")) != NULL) { fprintf (f, "%d\n", getpid()); fclose (f); } } /* Do this after logging init */ slave_initialize(); INFO0("icecast server started"); /* REM 3D Graphics */ /* let her rip */ global.running = ICE_RUNNING; #ifdef USE_YP /* Startup yp thread */ yp_initialize(); #endif _server_proc(); INFO0("Shutting down"); _shutdown_subsystems(); if (pidfile) { remove (pidfile); free (pidfile); } return 0; }
int main ( int argc, char *argv[] ) { int myid, stages, numbprocs, *TaskCount, total=0, remainder[2][2], remainder_pos=-1, remainderjob=0, cnt_index=0, NUM_GROUP, NUM_VARS, num_group=0, cnt_stage=1, i, slv, count, r, c; double startwtime,slavewtime,wtime,*mytime, stagewtime; char filename[50], ans; WSET *ws; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numbprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); adainit(); if(myid == 0) { printf("Give a file name (less than 50 characters) : "); scanf("%s",filename); scanf("%c",&ans); /* skip current new line symbol */ printf("\n# of eqn. group :"); scanf("%d",&NUM_GROUP); scanf("%c",&ans); printf("\n# of vars :"); scanf("%d",&NUM_VARS); scanf("%c",&ans); } /* broadcast data */ MPI_Barrier(MPI_COMM_WORLD); if(myid == 0) printf("\nManager broadcast data. \n"); MPI_Bcast(filename,50*sizeof(char),MPI_CHAR,0,MPI_COMM_WORLD); MPI_Bcast(&NUM_GROUP,sizeof(int),MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(&NUM_VARS,sizeof(int),MPI_INT,0,MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); num_group = NUM_GROUP; stages = (int)ceil(log(NUM_GROUP)/log(2)); if(myid == 0) { /* TaskCount = (int*) calloc(numbprocs-1, sizeof(int));*/ TaskCount = (int*) malloc(sizeof(int)*(numbprocs-1)); ws = (WSET*) calloc(NUM_GROUP*(stages+1), sizeof(WSET)); /* mytime = (double*) calloc(numbprocs, sizeof(double)); */ mytime = (double*) malloc(sizeof(double)*numbprocs); /* initialize TaskCount & remainder array */ cnt_index=0; for(slv=1;slv<=numbprocs-1;slv++) { *(TaskCount+slv-1)=0; } remainder_pos = -1; for(i=1;i<=2;i++) { remainder[i-1][0] = 0; remainder[i-1][1] = 0; } } /* initialization */ if(myid == 0) { startwtime = MPI_Wtime(); manager_initialize(ws, NUM_GROUP, stages, numbprocs, filename); } else { slavewtime = MPI_Wtime(); slave_initialize(myid, NUM_GROUP, filename); } /* Initialization phase and mainloop initialization are DONE */ if(myid == 0) { if((int)fmod(num_group,2)==1) /* there is a remainder */ { remainder_pos++; remainder[remainder_pos][0] = num_group-1; remainder[remainder_pos][1] = 0; printf("record remainder. ws[%d][%d]\n", remainder[remainder_pos][0], remainder[remainder_pos][1]); } } num_group = (int)floor(num_group/2); /* stages */ for(cnt_stage=1;cnt_stage<=stages;cnt_stage++) { if(myid == 0) { printf("*********** stage %d **************** \n", cnt_stage); stagewtime = MPI_Wtime(); } compute_witness_sets(myid,stages,cnt_stage,numbprocs,NUM_GROUP,NUM_VARS, num_group,ws,TaskCount,&cnt_index,filename, &remainder_pos,remainder); MPI_Barrier(MPI_COMM_WORLD); /* once all groups are finished, clear cnt_index */ if(myid == 0) { printf("outside of compute_witness_sets\n"); printf("remainder_pos=%d\n", remainder_pos); cnt_index = 0; if((int)fmod(num_group,2)==1 && cnt_stage!=stages) /* there is a remainder */ { remainder_pos++; remainder[remainder_pos][0] = num_group-1; remainder[remainder_pos][1] = cnt_stage; printf("record remainder: ws[%d][%d]\n", remainder[remainder_pos][0], remainder[remainder_pos][1]); printf("remainder_pos=%d\n", remainder_pos); } } num_group = (int)floor(num_group/2); if(num_group==0 && cnt_stage!=stages) num_group=1; /* print out remainders info. */ if(v>0) { if(myid == 0) { if(remainder_pos==1) /* two remainders exist */ {printf("remainders:\n"); printf("ws[%d][%d] and ws[%d][%d]\n", remainder[0][0],remainder[0][1], remainder[1][0],remainder[1][1]); } if(remainder_pos==0 && cnt_stage!=stages) { printf("remainder:\n"); printf("ws[%d][%d] \n", remainder[0][0],remainder[0][1]); } } } if(myid == 0) { printf("stage %d: %lf seconds\n", cnt_stage, MPI_Wtime()-stagewtime); } }/* cnt_stage, stages */ if(myid == 0) wtime = MPI_Wtime()-startwtime; else wtime = MPI_Wtime()-slavewtime; MPI_Gather(&wtime,1,MPI_DOUBLE,mytime,1,MPI_DOUBLE,0,MPI_COMM_WORLD); if(myid == 0) { print_time(mytime,numbprocs); printf("\nTask tallies:\n"); for(slv=1;slv<=numbprocs-1;slv++) { total = total + *(TaskCount+slv-1); printf("Node %d ----- %d jobs \n",slv, *(TaskCount+slv-1)); } printf("----------------------\n"); printf(" %d jobs! \n", total); /* clean up */ free(TaskCount); free(mytime); for(r=0;r<NUM_GROUP;r++) for(c=0;c<=stages;c++) kill_ws(ws+r*(stages+1)+c); } adafinal(); MPI_Finalize(); return 0; }