exit: add kernel_waitid_prepare() helper
authorJens Axboe <axboe@kernel.dk>
Tue, 11 Jul 2023 16:38:23 +0000 (10:38 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 21 Sep 2023 18:03:44 +0000 (12:03 -0600)
Move the setup logic out of kernel_waitid(), and into a separate helper.

No functional changes intended in this patch.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
kernel/exit.c

index c6fba9ecca27c0b389cd1dabbc3399e87da5a2cb..817c22bd7ae0059b570d1d536cb66cf70ba3a699 100644 (file)
@@ -1662,14 +1662,13 @@ static long do_wait(struct wait_opts *wo)
        return retval;
 }
 
-static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
-                         int options, struct rusage *ru)
+static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
+                                struct waitid_info *infop, int options,
+                                struct rusage *ru)
 {
-       struct wait_opts wo;
+       unsigned int f_flags = 0;
        struct pid *pid = NULL;
        enum pid_type type;
-       long ret;
-       unsigned int f_flags = 0;
 
        if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED|
                        __WNOTHREAD|__WCLONE|__WALL))
@@ -1712,19 +1711,32 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
                return -EINVAL;
        }
 
-       wo.wo_type      = type;
-       wo.wo_pid       = pid;
-       wo.wo_flags     = options;
-       wo.wo_info      = infop;
-       wo.wo_rusage    = ru;
+       wo->wo_type     = type;
+       wo->wo_pid      = pid;
+       wo->wo_flags    = options;
+       wo->wo_info     = infop;
+       wo->wo_rusage   = ru;
        if (f_flags & O_NONBLOCK)
-               wo.wo_flags |= WNOHANG;
+               wo->wo_flags |= WNOHANG;
+
+       return 0;
+}
+
+static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
+                         int options, struct rusage *ru)
+{
+       struct wait_opts wo;
+       long ret;
+
+       ret = kernel_waitid_prepare(&wo, which, upid, infop, options, ru);
+       if (ret)
+               return ret;
 
        ret = do_wait(&wo);
-       if (!ret && !(options & WNOHANG) && (f_flags & O_NONBLOCK))
+       if (!ret && !(options & WNOHANG) && (wo.wo_flags & WNOHANG))
                ret = -EAGAIN;
 
-       put_pid(pid);
+       put_pid(wo.wo_pid);
        return ret;
 }