[PATCH 4/6] slip: Use c_stdin and c_stdout in er everywhere
Ian Jackson
ijackson at chiark.greenend.org.uk
Mon Sep 22 16:45:11 BST 2014
The userv exec context er needs to contain both ends of the pipe, so
that the child can close the unused ends.
So move c_stdin and c_stdout into er, change all references to them,
and abolish er->in and er->out.
No functional change yet in this patch.
Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
slip.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/slip.c b/slip.c
index 2d45370..38b2ca8 100644
--- a/slip.c
+++ b/slip.c
@@ -250,8 +250,8 @@ static void userv_userv_callback(void *sst, pid_t pid, int status)
struct userv_entry_rec {
cstring_t path;
const char **argv;
- int in;
- int out;
+ int c_stdin[2];
+ int c_stdout[2];
/* XXX perhaps we should collect and log stderr? */
};
@@ -259,8 +259,8 @@ static void userv_entry(void *sst)
{
struct userv_entry_rec *st=sst;
- dup2(st->in,0);
- dup2(st->out,1);
+ dup2(st->c_stdin[0],0);
+ dup2(st->c_stdout[1],1);
/* XXX close all other fds */
setsid();
@@ -274,8 +274,6 @@ static void userv_entry(void *sst)
static void userv_invoke_userv(struct userv *st)
{
struct userv_entry_rec er[1];
- int c_stdin[2];
- int c_stdout[2];
string_t addrs;
string_t nets;
string_t s;
@@ -326,17 +324,15 @@ static void userv_invoke_userv(struct userv *st)
st->slip.pending_esc=False;
/* Invoke userv */
- if (pipe(c_stdin)!=0) {
+ if (pipe(er->c_stdin)!=0) {
fatal_perror("userv_invoke_userv: pipe(c_stdin)");
}
- if (pipe(c_stdout)!=0) {
+ if (pipe(er->c_stdout)!=0) {
fatal_perror("userv_invoke_userv: pipe(c_stdout)");
}
- st->txfd=c_stdin[1];
- st->rxfd=c_stdout[0];
+ st->txfd=er->c_stdin[1];
+ st->rxfd=er->c_stdout[0];
- er->in=c_stdin[0];
- er->out=c_stdout[1];
/* The arguments are:
userv
service-user
@@ -354,8 +350,8 @@ static void userv_invoke_userv(struct userv *st)
st->pid=makesubproc(userv_entry, userv_userv_callback,
er, st, st->slip.nl.name);
- close(er->in);
- close(er->out);
+ close(er->c_stdin[0]);
+ close(er->c_stdout[1]);
free(er->argv);
free(addrs);
free(nets);
--
1.7.10.4
More information about the sgo-software-discuss
mailing list