* [PATCH] Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate
@ 2013-07-01 16:39 Denys Vlasenko
2013-07-02 20:01 ` Oleg Nesterov
0 siblings, 1 reply; 3+ messages in thread
From: Denys Vlasenko @ 2013-07-01 16:39 UTC (permalink / raw)
To: Oleg Nesterov, linux-kernel; +Cc: Denys Vlasenko
Grepping for numeric constants is inconvenient.
No code changes.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
---
include/linux/wait.h | 4 ++++
kernel/exit.c | 14 +++++++-------
kernel/signal.c | 6 +++---
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/include/linux/wait.h b/include/linux/wait.h
index f487a47..0e04586 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -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);
diff --git a/kernel/exit.c b/kernel/exit.c
index a949819..41effa0 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -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)
diff --git a/kernel/signal.c b/kernel/signal.c
index 50e4107..2ad0e7d 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -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;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate
2013-07-01 16:39 [PATCH] Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate Denys Vlasenko
@ 2013-07-02 20:01 ` Oleg Nesterov
2013-07-04 9:03 ` Denys Vlasenko
0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2013-07-02 20:01 UTC (permalink / raw)
To: Denys Vlasenko; +Cc: linux-kernel
On 07/01, Denys Vlasenko wrote:
>
> Grepping for numeric constants is inconvenient.
Personally I agree very much, and I like the intent.
> +#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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate
2013-07-02 20:01 ` Oleg Nesterov
@ 2013-07-04 9:03 ` Denys Vlasenko
0 siblings, 0 replies; 3+ messages in thread
From: Denys Vlasenko @ 2013-07-04 9:03 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Denys Vlasenko, Linux Kernel Mailing List
On Tue, Jul 2, 2013 at 10:01 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> On 07/01, Denys Vlasenko wrote:
>>
>> Grepping for numeric constants is inconvenient.
>
> Personally I agree very much, and I like the intent.
>
>> +#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?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-07-04 9:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-01 16:39 [PATCH] Define WTERMSIG{,_MASK} and WCOREDUMP and use where appropriate Denys Vlasenko
2013-07-02 20:01 ` Oleg Nesterov
2013-07-04 9:03 ` Denys Vlasenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.