mips: rename offsets.c to asm-offsets.c
[linux-2.6/verdex.git] / arch / um / drivers / slirp_user.c
blob8d91f663d82c684267567f2489f8059b738590e8
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 "helper.h"
17 #include "os.h"
19 void slirp_user_init(void *data, void *dev)
21 struct slirp_data *pri = data;
23 pri->dev = dev;
26 struct slirp_pre_exec_data {
27 int stdin;
28 int stdout;
31 static void slirp_pre_exec(void *arg)
33 struct slirp_pre_exec_data *data = arg;
35 if(data->stdin != -1) dup2(data->stdin, 0);
36 if(data->stdout != -1) dup2(data->stdout, 1);
39 static int slirp_tramp(char **argv, int fd)
41 struct slirp_pre_exec_data pe_data;
42 int pid;
44 pe_data.stdin = fd;
45 pe_data.stdout = fd;
46 pid = run_helper(slirp_pre_exec, &pe_data, argv, NULL);
48 return(pid);
51 static int slirp_open(void *data)
53 struct slirp_data *pri = data;
54 int fds[2], pid, err;
56 err = os_pipe(fds, 1, 1);
57 if(err)
58 return(err);
60 err = slirp_tramp(pri->argw.argv, fds[1]);
61 if(err < 0){
62 printk("slirp_tramp failed - errno = %d\n", -err);
63 goto out;
65 pid = err;
67 pri->slave = fds[1];
68 pri->slip.pos = 0;
69 pri->slip.esc = 0;
70 pri->pid = err;
72 return(fds[0]);
73 out:
74 os_close_file(fds[0]);
75 os_close_file(fds[1]);
76 return err;
79 static void slirp_close(int fd, void *data)
81 struct slirp_data *pri = data;
82 int status,err;
84 os_close_file(fd);
85 os_close_file(pri->slave);
87 pri->slave = -1;
89 if(pri->pid<1) {
90 printk("slirp_close: no child process to shut down\n");
91 return;
94 #if 0
95 if(kill(pri->pid, SIGHUP)<0) {
96 printk("slirp_close: sending hangup to %d failed (%d)\n",
97 pri->pid, errno);
99 #endif
101 CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG));
102 if(err < 0) {
103 printk("slirp_close: waitpid returned %d\n", errno);
104 return;
107 if(err == 0) {
108 printk("slirp_close: process %d has not exited\n");
109 return;
112 pri->pid = -1;
115 int slirp_user_read(int fd, void *buf, int len, struct slirp_data *pri)
117 return slip_proto_read(fd, buf, len, &pri->slip);
120 int slirp_user_write(int fd, void *buf, int len, struct slirp_data *pri)
122 return slip_proto_write(fd, buf, len, &pri->slip);
125 static int slirp_set_mtu(int mtu, void *data)
127 return(mtu);
130 struct net_user_info slirp_user_info = {
131 .init = slirp_user_init,
132 .open = slirp_open,
133 .close = slirp_close,
134 .remove = NULL,
135 .set_mtu = slirp_set_mtu,
136 .add_address = NULL,
137 .delete_address = NULL,
138 .max_packet = BUF_SIZE