All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] connectors/pec_listener: Make exit_flag volatile
@ 2021-08-09 10:58 Martin Doucha
  2021-08-09 11:01 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Doucha @ 2021-08-09 10:58 UTC (permalink / raw)
  To: ltp

There are two ways in which the main loop of pec_listener can stop:
- syscall gets interrupted by signal and its error handler code breaks the loop
- or exit_flag get set to 1

The exit flag is only changed in signal handler so it needs to be volatile,
otherwise the compiler will optimize it out of the main program loop. If
an incoming signal doesn't interrupt a syscall, pec_listener will get stuck
in the loop forever. It's a rare situation but it does happen once in a while.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/connectors/pec/pec_listener.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/connectors/pec/pec_listener.c b/testcases/kernel/connectors/pec/pec_listener.c
index 7844dc905..2707ea8fb 100644
--- a/testcases/kernel/connectors/pec/pec_listener.c
+++ b/testcases/kernel/connectors/pec/pec_listener.c
@@ -50,7 +50,7 @@ int main(void)
 
 static __u32 seq;
 
-static int exit_flag;
+static volatile int exit_flag;
 static struct sigaction sigint_action;
 
 struct nlmsghdr *nlhdr;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [LTP] [PATCH] connectors/pec_listener: Make exit_flag volatile
  2021-08-09 10:58 [LTP] [PATCH] connectors/pec_listener: Make exit_flag volatile Martin Doucha
@ 2021-08-09 11:01 ` Cyril Hrubis
  0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2021-08-09 11:01 UTC (permalink / raw)
  To: ltp

Hi!
Good catch, applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-09 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-09 10:58 [LTP] [PATCH] connectors/pec_listener: Make exit_flag volatile Martin Doucha
2021-08-09 11:01 ` Cyril Hrubis

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.