Skip to content

Commit d83c8b4

Browse files
axboeopsiff
authored andcommitted
exit: add kernel_waitid_prepare() helper
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> (cherry picked from commit eda7e9d) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent e944624 commit d83c8b4

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

kernel/exit.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,14 +1671,13 @@ static long do_wait(struct wait_opts *wo)
16711671
return retval;
16721672
}
16731673

1674-
static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
1675-
int options, struct rusage *ru)
1674+
static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid,
1675+
struct waitid_info *infop, int options,
1676+
struct rusage *ru)
16761677
{
1677-
struct wait_opts wo;
1678+
unsigned int f_flags = 0;
16781679
struct pid *pid = NULL;
16791680
enum pid_type type;
1680-
long ret;
1681-
unsigned int f_flags = 0;
16821681

16831682
if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED|
16841683
__WNOTHREAD|__WCLONE|__WALL))
@@ -1721,19 +1720,32 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
17211720
return -EINVAL;
17221721
}
17231722

1724-
wo.wo_type = type;
1725-
wo.wo_pid = pid;
1726-
wo.wo_flags = options;
1727-
wo.wo_info = infop;
1728-
wo.wo_rusage = ru;
1723+
wo->wo_type = type;
1724+
wo->wo_pid = pid;
1725+
wo->wo_flags = options;
1726+
wo->wo_info = infop;
1727+
wo->wo_rusage = ru;
17291728
if (f_flags & O_NONBLOCK)
1730-
wo.wo_flags |= WNOHANG;
1729+
wo->wo_flags |= WNOHANG;
1730+
1731+
return 0;
1732+
}
1733+
1734+
static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
1735+
int options, struct rusage *ru)
1736+
{
1737+
struct wait_opts wo;
1738+
long ret;
1739+
1740+
ret = kernel_waitid_prepare(&wo, which, upid, infop, options, ru);
1741+
if (ret)
1742+
return ret;
17311743

17321744
ret = do_wait(&wo);
1733-
if (!ret && !(options & WNOHANG) && (f_flags & O_NONBLOCK))
1745+
if (!ret && !(options & WNOHANG) && (wo.wo_flags & WNOHANG))
17341746
ret = -EAGAIN;
17351747

1736-
put_pid(pid);
1748+
put_pid(wo.wo_pid);
17371749
return ret;
17381750
}
17391751

0 commit comments

Comments
 (0)