Skip to contentSkip to conversation

ivshmem-server: Terminate also on SIGINT

PATCH Applied Jan Kiszka 6 participants 7 messages Aug 3, 2019 – Nov 12, 2019

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH v2 1/1 ivshmem-server: Terminate also on SIGINT

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

 contrib/ivshmem-server/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +3 -2
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
     sa_quit.sa_handler = ivshmem_server_quit_cb;
     sa_quit.sa_flags = 0;
     if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
         goto err;
     }
 

--
2.16.4

Reviewed-by on v2 1/1
#1 lore raw
Quoted 30 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

 contrib/ivshmem-server/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +3 -3
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
     sa_quit.sa_handler = ivshmem_server_quit_cb;
     sa_quit.sa_flags = 0;
     if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
         goto err;
     }
 
--
Quoted 3 lines

2.16.4

Reviewed-by on v2 1/1
#2 lore raw
In reply to Jan Kiszka
Quoted 18 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

 contrib/ivshmem-server/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +0 -0
index 197c79c57e..e4cd35f74c 100644

contrib/ivshmem-server/main.c main(int argc, char *argv[]) · line 230

Quoted 10 lines
contrib/ivshmem-server/main.c +3 -2
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
     sa_quit.sa_handler = ivshmem_server_quit_cb;
     sa_quit.sa_flags = 0;
     if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
         goto err;
     }

Not related with this patch, but since I was looking at the code, I noticed the 'ivshmem_server_quit' variable, set in the signal handler, is not volatile.
Should we define it volatile to avoid possible compiler optimizations?

Thanks,
Stefano

author
#3 lore raw
Quoted 23 lines · Stefano Garzarella
Quoted 22 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

 contrib/ivshmem-server/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +0 -1
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
     sa_quit.sa_handler = ivshmem_server_quit_cb;
     sa_quit.sa_flags = 0;
     if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
Quoted 8 lines

contrib/ivshmem-server/main.c main(int argc, char *argv[]) · line 230

Quoted 6 lines
contrib/ivshmem-server/main.c +3 -1
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
         goto err;
     }

Thanks.

Quoted 5 lines

Not related with this patch, but since I was looking at the code, I noticed the 'ivshmem_server_quit' variable, set in the signal handler, is not volatile.
Should we define it volatile to avoid possible compiler optimizations?

Yes, would be better.

I'm sure there is more, possibly also on the current device model side. I only started to dig through it while implementing a new revision of the protocol on top and aside of it.

Jan

#4 lore raw
In reply to Jan Kiszka
Quoted 30 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

  contrib/ivshmem-server/main.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +3 -3
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
      sa_quit.sa_handler = ivshmem_server_quit_cb;
      sa_quit.sa_flags = 0;
      if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
          goto err;
      }
 
--
Quoted 3 lines

2.16.4

...and this one for you as well, Markus?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

  contrib/ivshmem-server/main.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +3 -2
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
      sa_quit.sa_handler = ivshmem_server_quit_cb;
      sa_quit.sa_flags = 0;
      if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
          goto err;
      }
 
Quoted 6 lines
Quoted 4 lines

--
2.16.4

...and this one for you as well, Markus?

Cc qemu-trivial
#6 lore raw

Le 08/11/2019 à 16:15, Markus Armbruster a écrit :

Quoted 32 lines
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Allows to shutdown a foreground session via ctrl-c.

---

Changes in v2:
- adjust error message

  contrib/ivshmem-server/main.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
contrib/ivshmem-server/main.c +3 -2
index 197c79c57e..e4cd35f74c 100644
@@ -223,8 +223,9 @@ main(int argc, char *argv[])
      sa_quit.sa_handler = ivshmem_server_quit_cb;
      sa_quit.sa_flags = 0;
      if (sigemptyset(&sa_quit.sa_mask) == -1 ||
-        sigaction(SIGTERM, &sa_quit, 0) == -1) {
-        perror("failed to add SIGTERM handler; sigaction");
+        sigaction(SIGTERM, &sa_quit, 0) == -1 ||
+        sigaction(SIGINT, &sa_quit, 0) == -1) {
+        perror("failed to add signal handler; sigaction");
          goto err;
      }
 
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

--
2.16.4

...and this one for you as well, Markus?

Cc qemu-trivial

Applied to my trivial-patches branch.

Thanks,
Laurent