Skip to contentSkip to conversation

qemu-ga: Remove unreachable code after g_error

PATCH Applied Stefan Weil 3 participants 5 messages Sep 1, 2012 – Sep 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-ga: Remove unreachable code after g_error

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
 qemu-ga.c |    2 --
 1 file changed, 2 deletions(-)
qemu-ga.c +0 -2
index 7623079..b747470 100644
@@ -114,12 +114,10 @@ static gboolean register_signal_handlers(void)
     ret = sigaction(SIGINT, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;
     }
     ret = sigaction(SIGTERM, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;
     }
 
     return true;
Signature · 1 line
1.7.10
#1 lore raw
Quoted 16 lines · On Sat, 1 Sep 2012 09:34:15 +0200 Stefan Weil <[email protected]> wrote:

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
 qemu-ga.c |    2 --
 1 file changed, 2 deletions(-)
qemu-ga.c +0 -0
index 7623079..b747470 100644

qemu-ga.c static gboolean register_signal_handlers(void) · line 117

Quoted 4 lines
qemu-ga.c +0 -1
@@ -114,12 +114,10 @@ static gboolean register_signal_handlers(void)
     ret = sigaction(SIGINT, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;

Good catch, but we should really drop g_error() usage as qemu-ga will not fail gracefully otherwise (will leak the pidfile, for example). We either just drop g_error() or replace it by fprintf().

Quoted 8 lines
qemu-ga.c +0 -1
     }
     ret = sigaction(SIGTERM, &sigact, NULL);
     if (ret == -1) {
         g_error("error configuring signal handler: %s", strerror(errno));
-        return false;
     }
 
     return true;
#2 lore raw

Am 03.09.2012 18:49, schrieb Luiz Capitulino:

Quoted 14 lines
Quoted 11 lines · On Sat, 1 Sep 2012 09:34:15 +0200 Stefan Weil <[email protected]> wrote:

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
  qemu-ga.c |    2 --
  1 file changed, 2 deletions(-)
Quoted 12 lines

qemu-ga.c static gboolean register_signal_handlers(void) · line 117

Quoted 9 lines
qemu-ga.c +0 -1
index 7623079..b747470 100644
@@ -114,12 +114,10 @@ static gboolean register_signal_handlers(void)
      ret = sigaction(SIGINT, &sigact, NULL);
      if (ret == -1) {
          g_error("error configuring signal handler: %s", strerror(errno));
-        return false;

Good catch, but we should really drop g_error() usage as qemu-ga will not fail gracefully otherwise (will leak the pidfile, for example). We either just drop g_error() or replace it by fprintf().

Isn't that a classical case of an error which should never occur, something which could also be handled by an assert statement?

I don't expect a graceful exit after such errors. If they occur, that's something which must be fixed in the code.

When I read the documentation of sigaction, I don't see how it could fail with the given function arguments.

Therefore I'd apply the patch as it is.

Regards,

- sw

#3 lore raw
Quoted 31 lines · On Mon, 03 Sep 2012 19:02:20 +0200 Stefan Weil <[email protected]> wrote:

Am 03.09.2012 18:49, schrieb Luiz Capitulino:

Quoted 14 lines
Quoted 11 lines · On Sat, 1 Sep 2012 09:34:15 +0200 Stefan Weil <[email protected]> wrote:

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
  qemu-ga.c |    2 --
  1 file changed, 2 deletions(-)
Quoted 12 lines

qemu-ga.c static gboolean register_signal_handlers(void) · line 117

Quoted 9 lines
qemu-ga.c +0 -1
index 7623079..b747470 100644
@@ -114,12 +114,10 @@ static gboolean register_signal_handlers(void)
      ret = sigaction(SIGINT, &sigact, NULL);
      if (ret == -1) {
          g_error("error configuring signal handler: %s", strerror(errno));
-        return false;

Good catch, but we should really drop g_error() usage as qemu-ga will not fail gracefully otherwise (will leak the pidfile, for example). We either just drop g_error() or replace it by fprintf().

Isn't that a classical case of an error which should never occur, something which could also be handled by an assert statement?

Quoted 7 lines

I don't expect a graceful exit after such errors. If they occur, that's something which must be fixed in the code.

When I read the documentation of sigaction, I don't see how it could fail with the given function arguments.

Therefore I'd apply the patch as it is.

Yes, taking a look at the sigaction() manpages shows you're obviously correct. Please, disregard what I've said.

#4 lore raw
In reply to Stefan Weil
Quoted 10 lines · Stefan Weil

Report from smatch:
qemu-ga.c:117 register_signal_handlers(11) info: ignoring unreachable code. qemu-ga.c:122 register_signal_handlers(16) info: ignoring unreachable code.

g_error calls abort which terminates the program.

---
 qemu-ga.c |    2 --
 1 file changed, 2 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan