]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
bindings: cleanup send_creds_clone_wrapper()
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 2 Mar 2020 09:00:32 +0000 (10:00 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 3 Mar 2020 14:01:18 +0000 (15:01 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
bindings.c
macro.h

index 128a504a8cd31aa4da163a6c266bcc3740fbabd4..9adc60d6177f7723a0c8590030356bf0551b197f 100644 (file)
@@ -301,18 +301,15 @@ static struct pidns_init_store *lookup_verify_initpid(struct stat *sb)
 
 static int send_creds_clone_wrapper(void *arg)
 {
-       struct ucred cred;
-       char v;
-       int sock = *(int *)arg;
-
-       /* we are the child */
-       cred.uid = 0;
-       cred.gid = 0;
-       cred.pid = 1;
-       v = '1';
-       if (send_creds(sock, &cred, v, true) != SEND_CREDS_OK)
-               return 1;
-       return 0;
+       int sock = PTR_TO_INT(arg);
+       char v = '1'; /* we are the child */
+       struct ucred cred = {
+           .uid = 0,
+           .gid = 0,
+           .pid = 1,
+       };
+
+       return send_creds(sock, &cred, v, true) != SEND_CREDS_OK;
 }
 
 /*
@@ -365,7 +362,7 @@ static void write_task_init_pid_exit(int sock, pid_t target)
        if (setns(fd, 0))
                log_exit("Failed to setns to pid namespace of process %d", target);
 
-       pid = lxcfs_clone(send_creds_clone_wrapper, &sock, 0);
+       pid = lxcfs_clone(send_creds_clone_wrapper, INT_TO_PTR(sock), 0);
        if (pid < 0)
                _exit(EXIT_FAILURE);
 
diff --git a/macro.h b/macro.h
index b4277cbf9039ddbb5aeb68971255524794dafede..b8edf0b80b39c1715afeb6b6bda1f3b76e4c5142 100644 (file)
--- a/macro.h
+++ b/macro.h
@@ -95,6 +95,8 @@
                _exit(EXIT_FAILURE);                    \
        })
 
+#define PTR_TO_INT(p) ((int)((intptr_t)(p)))
+#define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
 #define PTR_TO_UINT64(p) ((uint64_t)((intptr_t)(p)))
 #define INTTYPE_TO_PTR(u) ((void *)((intptr_t)(u)))