Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
a9849a06
Commit
a9849a06
authored
Jun 01, 2017
by
Serge Hallyn
Committed by
GitHub
Jun 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1592 from brauner/2017-05-28/idmap_handling
idmap improvements
parents
ca3592eb
f4f52cb5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
conf.c
src/lxc/conf.c
+0
-0
utils.c
src/lxc/utils.c
+62
-0
utils.h
src/lxc/utils.h
+14
-0
No files found.
src/lxc/conf.c
View file @
a9849a06
This diff is collapsed.
Click to expand it.
src/lxc/utils.c
View file @
a9849a06
...
@@ -2269,3 +2269,65 @@ pop_stack:
...
@@ -2269,3 +2269,65 @@ pop_stack:
return
umounts
;
return
umounts
;
}
}
int
run_command
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
)
{
pid_t
child
;
int
ret
,
fret
,
pipefd
[
2
];
ssize_t
bytes
;
/* Make sure our callers do not receive unitialized memory. */
if
(
buf_size
>
0
&&
buf
)
buf
[
0
]
=
'\0'
;
if
(
pipe
(
pipefd
)
<
0
)
{
SYSERROR
(
"failed to create pipe"
);
return
-
1
;
}
child
=
fork
();
if
(
child
<
0
)
{
close
(
pipefd
[
0
]);
close
(
pipefd
[
1
]);
SYSERROR
(
"failed to create new process"
);
return
-
1
;
}
if
(
child
==
0
)
{
/* Close the read-end of the pipe. */
close
(
pipefd
[
0
]);
/* Redirect std{err,out} to write-end of the
* pipe.
*/
ret
=
dup2
(
pipefd
[
1
],
STDOUT_FILENO
);
if
(
ret
>=
0
)
ret
=
dup2
(
pipefd
[
1
],
STDERR_FILENO
);
/* Close the write-end of the pipe. */
close
(
pipefd
[
1
]);
if
(
ret
<
0
)
{
SYSERROR
(
"failed to duplicate std{err,out} file descriptor"
);
exit
(
EXIT_FAILURE
);
}
/* Does not return. */
child_fn
(
args
);
ERROR
(
"failed to exec command"
);
exit
(
EXIT_FAILURE
);
}
/* close the write-end of the pipe */
close
(
pipefd
[
1
]);
bytes
=
read
(
pipefd
[
0
],
buf
,
(
buf_size
>
0
)
?
(
buf_size
-
1
)
:
0
);
if
(
bytes
>
0
)
buf
[
bytes
-
1
]
=
'\0'
;
fret
=
wait_for_pid
(
child
);
/* close the read-end of the pipe */
close
(
pipefd
[
0
]);
return
fret
;
}
src/lxc/utils.h
View file @
a9849a06
...
@@ -356,4 +356,18 @@ int lxc_prepare_loop_dev(const char *source, char *loop_dev, int flags);
...
@@ -356,4 +356,18 @@ int lxc_prepare_loop_dev(const char *source, char *loop_dev, int flags);
*/
*/
int
lxc_unstack_mountpoint
(
const
char
*
path
,
bool
lazy
);
int
lxc_unstack_mountpoint
(
const
char
*
path
,
bool
lazy
);
/*
* run_command runs a command and collect it's std{err,out} output in buf.
*
* @param[out] buf The buffer where the commands std{err,out] output will be
* read into. If no output was produced, buf will be memset
* to 0.
* @param[in] buf_size The size of buf. This function will reserve one byte for
* \0-termination.
* @param[in] child_fn The function to be run in the child process. This
* function must exec.
* @param[in] args Arguments to be passed to child_fn.
*/
int
run_command
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_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