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
Show 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)
}
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
];
pid_t
childpid
;
...
...
@@ -57,8 +71,6 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
goto
close_execfail_fail
;
if
(
childpid
==
0
)
{
char
**
args
=
gather_args
(
cmd
,
ap
);
if
(
fd_tochild
)
close
(
tochild
[
1
]);
if
(
fd_fromchild
)
...
...
@@ -66,9 +78,6 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
close
(
execfail
[
0
]);
// Child runs command.
if
(
!
args
)
err
=
ENOMEM
;
else
{
if
(
tochild
[
0
]
!=
STDIN_FILENO
)
{
if
(
dup2
(
tochild
[
0
],
STDIN_FILENO
)
==
-
1
)
goto
child_errno_fail
;
...
...
@@ -79,10 +88,10 @@ pid_t pipecmdv(int *fd_fromchild, int *fd_tochild, const char *cmd, va_list ap)
goto
child_errno_fail
;
close
(
fromchild
[
1
]);
}
execvp
(
cmd
,
args
);
execvp
(
arr
[
0
],
arr
);
child_errno_fail:
err
=
errno
;
}
write
(
execfail
[
1
],
&
err
,
sizeof
(
err
));
exit
(
127
);
}
...
...
ccan/pipecmd/pipecmd.h
View file @
c7e55a16
...
...
@@ -27,4 +27,12 @@ pid_t pipecmd(int *infd, int *outfd, const char *cmd, ...);
* @ap: argument list for arguments.
*/
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 */
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