BUG_ON() Conversion in kernel/signal.c
[linux/fpc-iii.git] / arch / um / drivers / slirp_user.c
blobb94c66114bc85d7a56fe4d9f6d29d4d31a633c13
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <stddef.h>
5 #include <sched.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <sys/wait.h>
9 #include <sys/signal.h>
10 #include "user_util.h"
11 #include "kern_util.h"
12 #include "user.h"
13 #include "net_user.h"
14 #include "slirp.h"
15 #include "slip_common.h"
16 #include "os.h"
18 void slirp_user_init(void *data, void *dev)
20 struct slirp_data *pri = data;
22 pri->dev = dev;
25 struct slirp_pre_exec_data {
26 int stdin;
27 int stdout;
30 static void slirp_pre_exec(void *arg)
32 struct slirp_pre_exec_data *data = arg;
34 if(data->stdin != -1) dup2(data->stdin, 0);
35 if(data->stdout != -1) dup2(data->stdout, 1);
38 static int slirp_tramp(char **argv, int fd)
40 struct slirp_pre_exec_data pe_data;
41 int pid;
43 pe_data.stdin = fd;
44 pe_data.stdout = fd;
45 pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL);
47 return(pid);
50 static int slirp_open(void *data)
52 struct slirp_data *pri = data;
53 int fds[2], pid, err;
55 err = os_pipe(fds, 1, 1);
56 if(err)
57 return(err);
59 err = slirp_tramp(pri->argw.argv, fds[1]);
60 if(err < 0){
61 printk("slirp_tramp failed - errno = %d\n", -err);
62 goto out;
64 pid = err;
66 pri->slave = fds[1];
67 pri->slip.pos = 0;
68 pri->slip.esc = 0;
69 pri->pid = err;
71 return(fds[0]);
72 out:
73 os_close_file(fds[0]);
74 os_close_file(fds[1]);
75 return err;
78 static void slirp_close(int fd, void *data)
80 struct slirp_data *pri = data;
81 int status,err;
83 os_close_file(fd);
84 os_close_file(pri->slave);
86 pri->slave = -1;
88 if(pri->pid<1) {
89 printk("slirp_close: no child process to shut down\n");
90 return;
93 #if 0
94 if(kill(pri->pid, SIGHUP)<0) {
95 printk("slirp_close: sending hangup to %d failed (%d)\n",
96 pri->pid, errno);
98 #endif
100 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
101 if(err < 0) {
102 printk("slirp_close: waitpid returned %d\n", errno);
103 return;
106 if(err == 0) {
107 printk("slirp_close: process %d has not exited\n");
108 return;
111 pri->pid = -1;
114 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
116 return slip_proto_read(fd, buf, len, &pri->slip);
119 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
121 return slip_proto_write(fd, buf, len, &pri->slip);
124 static int slirp_set_mtu(int mtu, void *data)
126 return(mtu);
129 struct net_user_info slirp_user_info = {
130 .init = slirp_user_init,
131 .open = slirp_open,
132 .close = slirp_close,
133 .remove = NULL,
134 .set_mtu = slirp_set_mtu,
135 .add_address = NULL,
136 .delete_address = NULL,
137 .max_packet = BUF_SIZE