Skip to contentSkip to conversation

qga: Fix shutdown command of guest agent to work with SysV

PATCH Applied whitearchey 2 participants 5 messages Nov 6, 2013 – Nov 13, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga: Fix shutdown command of guest agent to work with SysV

For now guest agent uses following command to shutdown system:
shutdown -P +0 "blabla"
but this syntax works only with shutdown command from systemd or upstart, because SysV shutdown requires -h switch.

Following patch changes the command so it works with systemd, upstart and SysV

---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +1 -1
index f453132..10682f5 100644
@@ -99,7 +99,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
         reopen_fd_to_null(1);
         reopen_fd_to_null(2);
 
-        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+        execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
                "hypervisor initiated shutdown", (char*)NULL, environ);
         _exit(EXIT_FAILURE);
     } else if (pid < 0) {
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 6 lines · whitearchey

For now guest agent uses following command to shutdown system:
shutdown -P +0 "blabla"
but this syntax works only with shutdown command from systemd or upstart, because SysV shutdown requires -h switch.

Following patch changes the command so it works with systemd, upstart and SysV

While the patch is one-liner indeed, it is a bit more than trivial. Because it changes things in a non-obvious way, especially when multiple systems are concerned. Cc'ing qemu-devel@ due to this.

qga/commands-posix.c void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) · line 102

Quoted 4 lines
qga/commands-posix.c +1 -1
-        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+        execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",

Note that shutdown command is not in POSIX, despite the fact that this is put into commands-posix.c

Note also that even shutdown from sysvinit on linux has another option, -P, which mean poweroff, while -h means "halt OR poweroff" (the latter is a bit unclear).

Does the same work on other *nixes? *BSD? Solaris?

Thanks,

/mjt

#2 lore raw
Quoted 20 lines · Michael Tokarev
Quoted 6 lines · whitearchey

For now guest agent uses following command to shutdown system:
shutdown -P +0 "blabla"
but this syntax works only with shutdown command from systemd or upstart, because SysV shutdown requires -h switch.

Following patch changes the command so it works with systemd, upstart and SysV

While the patch is one-liner indeed, it is a bit more than trivial. Because it changes things in a non-obvious way, especially when multiple systems are concerned. Cc'ing qemu-devel@ due to this.

qga/commands-posix.c void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) · line 102

Quoted 4 lines
qga/commands-posix.c +1 -1
-        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+        execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",

Note that shutdown command is not in POSIX, despite the fact that this is put into commands-posix.c

Quoted 3 lines

Note also that even shutdown from sysvinit on linux has another option, -P, which mean poweroff, while -h means "halt OR poweroff" (the latter is a bit unclear).

With upstart/systemd qga use one of thee commands, depending on 'mode' parameter:
shutdown -P +0 "..."
shutdown -H +0 "..."
shutdown -r +0 "..."
SysV equivalents for these are:
shutdown -h -P +0 "..."
shutdown -h -H +0 "..."
shutdown -h -r +0 "..."
and these retain their meaning with upstart/systemd.

Quoted 3 lines

Does the same work on other *nixes? *BSD? Solaris?

No, it doesn't. But existing code also does not work.
According to FreeBSD manpages, shutdown does not accept -P and -H options. Commands should be:
shutdown -p +0 "..."
shutdown -h +0 "..."
shutdown -r +0 "..."

shutdown in Solaris does not accept any of -hHpPr and does not accept time in "+0" format

Quoted 3 lines

Thanks,

/mjt

#3 lore raw

What about patch? Will it be applied? Or should it be rewritten?

Quoted 49 lines · whitearchey
Quoted 20 lines · Michael Tokarev
Quoted 6 lines · whitearchey

For now guest agent uses following command to shutdown system:
shutdown -P +0 "blabla"
but this syntax works only with shutdown command from systemd or upstart, because SysV shutdown requires -h switch.

Following patch changes the command so it works with systemd, upstart and SysV

While the patch is one-liner indeed, it is a bit more than trivial. Because it changes things in a non-obvious way, especially when multiple systems are concerned. Cc'ing qemu-devel@ due to this.

qga/commands-posix.c void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) · line 102

Quoted 4 lines
qga/commands-posix.c +1 -1
-        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+        execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",

Note that shutdown command is not in POSIX, despite the fact that this is put into commands-posix.c

Quoted 3 lines

Note also that even shutdown from sysvinit on linux has another option, -P, which mean poweroff, while -h means "halt OR poweroff" (the latter is a bit unclear).

With upstart/systemd qga use one of thee commands, depending on 'mode' parameter:

   shutdown -P +0 "..."
   shutdown -H +0 "..."
   shutdown -r +0 "..."
SysV equivalents for these are:
   shutdown -h -P +0 "..."
   shutdown -h -H +0 "..."
   shutdown -h -r +0 "..."

and these retain their meaning with upstart/systemd.

Quoted 3 lines

Does the same work on other *nixes? *BSD? Solaris?

No, it doesn't. But existing code also does not work.
According to FreeBSD manpages, shutdown does not accept -P and -H options. Commands should be:

   shutdown -p +0 "..."
   shutdown -h +0 "..."
   shutdown -r +0 "..."

shutdown in Solaris does not accept any of -hHpPr and does not accept time in "+0" format

Quoted 3 lines

Thanks,

/mjt

Signature · 1 line
Using Opera's revolutionary email client: http://www.opera.com/mail/
#4 lore raw
In reply to whitearchey
Quoted 17 lines · whitearchey

For now guest agent uses following command to shutdown system:
shutdown -P +0 "blabla"
but this syntax works only with shutdown command from systemd or upstart, because SysV shutdown requires -h switch.

Following patch changes the command so it works with systemd, upstart and SysV

---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix.c +0 -0
index f453132..10682f5 100644

qga/commands-posix.c void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) · line 105

Quoted 8 lines
qga/commands-posix.c +1 -1
@@ -99,7 +99,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
         reopen_fd_to_null(1);
         reopen_fd_to_null(2);
 
-        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+        execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
                "hypervisor initiated shutdown", (char*)NULL, environ);
         _exit(EXIT_FAILURE);
     } else if (pid < 0) {

Applied to the trivial-patches queue, with additional comments from your next email explaining which commands/flags are used by which shutdown command.

I guess we'll need some #ifdef SOLARIS..#ifdef *BSD here later, but for now it should be fine as-is, since apparently both variants (before and after your change) are linux-only anyway.

Thanks,

/mjt