void main_init( int argc, char ** const argv ) { dprintf(D_FULLDEBUG, "Welcome to the C-GAHP\n"); // handle specific command line args int i = 1; while ( i < argc ) { if ( argv[i][0] != '-' ) usage(); switch( argv[i][1] ) { case 's': // don't check parent for schedd addr. use this one instead if ( argc <= i + 1 ) usage(); ScheddAddr = strdup( argv[i + 1] ); i++; break; case 'P': // specify what pool (i.e. collector) to lookup the schedd name if ( argc <= i + 1 ) usage(); ScheddPool = strdup( argv[i + 1] ); i++; break; default: usage(); break; } i++; } // Setup dprintf to display pid DebugId = display_dprintf_header; Init(); Register(); Reconfig(); // inherit the DaemonCore pipes that our parent created REQUEST_INBOX = daemonCore->Inherit_Pipe(fileno(stdin), false, // read pipe true, // registerable false); // blocking RESULT_OUTBOX = daemonCore->Inherit_Pipe(fileno(stdout), true, // write pipe false, // nonregistrable false); // blocking request_buffer.setPipeEnd( REQUEST_INBOX ); daemonCore->Register_Timer(0, init_pipes, "init_pipes" ); // Just set up timers.... contactScheddTid = daemonCore->Register_Timer( contact_schedd_interval, doContactSchedd, "doContactSchedD" ); }
void main_init( int, char ** const) { dprintf(D_ALWAYS, "FT-GAHP IO thread\n"); dprintf(D_SECURITY | D_FULLDEBUG, "FT-GAHP IO thread\n"); int stdin_pipe = -1; #if defined(WIN32) // if our parent is not DaemonCore, then our assumption that // the pipe we were passed in via stdin is overlapped-mode // is probably wrong. we therefore create a new pipe with the // read end overlapped and start a "forwarding thread" if (daemonCore->InfoCommandSinfulString(daemonCore->getppid()) == NULL) { dprintf(D_FULLDEBUG, "parent is not DaemonCore; creating a forwarding thread\n"); int pipe_ends[2]; if (daemonCore->Create_Pipe(pipe_ends, true) == FALSE) { EXCEPT("failed to create forwarding pipe"); } forwarding_pipe = pipe_ends[1]; HANDLE thread_handle = (HANDLE)_beginthreadex(NULL, // default security 0, // default stack size pipe_forward_thread, // start function NULL, // arg: write end of pipe 0, // not suspended NULL); // don't care about the ID if (thread_handle == NULL) { EXCEPT("failed to create forwarding thread"); } CloseHandle(thread_handle); stdin_pipe = pipe_ends[0]; } #endif if (stdin_pipe == -1) { // create a DaemonCore pipe from our stdin stdin_pipe = daemonCore->Inherit_Pipe(fileno(stdin), false, // read pipe true, // registerable false); // blocking } stdin_buffer.setPipeEnd(stdin_pipe); (void)daemonCore->Register_Pipe (stdin_buffer.getPipeEnd(), "stdin pipe", (PipeHandler)&stdin_pipe_handler, "stdin_pipe_handler"); // Setup dprintf to display pid DebugId = display_dprintf_header; // Print out the GAHP version to the screen // now we're ready to roll printf ("%s\n", version); fflush(stdout); dprintf(D_FULLDEBUG,"put stdout: %s\n",version); download_sandbox_reaper_id = daemonCore->Register_Reaper( "download_sandbox_reaper", &download_sandbox_reaper, "download_sandbox", NULL ); dprintf(D_FULLDEBUG, "registered download_sandbox_reaper() at %i\n", download_sandbox_reaper_id); upload_sandbox_reaper_id = daemonCore->Register_Reaper( "upload_sandbox_reaper", &upload_sandbox_reaper, "upload_sandbox", NULL ); dprintf(D_FULLDEBUG, "registered upload_sandbox_reaper() at %i\n", upload_sandbox_reaper_id); destroy_sandbox_reaper_id = daemonCore->Register_Reaper( "destroy_sandbox_reaper", &destroy_sandbox_reaper, "destroy_sandbox", NULL ); dprintf(D_FULLDEBUG, "registered destroy_sandbox_reaper() at %i\n", destroy_sandbox_reaper_id); dprintf (D_FULLDEBUG, "FT-GAHP IO initialized\n"); }