]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: adapt to lxc-user-nic usage
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 26 Aug 2017 21:04:01 +0000 (23:04 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 29 Aug 2017 20:54:49 +0000 (22:54 +0200)
- 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>
src/lxc/conf.c
src/lxc/lxc_user_nic.c

index 0105eaec02b91ddc9f09a46d70df48859b886b6b..c8a05b43cfc646fe9a0aabb35a3345b67db4c1c1 100644 (file)
@@ -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;
        }
index c0f9eea697b8d547b525685b9ed8004706424478..b462053fc033d32f536f38173db8a1250c203749 100644 (file)
@@ -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;