static int change_tramp(char **argv, char *output, int output_len) { int pid, fds[2], err; struct change_pre_exec_data pe_data; err = os_pipe(fds, 1, 0); if (err < 0) { printk(UM_KERN_ERR "change_tramp - pipe failed, err = %d\n", -err); return err; } pe_data.close_me = fds[0]; pe_data.stdout = fds[1]; pid = run_helper(change_pre_exec, &pe_data, argv); if (pid > 0) /* Avoid hang as we won't get data in failure case. */ read_output(fds[0], output, output_len); close(fds[0]); close(fds[1]); if (pid > 0) helper_wait(pid); return pid; }
static void slirp_close(int fd, void *data) { struct slirp_data *pri = data; int err; close(fd); close(pri->slave); pri->slave = -1; if (pri->pid<1) { printk(UM_KERN_ERR "slirp_close: no child process to shut " "down\n"); return; } #if 0 if (kill(pri->pid, SIGHUP)<0) { printk(UM_KERN_ERR "slirp_close: sending hangup to %d failed " "(%d)\n", pri->pid, errno); } #endif err = helper_wait(pri->pid); if (err < 0) return; pri->pid = -1; }
static int slip_tramp(char **argv, int fd) { struct slip_pre_exec_data pe_data; char *output; int pid, fds[2], err, output_len; err = os_pipe(fds, 1, 0); if (err < 0) { printk(UM_KERN_ERR "slip_tramp : pipe failed, err = %d\n", -err); goto out; } err = 0; pe_data.stdin = fd; pe_data.stdout = fds[1]; pe_data.close_me = fds[0]; err = run_helper(slip_pre_exec, &pe_data, argv); if (err < 0) goto out_close; pid = err; output_len = UM_KERN_PAGE_SIZE; output = kmalloc(output_len, UM_GFP_KERNEL); if (output == NULL) { printk(UM_KERN_ERR "slip_tramp : failed to allocate output " "buffer\n"); os_kill_process(pid, 1); err = -ENOMEM; goto out_free; } close(fds[1]); read_output(fds[0], output, output_len); printk("%s", output); err = helper_wait(pid, 0, argv[0]); close(fds[0]); out_free: kfree(output); return err; out_close: close(fds[0]); close(fds[1]); out: return err; }
static int etap_tramp(char *dev, char *gate, int control_me, int control_remote, int data_me, int data_remote) { struct etap_pre_exec_data pe_data; int pid, err, n; char version_buf[sizeof("nnnnn\0")]; char data_fd_buf[sizeof("nnnnnn\0")]; char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; char *setup_args[] = { "uml_net", version_buf, "ethertap", dev, data_fd_buf, gate_buf, NULL }; char *nosetup_args[] = { "uml_net", version_buf, "ethertap", dev, data_fd_buf, NULL }; char **args, c; sprintf(data_fd_buf, "%d", data_remote); sprintf(version_buf, "%d", UML_NET_VERSION); if (gate != NULL) { strcpy(gate_buf, gate); args = setup_args; } else args = nosetup_args; err = 0; pe_data.control_remote = control_remote; pe_data.control_me = control_me; pe_data.data_me = data_me; pid = run_helper(etap_pre_exec, &pe_data, args); if (pid < 0) err = pid; close(data_remote); close(control_remote); CATCH_EINTR(n = read(control_me, &c, sizeof(c))); if (n != sizeof(c)) { err = -errno; printk(UM_KERN_ERR "etap_tramp : read of status failed, " "err = %d\n", -err); return err; } if (c != 1) { printk(UM_KERN_ERR "etap_tramp : uml_net failed\n"); err = helper_wait(pid); } return err; }
static void slirp_close(int fd, void *data) { struct slirp_data *pri = data; int err; close(fd); close(pri->slave); pri->slave = -1; if (pri->pid<1) { printk(UM_KERN_ERR "slirp_close: no child process to shut " "down\n"); return; } err = helper_wait(pri->pid); if (err < 0) return; pri->pid = -1; }
int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock) { struct dog_data data; int in_fds[2], out_fds[2], pid, n, err; char pid_buf[sizeof("nnnnn\0")], c; char *pid_args[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf, NULL }; char *mconsole_args[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL, NULL }; char **args = NULL; err = os_pipe(in_fds, 1, 0); if (err < 0) { printk("harddog_open - os_pipe failed, err = %d\n", -err); goto out; } err = os_pipe(out_fds, 1, 0); if (err < 0) { printk("harddog_open - os_pipe failed, err = %d\n", -err); goto out_close_in; } data.stdin = out_fds[0]; data.stdout = in_fds[1]; data.close_me[0] = out_fds[1]; data.close_me[1] = in_fds[0]; if (sock != NULL) { mconsole_args[2] = sock; args = mconsole_args; } else { /* XXX The os_getpid() is not SMP correct */ sprintf(pid_buf, "%d", os_getpid()); args = pid_args; } pid = run_helper(pre_exec, &data, args); close(out_fds[0]); close(in_fds[1]); if (pid < 0) { err = -pid; printk("harddog_open - run_helper failed, errno = %d\n", -err); goto out_close_out; } n = read(in_fds[0], &c, sizeof(c)); if (n == 0) { printk("harddog_open - EOF on watchdog pipe\n"); helper_wait(pid); err = -EIO; goto out_close_out; } else if (n < 0) { printk("harddog_open - read of watchdog pipe failed, " "err = %d\n", errno); helper_wait(pid); err = n; goto out_close_out; } *in_fd_ret = in_fds[0]; *out_fd_ret = out_fds[1]; return 0; out_close_in: close(in_fds[0]); close(in_fds[1]); out_close_out: close(out_fds[0]); close(out_fds[1]); out: return err; }