/* Start the owlib process -- actually only tests for backgrounding */ GOOD_OR_BAD EnterBackground(void) { /* First call to pthread should be done after daemon() in uClibc, so * I moved it here to avoid calling __pthread_initialize() */ /* daemon() is called BEFORE initialization of USB adapter etc... Cygwin will fail to * use the adapter after daemon otherwise. Some permissions are changed on the process * (or process-group id) which libusb-win32 is depending on. */ //printf("Enter Background\n") ; if (Globals.want_background) { switch (Globals.program_type) { case program_type_filesystem: // handles PID from a callback break; case program_type_httpd: case program_type_ftpd: case program_type_server: case program_type_external: if ( // daemonize // current directory left unchanged (not root) // stdin, stdout and stderr sent to /dev/null #ifdef HAVE_DAEMON daemon(1, 0) #else /* HAVE_DAEMON */ my_daemon(1, 0) #endif /* HAVE_DAEMON */ ) { LEVEL_DEFAULT("Cannot enter background mode, quitting."); return gbBAD; } else { Globals.now_background = 1; LEVEL_DEFAULT("Entered background mode, quitting."); #ifdef __UCLIBC__ /* Have to re-initialize pthread since the main-process is gone. * * This workaround will probably be fixed in uClibc-0.9.28 * Other uClibc developers have noticed similar problems which are * trigged when pthread functions are used in shared libraries. */ LockSetup(); #endif /* __UCLIBC__ */ } default: PIDstart(); break; } } else { // not background if (Globals.program_type != program_type_filesystem) { PIDstart(); } } #if OW_MT main_threadid = pthread_self(); main_threadid_init = 1 ; LEVEL_DEBUG("main thread id = %lu", (unsigned long int) main_threadid); #endif return gbGOOD; }
/* All ow library setup */ void LibSetup(enum enum_program_type program_type) { Return_code_setup() ; /* Setup the multithreading synchronizing locks */ LockSetup(); Globals.program_type = program_type; Cache_Open(); Detail_Init(); StateInfo.start_time = NOW_TIME; SetLocalControlFlags() ; // reset by every option and other change. errno = 0; /* set error level none */ }