Skip to content

Commit

Permalink
conf: adapt to lxc-user-nic usage
Browse files Browse the repository at this point in the history
- lxc-user-nic gains the subcommands {create,delete}
- dup2() STDERR_FILENO as well so that we can show helpful messages in our logs
  on failure
- initialize output buffer so that we don't print garbage

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Aug 27, 2017
1 parent f703d99 commit 25aead3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/lxc/conf.c
Expand Up @@ -3277,8 +3277,8 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
pid_t child;
int bytes, pipefd[2];
char *token, *saveptr = NULL;
char buffer[MAX_BUFFER_SIZE];
char netdev_link[IFNAMSIZ + 1];
char buffer[MAX_BUFFER_SIZE] = {0};

if (netdev->type != LXC_NET_VETH) {
ERROR("nic type %d not support for unprivileged use",
Expand Down Expand Up @@ -3308,6 +3308,8 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,

/* Redirect stdout to write-end of the pipe. */
ret = dup2(pipefd[1], STDOUT_FILENO);
if (ret >= 0)
ret = dup2(pipefd[1], STDERR_FILENO);
close(pipefd[1]); /* Close the write-end of the pipe. */
if (ret < 0) {
SYSERROR("Failed to dup2() to redirect stdout to pipe file descriptor.");
Expand Down Expand Up @@ -3351,7 +3353,8 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
buffer[bytes - 1] = '\0';

if (wait_for_pid(child) != 0) {
TRACE("lxc-user-nic failed to configure requested network");
ERROR("lxc-user-nic failed to configure requested network: %s",
buffer[0] != '\0' ? buffer : "(null)");
close(pipefd[0]);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/lxc_user_nic.c
Expand Up @@ -940,7 +940,7 @@ int main(int argc, char *argv[])
{
int fd, n, pid, ret;
char *me;
char *cnic = NULL, *nicname = NULL, *vethname = NULL;
char *cnic = NULL, *nicname = NULL;
struct alloted_s *alloted = NULL;
struct user_nic_args args;

Expand Down

0 comments on commit 25aead3

Please sign in to comment.