Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
c7e55a16
Commit
c7e55a16
authored
Nov 20, 2015
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pipecmd: add pipecmdarr variant.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
93bdadc1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
18 deletions
+35
-18
ccan/pipecmd/pipecmd.c
ccan/pipecmd/pipecmd.c
+27
-18
ccan/pipecmd/pipecmd.h
ccan/pipecmd/pipecmd.h
+8
-0
No files found.
ccan/pipecmd/pipecmd.c
View file @
c7e55a16
...
@@ -24,6 +24,20 @@ static char **gather_args(const char *arg0, va_list ap)
...
@@ -24,6 +24,20 @@ static char **gather_args(const char *arg0, va_list ap)
}
}
pid_t
pipecmdv
(
int
*
fd_fromchild
,
int
*
fd_tochild
,
const
char
*
cmd
,
va_list
ap
)
pid_t
pipecmdv
(
int
*
fd_fromchild
,
int
*
fd_tochild
,
const
char
*
cmd
,
va_list
ap
)
{
char
**
arr
=
gather_args
(
cmd
,
ap
);
pid_t
ret
;
if
(
!
arr
)
{
errno
=
ENOMEM
;
return
-
1
;
}
ret
=
pipecmdarr
(
fd_fromchild
,
fd_tochild
,
arr
);
free_noerr
(
arr
);
return
ret
;
}
pid_t
pipecmdarr
(
int
*
fd_fromchild
,
int
*
fd_tochild
,
char
*
const
*
arr
)
{
{
int
tochild
[
2
],
fromchild
[
2
],
execfail
[
2
];
int
tochild
[
2
],
fromchild
[
2
],
execfail
[
2
];
pid_t
childpid
;
pid_t
childpid
;
...
@@ -57,8 +71,6 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
...
@@ -57,8 +71,6 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
goto
close_execfail_fail
;
goto
close_execfail_fail
;
if
(
childpid
==
0
)
{
if
(
childpid
==
0
)
{
char
**
args
=
gather_args
(
cmd
,
ap
);
if
(
fd_tochild
)
if
(
fd_tochild
)
close
(
tochild
[
1
]);
close
(
tochild
[
1
]);
if
(
fd_fromchild
)
if
(
fd_fromchild
)
...
@@ -66,23 +78,20 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
...
@@ -66,23 +78,20 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
close
(
execfail
[
0
]);
close
(
execfail
[
0
]);
// Child runs command.
// Child runs command.
if
(
!
args
)
if
(
tochild
[
0
]
!=
STDIN_FILENO
)
{
err
=
ENOMEM
;
if
(
dup2
(
tochild
[
0
],
STDIN_FILENO
)
==
-
1
)
else
{
goto
child_errno_fail
;
if
(
tochild
[
0
]
!=
STDIN_FILENO
)
{
close
(
tochild
[
0
]);
if
(
dup2
(
tochild
[
0
],
STDIN_FILENO
)
==
-
1
)
goto
child_errno_fail
;
close
(
tochild
[
0
]);
}
if
(
fromchild
[
1
]
!=
STDOUT_FILENO
)
{
if
(
dup2
(
fromchild
[
1
],
STDOUT_FILENO
)
==
-
1
)
goto
child_errno_fail
;
close
(
fromchild
[
1
]);
}
execvp
(
cmd
,
args
);
child_errno_fail:
err
=
errno
;
}
}
if
(
fromchild
[
1
]
!=
STDOUT_FILENO
)
{
if
(
dup2
(
fromchild
[
1
],
STDOUT_FILENO
)
==
-
1
)
goto
child_errno_fail
;
close
(
fromchild
[
1
]);
}
execvp
(
arr
[
0
],
arr
);
child_errno_fail:
err
=
errno
;
write
(
execfail
[
1
],
&
err
,
sizeof
(
err
));
write
(
execfail
[
1
],
&
err
,
sizeof
(
err
));
exit
(
127
);
exit
(
127
);
}
}
...
...
ccan/pipecmd/pipecmd.h
View file @
c7e55a16
...
@@ -27,4 +27,12 @@ pid_t pipecmd(int *infd, int *outfd, const char *cmd, ...);
...
@@ -27,4 +27,12 @@ pid_t pipecmd(int *infd, int *outfd, const char *cmd, ...);
* @ap: argument list for arguments.
* @ap: argument list for arguments.
*/
*/
pid_t
pipecmdv
(
int
*
infd
,
int
*
outfd
,
const
char
*
cmd
,
va_list
ap
);
pid_t
pipecmdv
(
int
*
infd
,
int
*
outfd
,
const
char
*
cmd
,
va_list
ap
);
/**
* pipecmdarr - run a command, optionally connect pipes (char arry version)
* @infd: input fd to write to child (if non-NULL)
* @outfd: output fd to read from child (if non-NULL)
* @arr: NULL-terminated array for arguments (first is program to run).
*/
pid_t
pipecmdarr
(
int
*
infd
,
int
*
outfd
,
char
*
const
*
arr
);
#endif
/* CCAN_PIPECMD_H */
#endif
/* CCAN_PIPECMD_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment