]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
usernsexec: Make err out vebose for unshare error 2532/head
authorTobin C. Harding <me@tobin.cc>
Wed, 15 Aug 2018 23:43:02 +0000 (09:43 +1000)
committerTobin C. Harding <me@tobin.cc>
Thu, 16 Aug 2018 06:44:12 +0000 (16:44 +1000)
Currently if lxc-usernsexec is run on a kernel without user namespaces
enabled the error message is

unshare: Invalid argument
read pipe: Success

This error message 'Invalid argument' does not point at the root cause
of the error.  We can help the user out by giving a more detailed error
message and also not using perror() if errno==0.

Improve error message by
 - Printing unshare flags
 - Printing suggested cause of failure (user namespace not enabled)
 - Print error message with fprintf() if errno==0 (EOF)

Signed-off-by: Tobin C. Harding <me@tobin.cc>
src/lxc/cmd/lxc_usernsexec.c

index c342a90a0821cbe4b938951a0f05077c9ba87f25..107668273f0beb88eda548b39bb73d9aac96d1ea 100644 (file)
@@ -375,7 +375,8 @@ int main(int argc, char *argv[])
 
                ret = unshare(flags);
                if (ret < 0) {
-                       perror("unshare");
+                       fprintf(stderr,
+                               "Failed to unshare mount and user namespace\n");
                        return 1;
                }
                buf[0] = '1';
@@ -399,9 +400,13 @@ int main(int argc, char *argv[])
 
        close(pipe_fds1[1]);
        close(pipe_fds2[0]);
-       if (lxc_read_nointr(pipe_fds1[0], buf, 1) < 1) {
+       ret = lxc_read_nointr(pipe_fds1[0], buf, 1);
+       if (ret < 0) {
                perror("read pipe");
                exit(EXIT_FAILURE);
+       } else if (ret == 0) {
+               fprintf(stderr, "Failed to read from pipe\n");
+               exit(EXIT_FAILURE);
        }
 
        buf[0] = '1';