Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate
PATCH 1/1 Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate
Grepping for numeric constants is inconvenient.
No code changes.
--- include/linux/wait.h | 4 ++++ kernel/exit.c | 14 +++++++------- kernel/signal.c | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-)
include/linux/wait.h +4 -0
@@ -8,6 +8,10 @@#include <asm/current.h> #include <uapi/linux/wait.h> +#define WTERMSIG_MASK 0x7f +#define WTERMSIG (status) ((status) & WTERMSIG_MASK) +#define WCOREDUMP (status) ((status) & 0x80) +typedef struct __wait_queue wait_queue_t ;typedef int (*wait_queue_func_t )(wait_queue_t *wait,unsigned mode,int flags,void *key);int default_wake_function (wait_queue_t *wait,unsigned mode,int flags,void *key);
kernel/exit.c +7 -7
@@ -899,7 +899,7 @@ do_group_exit(int exit_code) {struct signal_struct *sig = current->signal; -BUG_ON (exit_code &0x80 );/* core dumps don't get here */ +BUG_ON (WCOREDUMP (exit_code));/* core dumps don't get here */ if (signal_group_exit (sig)) exit_code = sig->group_exit_code;
@@ -1027,12 +1027,12 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)get_task_struct (p);read_unlock (&tasklist_lock); -if ((exit_code &0x7f ) ==0 ) { +if (!WTERMSIG (exit_code)) { why =CLD_EXITED ; status = exit_code >>8 ; }else { - why = (exit_code &0x80 ) ?CLD_DUMPED :CLD_KILLED ; - status = exit_code &0x7f ; + why =WCOREDUMP (exit_code) ?CLD_DUMPED :CLD_KILLED ; + status =WTERMSIG (exit_code); }return wait_noreap_copyout (wo, p, pid, uid, why, status); }
@@ -1127,12 +1127,12 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)if (!retval && infop) {int why; -if ((status &0x7f ) ==0 ) { +if ((status &WTERMSIG_MASK ) ==0 ) { why =CLD_EXITED ; status >>=8 ; }else { - why = (status &0x80 ) ?CLD_DUMPED :CLD_KILLED ; - status &=0x7f ; + why =WCOREDUMP (status) ?CLD_DUMPED :CLD_KILLED ; + status &=WTERMSIG_MASK ; } retval =put_user ((short )why, &infop->si_code);if (!retval)
kernel/signal.c +3 -3
@@ -1679,10 +1679,10 @@ bool do_notify_parent(struct task_struct *tsk, int sig) info.si_utime =cputime_to_clock_t (utime + tsk->signal->utime); info.si_stime =cputime_to_clock_t (stime + tsk->signal->stime); - info.si_status = tsk->exit_code &0x7f ; -if (tsk->exit_code &0x80 ) + info.si_status =WTERMSIG (tsk->exit_code); +if (WCOREDUMP (tsk->exit_code)) info.si_code =CLD_DUMPED ; -else if (tsk->exit_code &0x7f ) +else if (WTERMSIG (tsk->exit_code)) info.si_code =CLD_KILLED ;else { info.si_code =CLD_EXITED ;
Signature · 1 line
1.8.1.4
Quoted 2 lines · Denys Vlasenko
Grepping for numeric constants is inconvenient.
Personally I agree very much, and I like the intent.
include/linux/wait.h line 13
Quoted 3 lines
include/linux/wait.h +3
-0+#define WTERMSIG_MASK 0x7f +#define WTERMSIG (status) ((status) & WTERMSIG_MASK) +#define WCOREDUMP (status) ((status) & 0x80)
But I am not sure we need WTERMSIG/WCOREDUMP helpers, although I won't really argue.
OTOH, I think it would be nice to add the name for 0x80 and change coredump_finish().
And if we do not add WTERMSIG(), then perhaps we can turn other 0x7f's into WTERMSIG_MASK?
Oleg.
Quoted 4 lines · Oleg Nesterov
Quoted 2 lines · Denys Vlasenko
Grepping for numeric constants is inconvenient.
Quoted 8 lines
Personally I agree very much, and I like the intent.
include/linux/wait.h line 13
Quoted 3 lines
include/linux/wait.h +3
-0+#define WTERMSIG_MASK 0x7f +#define WTERMSIG (status) ((status) & WTERMSIG_MASK) +#define WCOREDUMP (status) ((status) & 0x80)But I am not sure we need WTERMSIG/WCOREDUMP helpers, although I won't really argue.
Are you saying that you prefer just mask constants, do not want macros?