static bool start_master() { bool is_child; //master inherits fds! ltr_int_log_message("Start master\n"); int socket = ltr_int_connect_to_socket(ltr_int_master_socket_name()); ltr_int_log_message("socket %d\n", socket); if(socket < 0){ //no master there yet, so lets start one ltr_int_log_message("Master is not running, start it\n"); if(!getenv("LTR_KEEP_LD_LIBRARY_PATH")){ ltr_int_log_message("Reseting LD_LIBRARY_PATH.\n"); unsetenv("LD_LIBRARY_PATH"); }else{ ltr_int_log_message("LTR_KEEP_LD_LIBRARY_PATH set, keeping LD_LIBRARY_PATH set.\n"); } char *args[] = {"srv", NULL}; args[0] = ltr_int_get_app_path("/ltr_server1"); ltr_int_fork_child(args, &is_child); int status; //Disable the wait when not daemonizing master!!! wait(&status); //At this point master is either running or exited (depending on the state of socket) free(args[0]); } close(socket); //At this point either master runs already, or we just started one return true; }
static bool start_master(int *l_master_uplink, int *l_master_downlink) { bool is_child; //master inherits fds! int fifo = ltr_int_open_fifo_exclusive(ltr_int_master_fifo_name(), &master_lock); if(fifo > 0){ //no master there yet, so lets start one close(fifo); ltr_int_unlockSemaphore(master_lock); ltr_int_closeSemaphore(master_lock); close_master_comms(l_master_uplink, l_master_downlink); ltr_int_log_message("Master is not running, start it\n"); char *args[] = {"srv", NULL}; args[0] = ltr_int_get_app_path("/ltr_server1"); ltr_int_fork_child(args, &is_child); int status; //Disable the wait when not daemonizing master!!! wait(&status); //At this point master is either running or exited (depending on the state of fifo) free(args[0]); } //At this point either master runs already, or we just started one return true; }