static void ok_cb(Fl_Widget*, void* w) { LaunchWindow* win = (LaunchWindow*)w; const char* cmd = dialog_input->value(); bool started = false; win->hide(); /* do not block dialog when program is starting */ Fl::check(); /* TODO: is 'cmd' safe after hide? */ if(in_term->value()) { char buf[128]; char* term = getenv("TERM"); if(!term) term = "xterm"; snprintf(buf, sizeof(buf), "%s -e %s", term, cmd); started = start_child(buf); } else { started = start_child(cmd); } if(!started) { /* show dialog again */ win->show(); if(cmd) dialog_input->position(0, dialog_input->size()); } else { Resource rc; rc.set("History", "open", cmd); rc.save("ede-launch-history"); } }
int start_server(int fd){ int child_indx,pid,i,status; int childs,freeservers,used,maxrequests; ci_proc_mutex_init(&accept_mutex); if(!create_childs_queue(&childs_queue,MAX_CHILDS)){ debug_printf(1,"Can't init shared memory.Fatal error, exiting!\n"); exit(0); } pid=1; #ifdef MULTICHILD for(i=0;i< START_CHILDS; i++){ if(pid) pid=start_child(fd); } if(pid!=0){ main_signals(); while(1){ sleep(1); /*Must be replaced by nanosleep. */ childs_queue_stats(&childs_queue,&childs,&freeservers, &used, &maxrequests); debug_printf(10,"Server stats: \n\t Childs:%d\n\t Free servers:%d\n\tUsed servers:%d\n\tRequests served:%d\n", childs, freeservers,used, maxrequests); if( (freeservers<=MIN_FREE_SERVERS && childs<MAX_CHILDS) ||childs<START_CHILDS){ debug_printf(8,"Going to start a child .....\n"); pid=start_child(fd); } else if(freeservers>=MAX_FREE_SERVERS&& childs>START_CHILDS){ child_indx=find_an_idle_child(&childs_queue); childs_queue.childs[child_indx].to_be_killed=GRACEFULLY; kill(childs_queue.childs[child_indx].pid,SIGINT); debug_printf(8,"Going to stop child %d .....\n",childs_queue.childs[child_indx].pid); //kill a server ... } } for(i=0;i<START_CHILDS;i++){ pid=wait(&status); debug_printf(5,"The child %d died with status %d\n",pid,status); } } #else child_data=(child_shared_data_t *)malloc(sizeof(child_shared_data_t)); child_data->pid=0; child_data->freeservers=START_SERVERS; child_data->usedservers=0; child_data->requests=0; child_data->connections=0; child_data->to_be_killed=0; child_data->idle=1; child_main(fd); #endif }
static void pcmk_process_exit(pcmk_child_t * child) { child->pid = 0; child->active_before_startup = FALSE; /* Broadcast the fact that one of our processes died ASAP * * Try to get some logging of the cause out first though * because we're probably about to get fenced * * Potentially do this only if respawn_count > N * to allow for local recovery */ update_node_processes(local_nodeid, NULL, get_process_list()); child->respawn_count += 1; if (child->respawn_count > MAX_RESPAWN) { crm_err("Child respawn count exceeded by %s", child->name); child->respawn = FALSE; } if (shutdown_trigger) { mainloop_set_trigger(shutdown_trigger); update_node_processes(local_nodeid, NULL, get_process_list()); } else if (child->respawn && crm_is_true(getenv("PCMK_fail_fast"))) { crm_err("Rebooting system because of %s", child->name); pcmk_panic(__FUNCTION__); } else if (child->respawn) { crm_notice("Respawning failed child process: %s", child->name); start_child(child); } }
static void init_children_processes(void) { int start_seq = 1, lpc = 0; static int max = SIZEOF(pcmk_children); /* start any children that have not been detected */ for (start_seq = 1; start_seq < max; start_seq++) { /* dont start anything with start_seq < 1 */ for (lpc = 0; lpc < max; lpc++) { if (pcmk_children[lpc].pid) { /* we are already tracking it */ continue; } if (start_seq == pcmk_children[lpc].start_seq) { start_child(&(pcmk_children[lpc])); } } } /* From this point on, any daemons being started will be due to * respawning rather than node start. * * This may be useful for the daemons to know */ setenv("PCMK_respawned", "true", 1); }
int main(int argc, char *argv[]) { if (argc < 2) { std::cerr << "Please provide a program name" << std::endl; return EXIT_FAILURE; } bp::child c = start_child(argv[1]); bp::posix_status s = c.wait(); if (s.exited()) std::cout << "Program returned exit code " << s.exit_status() << std::endl; else if (s.signaled()) { std::cout << "Program received signal " << s.term_signal() << std::endl; if (s.dumped_core()) std::cout << "Program also dumped core" << std::endl; } else if (s.stopped()) std::cout << "Program stopped by signal " << s.stop_signal() << std::endl; else std::cout << "Unknown termination reason" << std::endl; return s.exited() ? s.exit_status() : EXIT_FAILURE; }
int GraphBuilder::get_trace(const char* pathfile, syscall_t** trace) { int fd, status, ret; pid_t child; /* open system call interceptor driver */ fd = open(SCID_DEVICE_PATH, O_RDWR); DIE(fd < 0, "scid device open"); /* create process and get pid */ child = start_child(pathfile); /* set process pid to monitor */ ret = ioctl(fd, IOCTL_SET_PID, &child); if(ret != 0) { std::cerr<<"failed to set pid"<<std::endl; return -1; } ret = sem_post(child_sem); DIE(ret < 0, "error posting semaphore"); /* wait until process child ends to get a full trace of it's * execution */ ret = waitpid(child, &status, 0); /* read the program system call trace from driver */ ret = read_trace(fd, trace); /* close device */ close(fd); return ret; }
int main() { bp::child c = start_child(); bp::pistream &is = c.get_stdout(); std::string line; while (std::getline(is, line)) std::cout << line << std::endl; }
int main() { int pipefd[2]; int pipefd2[2]; char c; if (pipe(pipefd) || pipe(pipefd2)) { perror("pipe"); exit(1); } signal(SIGCHLD, sighandler); started=finished=0; while (started < INITCHILDREN) { if (start_child() == 0) { close(pipefd2[0]); close(pipefd2[1]); close(pipefd[1]); if (read(pipefd[0], &c, 1) != 1) ; /* Shut gcc up */ close(pipefd[0]); _exit(0); } } close(pipefd2[1]); close(pipefd[0]); if (read(pipefd2[0], &c, 1) != 1) ; /* Shut gcc up */ close(pipefd[1]); close(pipefd2[0]); while (started < NUMCHILDREN) if (start_child() == 0) _exit(0); alarm(30); while (finished < started) foobar(); exit(0); }
int main(int argc, char** argv) { if(argc <= 1) return start_dialog(argc, argv); /* do not see possible flags as commands */ if(argv[1][0] == '-') { help(); return 0; } String args; unsigned int alen; for(int i = 1; i < argc; i++) { args += argv[i]; args += ' '; } alen = args.length(); /* remove start/ending quotes and spaces */ if((args[0] == '"') || isspace(args[0]) || (args[alen - 1] == '"') || isspace(args[alen - 1])) { int i; char *copy = strdup(args.c_str()); char *ptr = copy; /* remove ending first */ for(i = (int)alen - 1; i > 0 && (ptr[i] == '"' || isspace(ptr[i])); i--) ; ptr[i + 1] = 0; /* remove then starting */ for(; *ptr && (*ptr == '"' || isspace(*ptr)); ptr++) ; start_child(ptr); free(copy); } else { start_child(args.c_str()); } return 0; }
/* * Called only in the main thread * * For IPv6, unplumbing the link local interface causes dhcp and ndpd to remove * other addresses they have added. We watch for routing socket events on the * IPv4 interface, which is always enabled, so no need to keep IPv6 around on a * switch. */ void clear_cached_address(const char *ifname) { struct interface *ifp; uint64_t ifflags; if ((ifp = get_interface(ifname)) == NULL) { dprintf("clear_cached_address: can't find interface struct " "for %s", ifname); (void) start_child(IFCONFIG, ifname, "inet6", "unplumb", NULL); return; } if (ifp->if_v6onlink) (void) start_child(IFCONFIG, ifname, "inet6", "unplumb", NULL); ifflags = get_ifflags(ifname, AF_INET); if ((ifflags & IFF_UP) && !(ifflags & IFF_RUNNING)) zero_out_v4addr(ifname); ifp->if_ipv4addr = INADDR_ANY; ifp->if_lflags &= ~IF_DHCPFLAGS; }
int main() { try { bp::win32_child c = start_child(); } catch (boost::filesystem::filesystem_error &ex) { std::cout << ex.what() << std::endl; } }
int main() { bp::child c = start_child(); bp::pistream &is = c.get_stdout(); in.assign(is.handle().release()); begin_read(); io_service.run(); c.wait(); }
static int server_reconfigure() { int i; if (old_childs_queue) { ci_debug_printf(1, "A reconfigure pending. Ignoring reconfigure request.....\n"); return 1; } /*shutdown all modules and services and reopen config file */ if (!system_reconfigure()) return 0; /*initialize commands table for server */ init_commands(); /* Mark all existing childs as to_be_killed gracefully (childs_queue.childs[child_indx].to_be_killed = GRACEFULLY) */ for (i = 0; i < childs_queue->size; i++) { if (childs_queue->childs[i].pid != 0) { childs_queue->childs[i].father_said = GRACEFULLY; kill(childs_queue->childs[i].pid, SIGTERM); } } /* Create new shared mem for childs queue */ old_childs_queue = childs_queue; childs_queue = malloc(sizeof(struct childs_queue)); if (!create_childs_queue(childs_queue, 2 * CONF.MAX_SERVERS)) { ci_debug_printf(1, "Cannot init shared memory. Fatal error, exiting!\n"); return 0; /*It is not enough. We must wait all childs to exit ..... */ } /* Start new childs to handle new requests. */ if (CONF.START_SERVERS > CONF.MAX_SERVERS) CONF.START_SERVERS = CONF.MAX_SERVERS; for (i = 0; i < CONF.START_SERVERS; i++) { start_child(LISTEN_SOCKET); } /* When all childs exits release the old shared mem block.... */ return 1; }
int main() { bp::context ctx; ctx.stdout_behavior = bp::capture_stream(); ctx.environment = bp::self::get_environment(); bp::child c = start_child(ctx); bp::pistream &is = c.get_stdout(); std::string line; while (std::getline(is, line)) std::cout << line << std::endl; }
/* ARGSUSED */ static int do_unplumb_if(icfg_if_t *intf, void *arg) { uint64_t flags = get_ifflags(intf->if_name, intf->if_protocol); /* We don't touch loopback interface. */ if (flags & IFF_LOOPBACK) return (ICFG_SUCCESS); (void) start_child(IFCONFIG, intf->if_name, intf->if_protocol == AF_INET6 ? "inet6" : "inet", "unplumb", NULL); return (ICFG_SUCCESS); }
static void terminated_child(unsigned idx, unsigned delid) { if (ESMTP_TERMINATING(&info[idx])) { char *p; if ((p=info[idx].pendel) != 0) { char **cols=module_parsecols(info[idx].pendel); /* ** Clear to 0 to prevent infinite loop if fork fails ** in start_child. */ info[idx].pendel=0; start_child(idx, info[idx].pendel, cols); info[idx].pendel=p; send_child(idx, info[idx].pendel, cols); return; } info[idx].pid= -1; return; } /* Oops, something crashed. Clean it up */ clog_msg_start_err(); if (info[idx].pid < 0) { clog_msg_str("Unable to fork"); } else { clog_msg_str("Crashed child process "); clog_msg_uint(info[idx].pid); } if (ESMTP_BUSY(&info[idx])) { clog_msg_str(", while delivering to "); clog_msg_str(info[idx].host); module_completed(idx, delid); } clog_msg_send(); close(info[idx].cmdpipe); info[idx].cmdpipe= -1; info[idx].pid= -1; }
int main() { bp::context ctx; ctx.stdout_behavior = bp::capture_stream(); ctx.environment = bp::self::get_environment(); ctx.environment.erase("TMP"); ctx.environment.insert(bp::environment::value_type("MYNEWVAR", "VALUE")); bp::child c = start_child(ctx); bp::pistream &is = c.get_stdout(); std::string line; while (std::getline(is, line)) std::cout << line << std::endl; }
static inline void handle_incoming_fds(fd_set * readmask, fd_set * writemask) { struct stService *p; for(p=servicelist; p!=NULL; p=p->next) { int fd; if (p->master_socket && FD_ISSET(p->master_socket, readmask)) { union sa remote; int j; /* * There is always at least one slot available in the loop below, * see generate_select_fds(), the p->limit check. */ for(j=0;j<MAX_CONNECT;j++) if (p->pid[j] == 0) break; if (p->tcp) { int remotelen = sizeof(remote); fd = accept(p->master_socket, &remote.sa, &remotelen); if (fd < 0) { fprintf(stderr, "accept failed\n"); break; } } else { fd = p->master_socket; } p->current++; if ((p->pid[j] = start_child(p, fd, p->tcp, p->ipv6, p->port, &remote)) == -1) { /* * if we fail to start the child, disable the service */ p->enabled = 0; close(p->master_socket); p->master_socket = 0; p->current--; } if (p->tcp) { close(fd); } } } }
/* --- execute a shell command --- */ int executeshellcmd (Shellcmd *shellcmd) { int pipe_ends[2]; int pipe_in = STDIN_FILENUMBER; // Used for a future command, to read from a previous one. pid_t process_id; Cmd *current_cmd = reverse(shellcmd->the_cmds); //Commands are parsed back-to-front, so we reverse. int first = 1; //We're at the first command at first run. while (current_cmd) { if (pipe(pipe_ends) == -1) return -1; //Try to pipe. process_id = fork(); //Instantiate new process. if (process_id == 0) { //This is a child process. int *in, *out; *in = -1; *out = -1; set_in_out(shellcmd, current_cmd, pipe_ends, pipe_in, first, in, out); start_child(current_cmd, *in, *out); } else { // Parent process. if (!first) { close(pipe_in); } pipe_in = pipe_ends[STDIN_FILENUMBER]; close(pipe_ends[STDOUT_FILENUMBER]); first = 0; //No longer the first command. current_cmd = current_cmd->next; //Assign the next command for execution. } } close(pipe_ends[STDIN_FILENUMBER]); //Close the pipe in parent if (shellcmd->background) { //If the user specified to execute in background, then don't wait. return 0; } int exit_code; waitpid(process_id, &exit_code, 0); //Assert that the process executed succesfully. return 0; }
int main() { try { bp::win32_child c = start_child(); std::cout << "Process handle : 0x" << c.get_handle() << std::endl; std::cout << "Process identifier : " << c.get_id() << std::endl; std::cout << "Primary thread handle : 0x" << c.get_primary_thread_handle() << std::endl; std::cout << "Primary thread identifier : " << c.get_primary_thread_id() << std::endl; } catch (boost::filesystem::filesystem_error &ex) { std::cout << ex.what() << std::endl; } }
static inline void handle_incoming_fds(fd_set * readmask, fd_set * writemask) { struct stService *p; for(p=servicelist; p!=NULL; p=p->next) { int fd; if (p->master_socket && FD_ISSET(p->master_socket, readmask)) { int j; for(j=0;j<MAX_CONNECT;j++) if (p->pid[j] == 0) break; if (p->tcp) { struct sockaddr_in remote; unsigned int remotelen = sizeof(remote); fd = accept(p->master_socket, (struct sockaddr*)&remote, &remotelen); if (fd < 0) { printf("accept failed\n"); break; } } else { fd = p->master_socket; } p->current++; if ((p->pid[j] = start_child(p, fd)) == -1) { /* * if we fail to start the child, disable the service */ p->enabled = 0; close(p->master_socket); p->master_socket = 0; p->current--; } if (p->tcp) { close(fd); } } } }
static void init_children_processes(void) { int start_seq = 1, lpc = 0; static int max = SIZEOF(pcmk_children); /* start any children that have not been detected */ for (start_seq = 1; start_seq < max; start_seq++) { /* dont start anything with start_seq < 1 */ for (lpc = 0; lpc < max; lpc++) { if (pcmk_children[lpc].pid) { /* we are already tracking it */ continue; } if (start_seq == pcmk_children[lpc].start_seq) { start_child(&(pcmk_children[lpc])); } } } }
void deactivate_upper_layer_profile(void) { char buffer[1024]; /* * If ULP wasn't defined... */ if (!ulp_is_active()) return; (void) snprintf(buffer, sizeof (buffer), ULP_DIR "/%s/teardown", upper_layer_profile); (void) start_child(PFEXEC, "-P", "basic", buffer, NULL); syslog(LOG_NOTICE, "upper layer profile %s deactivated", upper_layer_profile); report_ulp_deactivated(upper_layer_profile); upper_layer_profile[0] = '\0'; }
/* * Execute 'ifconfig ifname dhcp wait 0'. */ static void start_dhcp(struct interface *ifp) { int res; uint32_t now_s; uint64_t timer_s; if (ifp->if_lflags & IF_DHCPSTARTED) { dprintf("start_dhcp: already started; returning"); return; } ifp->if_lflags |= IF_DHCPSTARTED; /* * If we need to use DHCP and DHCP is already controlling the * interface, we don't need to do anything. Otherwise, start it now. */ if (!(ifp->if_flags & IFF_DHCPRUNNING)) { dprintf("launching DHCP on %s", ifp->if_name); (void) start_child(IFCONFIG, ifp->if_name, "dhcp", "wait", "0", NULL); } else { dprintf("DHCP already running on %s; resetting timer", ifp->if_name); } ifp->if_lflags &= ~IF_DHCPFAILED; /* start dhcp timer */ res = lookup_count_property(OUR_PG, "dhcp_wait_time", &timer_s); if (res == -1) timer_s = NWAM_DEFAULT_DHCP_WAIT_TIME; now_s = NSEC_TO_SEC(gethrtime()); ifp->if_timer_expire = now_s + timer_s; start_timer(now_s, timer_s); }
int startMercury(LogContext& m_log, MercuryConfig& config) { StreamServerSocket sock; SocketAddress* bind_addr = config.bind_ip; int error_pipe[2]; if(pipe(error_pipe)) { perror("Error on pipe()\n"); return 1; } /* Redirect stderr to the error_pipe. This will make it * so we can still see stderr messages in the log */ dup2(error_pipe[1], STDERR_FILENO); /* Start the service that is only resposible for * logging the stderr of the this process and * its other children */ start_logging_service(error_pipe[0]); /* * Start the monitor. This will be used * to retrieve statistics about all the * network interfaces. */ MonitorProxy* monitor_proxy; monitor_proxy = start_monitor(config); m_log.printfln(INFO, "Binding to address: %s", bind_addr->toString().c_str()); sock.bind(*bind_addr); sock.listen(1); while(true) { StreamSocket* client = sock.accept(); m_log.printfln(INFO, "Connection accepted"); /* simply get 64 bytes from the client and * then close the connection */ byte recieve[64]; size_t bytes_read; bytes_read = client->read(recieve, sizeof(recieve)); delete client; /* make sure the cookie is equal to what we expect */ if(bytes_read == 64 && std::equal(recieve, recieve + 32, mercury_magic_cookie)) { ScopedLock __sl(*g_mutex); /* the cookie is equal to what we expect * so continue with the fork() */ m_log.printfln(INFO, "Magic cookie accepted, forking new process"); pid_t child; child = start_child(recieve, config, monitor_proxy); /* parent */ m_log.printfln(INFO, "Child started pid=%d", child); int res = 0; pid_t pid; /* Wait for the child to exit. this * condition will be signaled by the * sigchld handler */ if(!g_cond->timedwait(*g_mutex, 300 SECS)) { /* The child is taking too long to return * kill it */ m_log.printfln(WARN, "Child timeout, sending SIGTERM"); kill(child, SIGTERM); if(!g_cond->timedwait(*g_mutex, 10 SECS)) { /* The child still isn't dead */ m_log.printfln(WARN, "Child hard timeout, sending SIGKILL"); kill(child, SIGKILL); } } if((pid = waitpid(child, &res, WNOHANG))) { if(pid == -1) { m_log.printfln(ERROR, "Error in waitpid %s", strerror(errno)); } else { m_log.printfln(INFO, "Reap child (%d)\n", (int)pid); } } if(WIFSIGNALED(res)) { m_log.printfln(WARN, "Child was signaled with %d", WTERMSIG(res)); } if(WEXITSTATUS(res)) { m_log.printfln(WARN, "Child returned abnormal status: %d", WEXITSTATUS(res)); } if(WIFSTOPPED(res)) { m_log.printfln(WARN, "Child timed out and was killed by parent"); } } else { m_log.printfln(ERROR, "Bad magic cookie received. Timeout for 5 seconds"); sleep(5); m_log.printfln(INFO, "Timeout complete"); } } return 0; }
void nsexec(void) { int pipenum; // If we don't have init pipe, then just return to the go routine, // we'll only have init pipe for start or exec pipenum = get_init_pipe(); if (pipenum == -1) { return; } // Retrieve the netlink header struct nlmsghdr nl_msg_hdr; int len; if ((len = read(pipenum, &nl_msg_hdr, NLMSG_HDRLEN)) != NLMSG_HDRLEN) { pr_perror("Invalid netlink header length %d", len); exit(1); } if (nl_msg_hdr.nlmsg_type == NLMSG_ERROR) { pr_perror("Failed to read netlink message"); exit(1); } if (nl_msg_hdr.nlmsg_type != INIT_MSG) { pr_perror("Unexpected msg type %d", nl_msg_hdr.nlmsg_type); exit(1); } // Retrieve data int nl_total_size = NLMSG_PAYLOAD(&nl_msg_hdr, 0); char data[nl_total_size]; if ((len = read(pipenum, data, nl_total_size)) != nl_total_size) { pr_perror("Failed to read netlink payload, %d != %d", len, nl_total_size); exit(1); } jmp_buf env; int syncpipe[2] = {-1, -1}; struct nsenter_config config = process_nl_attributes(pipenum, data, nl_total_size); // required clone_flags to be passed if (config.cloneflags == -1) { pr_perror("Missing clone_flags"); exit(1); } // prepare sync pipe between parent and child. We need this to let the // child know that the parent has finished setting up if (pipe(syncpipe) != 0) { pr_perror("Failed to setup sync pipe between parent and child"); exit(1); } if (setjmp(env) == 1) { // Child uint8_t s = 0; int consolefd = config.consolefd; // close the writing side of pipe close(syncpipe[1]); // sync with parent if ((read(syncpipe[0], &s, 1) != 1) || (s != 1)) { pr_perror("Failed to read sync byte from parent"); exit(1); } if (setsid() == -1) { pr_perror("setsid failed"); exit(1); } if (setuid(0) == -1) { pr_perror("setuid failed"); exit(1); } if (setgid(0) == -1) { pr_perror("setgid failed"); exit(1); } if (setgroups(0, NULL) == -1) { pr_perror("setgroups failed"); exit(1); } if (consolefd != -1) { if (ioctl(consolefd, TIOCSCTTY, 0) == -1) { pr_perror("ioctl TIOCSCTTY failed"); exit(1); } if (dup3(consolefd, STDIN_FILENO, 0) != STDIN_FILENO) { pr_perror("Failed to dup stdin"); exit(1); } if (dup3(consolefd, STDOUT_FILENO, 0) != STDOUT_FILENO) { pr_perror("Failed to dup stdout"); exit(1); } if (dup3(consolefd, STDERR_FILENO, 0) != STDERR_FILENO) { pr_perror("Failed to dup stderr"); exit(1); } } // Finish executing, let the Go runtime take over. return; } // Parent start_child(pipenum, &env, syncpipe, &config); }
int WINAPI WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) { int wait_for_child = FALSE; int compact_invocation = FALSE; DWORD ret_code = 0; char execname[FILENAME_MAX]; char execpath[MAX_PATH]; char* argv[MAX_ARGS+1]; /* leave extra slot for compact_invocation argv[0] */ int argc; int i,j; char exec[MAX_PATH + FILENAME_MAX + 100]; char cmdline2[MAX_ARGS * MAX_PATH]; compact_invocation = get_exec_name_and_path(execname,execpath); if (compact_invocation) { argv[0] = execname; argc = parse_cmdline_to_arg_array(&(argv[1]),cmdline); argc++; } else { argc = parse_cmdline_to_arg_array(argv,cmdline); if (argc >= 1) strcpy(execname,argv[0]); } /* at this point, execpath is defined, as are argv[] and execname */ #ifdef DEBUG j = sprintf(buffer,"\nexecname : %s\nexecpath : %s\n",execname,execpath); for (i = 0; i < argc; i++) j += sprintf(buffer+j,"argv[%d]\t: %s\n",i,argv[i]); Trace((buffer)); #endif if (execname == NULL) error("you must supply a program name to run"); #if defined(__CYGWIN__) /* this insures that we search for symlinks before .exe's */ // if (compact_invocation) // strip_exe(execname); #endif process_execname(exec,execname,execpath); Trace(("exec\t%s\nexecname\t%s\nexecpath\t%s\n", exec,execname,execpath)); wait_for_child = build_cmdline(cmdline2,exec,argc,argv); Trace((cmdline2)); xemacs_special(exec); ret_code = start_child(cmdline2,wait_for_child); if (compact_invocation) for (i = 1; i < argc; i++) // argv[0] was not malloc'ed free(argv[i]); else for (i = 0; i < argc; i++) free(argv[i]); return (int) ret_code; }
/* Called only in the main thread */ void takedowninterface(const char *ifname, libnwam_diag_cause_t cause) { uint64_t flags; struct interface *ifp; dprintf("takedowninterface(%s, %d)", ifname, (int)cause); if ((ifp = get_interface(ifname)) == NULL) { dprintf("takedowninterface: can't find interface struct for %s", ifname); } flags = get_ifflags(ifname, AF_INET); if (flags & IFF_DHCPRUNNING) { /* * We generally prefer doing a release, as that tells the * server that it can relinquish the lease, whereas drop is * just a client-side operation. But if we never came up, * release will fail, because dhcpagent does not allow an * interface without a lease to release, so we have to drop in * that case. So try release first, then fall back to drop. */ if (start_child(IFCONFIG, ifname, "dhcp", "wait", "2", "release", NULL) != 0) { (void) start_child(IFCONFIG, ifname, "dhcp", "wait", "2", "drop", NULL); } } else { if (flags & IFF_UP) (void) start_child(IFCONFIG, ifname, "down", NULL); /* need to unset a statically configured addr */ (void) start_child(IFCONFIG, ifname, "0.0.0.0", "netmask", "0", "broadcast", "0.0.0.0", NULL); } if (ifp == NULL || ifp->if_v6onlink) { /* * Unplumbing the link local interface causes dhcp and ndpd to * remove other addresses they have added. */ (void) start_child(IFCONFIG, ifname, "inet6", "unplumb", NULL); } if (ifp == NULL || ifp->if_up_attempted) report_interface_down(ifname, cause); if (ifp != NULL) { /* We're no longer expecting the interface to be up */ ifp->if_flags = flags & ~IFF_UP; if (ifp->if_type == IF_WIRELESS) { /* and if it's wireless, it's not running, either */ ifp->if_flags &= ~IFF_RUNNING; disconnect_wlan(ifp->if_name); } dprintf("takedown interface, zero cached ip address"); ifp->if_lflags &= ~IF_DHCPSTARTED & ~IF_DHCPACQUIRED; ifp->if_ipv4addr = INADDR_ANY; ifp->if_up_attempted = B_FALSE; } }
int main() { while (start_child() > 0) { killworkers(); } return 0; }
int main(int argc, char *argv[]) { int other=0; int i; char *conn="conntrack -E"; char *logger="logger -t log-conntrack -p daemon.notice"; char *fother="grep -vE 'tcp|udp|icmp'"; char cmd[1024]; char cmd_to_run[1024]; int length = 0; char * temp_cmd = cmd; for (i=1; i<argc; i++) { switch(argv[i][1]) { case 'p': if (i+1 < argc && argv[i+1][0] != '-') { if (strncmp(argv[i+1], "other", strlen(argv[i+1])) == 0) { other=1; snprintf(cmd, sizeof (cmd), "%s", conn); length = strlen (cmd); temp_cmd = cmd + length; i++; } else if ((strncmp(argv[i+1], "tcp", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "udp", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "icmp", strlen(argv[i+1])) == 0)) { snprintf(cmd, sizeof (cmd), "%s%s%s", conn, " -p ", argv[i+1]); other=0; length = strlen (cmd); temp_cmd = cmd + length; i++; } } break; case 'e': if (i+1 < argc && argv[i+1][0] != '-') { if ((strncmp(argv[i+1], "NEW", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "UPDATES", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "DESTROY", strlen(argv[i+1])) == 0)) { if (other == 1) { snprintf(temp_cmd, sizeof (cmd) - length, "%s%s%s%s%s%s%s%s", " -e ", argv[i+1], " -o id", " -b %d", " | ", fother, " | ", logger); cmds[pcounter] = malloc(strlen(cmd)+1); strcpy(cmds[pcounter],cmd); pcounter++; } else if ((strncmp(argv[i-1], "tcp",strlen(argv[i-1]))==0) && (strncmp(argv[i+1], "UPDATES",strlen(argv[i+1])) == 0)){ snprintf(temp_cmd, sizeof (cmd) - length, "%s%s", " -e ", argv[i+1]); } else { snprintf(temp_cmd, sizeof (cmd) - length, "%s%s%s%s%s%s", " -e ", argv[i+1], " -o id", " -b %d", " | ", logger); cmds[pcounter] = malloc(strlen(cmd)+1); strcpy(cmds[pcounter],cmd); pcounter++; } length = strlen (cmd); temp_cmd = cmd + length; i++; } } break; case 's': if (i+1 < argc && argv[i+1][0] != '-') { if ((strncmp(argv[i+1], "SYN_RECV", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "ESTABLISHED", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "FIN_WAIT", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "CLOSE_WAIT", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "LAST_ACK", strlen(argv[i+1])) == 0) || (strncmp(argv[i+1], "TIME_WAIT", strlen(argv[i+1])) == 0)) { snprintf(temp_cmd, sizeof (cmd) - length, "%s%s%s%s%s%s", " --state ", argv[i+1], " -o id", " -b %d", " | ", logger); cmds[pcounter] = malloc(strlen(cmd)+1); strcpy(cmds[pcounter],cmd); pcounter++; length = strlen (cmd); temp_cmd = cmd + length; i++; } } break; } } // Daemonize the connlog process. daemonize(); // Call to init_nbuffer init_nbuffer(); //Start the conntrack logging processes for(i=0;i<pcounter;i++) { sprintf(cmd_to_run, cmds[i], nbuffer[i]); start_child(cmd_to_run,i); } pid_t dead_child; int status; while( (dead_child=wait(&status)) != -1) { for(i=0;i<pcounter;i++) { if (pids[i]==dead_child) { sprintf(cmd_to_run, cmds[i], nbuffer[i]); openlog("log-conntrack", LOG_PID, LOG_USER); syslog(LOG_ALERT, "PROCESS EXITED: %s ", cmd_to_run); nbuffer[i] += netlink_buffer_size; if (nbuffer[i] <= netlink_buffer_maxsize) { sprintf(cmd_to_run, cmds[i], nbuffer[i]); } else { nbuffer[i] -= netlink_buffer_size; sprintf(cmd_to_run, cmds[i], nbuffer[i]); } syslog(LOG_ALERT,"RESTARTING PROCESS (Increase netlink buffer to %ld bytes)", nbuffer[i]); closelog(); start_child(cmd_to_run,i); } } } return 0; }