From: Christian Brauner Date: Sat, 26 Aug 2017 21:04:01 +0000 (+0200) Subject: conf: adapt to lxc-user-nic usage X-Git-Tag: lxc-2.0.9~49^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=859d1a2860a524309fde8f07c0d52d0ec1987ebf;p=thirdparty%2Flxc.git conf: adapt to lxc-user-nic usage - 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 --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 0105eaec0..c8a05b43c 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3170,8 +3170,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", @@ -3201,6 +3201,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."); @@ -3244,7 +3246,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; } diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c index c0f9eea69..b462053fc 100644 --- a/src/lxc/lxc_user_nic.c +++ b/src/lxc/lxc_user_nic.c @@ -944,7 +944,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;