chiark / gitweb /
fds: Introduce pipe_cloexec()
[secnet.git] / slip.c
diff --git a/slip.c b/slip.c
index aed2551de70d2d695ec1ef99e04081923227dabf..7d060c371881cfeb8c9e28ac78fe0c0476bc2a9c 100644 (file)
--- a/slip.c
+++ b/slip.c
@@ -27,7 +27,6 @@ struct slip {
     bool_t ignoring_packet; /* If this packet was corrupt or overlong,
                               we ignore everything up to the next END */
     netlink_deliver_fn *netlink_to_tunnel;
-    uint32_t local_address;
 };
 
 /* Generic SLIP mangling code */
@@ -128,7 +127,7 @@ static void slip_unstuff(struct slip *st, uint8_t *buf, uint32_t l)
                }
                st->buff->size=0;
            } else if (outputchr != OUTPUT_NOTHING) {
-               if (st->buff->size < st->buff->len) {
+               if (buf_remaining_space(st->buff)) {
                    buf_append_uint8(st->buff,outputchr);
                } else {
                    Message(M_WARNING, "userv_afterpoll: dropping overlong"
@@ -147,8 +146,6 @@ static void slip_init(struct slip *st, struct cloc loc, dict_t *dict,
        netlink_init(&st->nl,st,loc,dict,
                     "netlink-userv-ipif",NULL,to_host);
     st->buff=find_cl_if(dict,"buffer",CL_BUFFER,True,"name",loc);
-    st->local_address=string_item_to_ipaddr(
-       dict_find_item(dict,"local-address", True, name, loc),"netlink");
     BUF_ALLOC(st->buff,"slip_init");
     st->pending_esc=False;
     st->ignoring_packet=False;
@@ -265,7 +262,6 @@ static void userv_entry(void *sst)
     dup2(st->in,0);
     dup2(st->out,1);
 
-    /* XXX close all other fds */
     setsid();
     /* XXX We really should strdup() all of argv[] but because we'll just
        exit anyway if execvp() fails it doesn't seem worth bothering. */
@@ -297,7 +293,7 @@ static void userv_invoke_userv(struct userv *st)
 
     addrs=safe_malloc(512,"userv_invoke_userv:addrs");
     snprintf(addrs,512,"%s,%s,%d,slip",
-            ipaddr_to_string(st->slip.local_address),
+            ipaddr_to_string(st->slip.nl.local_address),
             ipaddr_to_string(st->slip.nl.secnet_address),st->slip.nl.mtu);
 
     allnets=ipset_new();
@@ -329,12 +325,8 @@ static void userv_invoke_userv(struct userv *st)
     st->slip.pending_esc=False;
 
     /* Invoke userv */
-    if (pipe(c_stdin)!=0) {
-       fatal_perror("userv_invoke_userv: pipe(c_stdin)");
-    }
-    if (pipe(c_stdout)!=0) {
-       fatal_perror("userv_invoke_userv: pipe(c_stdout)");
-    }
+    pipe_cloexec(c_stdin);
+    pipe_cloexec(c_stdout);
     st->txfd=c_stdin[1];
     st->rxfd=c_stdout[0];