Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-18 Thread Eric Blake
On 01/17/2012 03:57 AM, Jamie Lokier wrote: > You're right, but it looks like it may be removed in the next edition: > >https://www.opengroup.org/austin/docs/austin_446.txt > >> it was only pthread_atfork() which was removed. > > I didn't think pthread_atfork() ever was async-signal-safe. >

[Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Luiz Capitulino
The guest-suspend command supports three modes: o hibernate (suspend to disk) o sleep (suspend to ram) o hybrid(save RAM contents to disk, but suspend instead of powering off) Before trying to suspend, the command queries the guest in order to know whether the given mode

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Daniel P. Berrange
On Tue, Jan 17, 2012 at 10:18:34AM -0200, Luiz Capitulino wrote: > On Mon, 16 Jan 2012 21:06:27 + > "Daniel P. Berrange" wrote: > > > +has_pmutils = find_executable_file(pmutils_bin, pmutils_path, > > > + sizeof(pmutils_path)); > > > + > > > +pid =

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Luiz Capitulino
On Mon, 16 Jan 2012 16:17:34 -0600 Michael Roth wrote: > On 01/16/2012 02:09 PM, Luiz Capitulino wrote: > > The guest-suspend command supports three modes: > > > > o hibernate (suspend to disk) > > o sleep (suspend to ram) > > o hybrid(save RAM contents to disk, but suspend instead

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Luiz Capitulino
On Mon, 16 Jan 2012 21:06:27 + "Daniel P. Berrange" wrote: > On Mon, Jan 16, 2012 at 06:09:52PM -0200, Luiz Capitulino wrote: > > > +/* Try to find executable file 'file'. If it's found, its absolute path is > > + returned in 'abs_path' and the function returns true. If it's not found, > >

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Jamie Lokier
Michael Roth wrote: > >STDIO is one of the major areas of code that is definitely not > >async signal safe. Consider Thread A doing something like > >fwrite(stderr, "Foo\n"), while another thread forks, and then > >its child also does an fwrite(stderr, "Foo\n"). Given that > >every stdio function w

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-17 Thread Jamie Lokier
Eric Blake wrote: > On 01/16/2012 03:51 AM, Jamie Lokier wrote: > > I'm not sure if it's relevant to the this code, but on Glibc fork() is > > not async-signal-safe and has been known to crash in signal handlers. > > This is why fork() was removed from SUS async-signal-safe functions. > > fork() i

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Michael Roth
On 01/16/2012 02:09 PM, Luiz Capitulino wrote: The guest-suspend command supports three modes: o hibernate (suspend to disk) o sleep (suspend to ram) o hybrid(save RAM contents to disk, but suspend instead of powering off) Before trying to suspend, the command queri

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Michael Roth
On 01/16/2012 02:35 PM, Daniel P. Berrange wrote: On Mon, Jan 16, 2012 at 02:02:08PM -0600, Michael Roth wrote: On 01/16/2012 11:23 AM, Luiz Capitulino wrote: On Mon, 16 Jan 2012 15:18:37 -0200 Luiz Capitulino wrote: On Mon, 16 Jan 2012 17:13:39 + "Daniel P. Berrange" wrote: On Mon,

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Jamie Lokier
Eric Blake wrote: > On 01/13/2012 12:15 PM, Luiz Capitulino wrote: > > This might look complex, but the final code is quite simple. The > > purpose of that approach is to allow qemu-ga to reap its children > > (semi-)automatically from its SIGCHLD handler. > > Yes, given your desire for the top-le

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Eric Blake
On 01/16/2012 01:19 PM, Luiz Capitulino wrote: >> memset(), strlen, strcpy, and friends in are all in the class >> of functions that I think are unintentional omissions from the list of >> async-signal-safe functions (they don't read/modify anything but the >> pointers passed in, so the _only_ rea

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Daniel P. Berrange
On Mon, Jan 16, 2012 at 06:09:52PM -0200, Luiz Capitulino wrote: > +/* Try to find executable file 'file'. If it's found, its absolute path is > + returned in 'abs_path' and the function returns true. If it's not found, > + the function will return false and 'abs_path' will contain zeros */ >

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Daniel P. Berrange
On Mon, Jan 16, 2012 at 02:02:08PM -0600, Michael Roth wrote: > On 01/16/2012 11:23 AM, Luiz Capitulino wrote: > >On Mon, 16 Jan 2012 15:18:37 -0200 > >Luiz Capitulino wrote: > > > >>On Mon, 16 Jan 2012 17:13:39 + > >>"Daniel P. Berrange" wrote: > >> > >>>On Mon, Jan 16, 2012 at 03:08:53PM -0

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
On Mon, 16 Jan 2012 13:08:23 -0700 Eric Blake wrote: > On 01/16/2012 10:08 AM, Luiz Capitulino wrote: > >> Strangely enough, POSIX doesn't include strcmp() in its list of > >> async-signal-safe functions (which is what you should be restricting > >> yourself to, if qemu-ga is multi-threaded), but

[Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
The guest-suspend command supports three modes: o hibernate (suspend to disk) o sleep (suspend to ram) o hybrid(save RAM contents to disk, but suspend instead of powering off) Before trying to suspend, the command queries the guest in order to know whether the given mode

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Eric Blake
On 01/16/2012 10:08 AM, Luiz Capitulino wrote: >> Strangely enough, POSIX doesn't include strcmp() in its list of >> async-signal-safe functions (which is what you should be restricting >> yourself to, if qemu-ga is multi-threaded), but in practice, I think >> that is a bug of omission in POSIX, an

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Michael Roth
On 01/16/2012 11:23 AM, Luiz Capitulino wrote: On Mon, 16 Jan 2012 15:18:37 -0200 Luiz Capitulino wrote: On Mon, 16 Jan 2012 17:13:39 + "Daniel P. Berrange" wrote: On Mon, Jan 16, 2012 at 03:08:53PM -0200, Luiz Capitulino wrote: On Fri, 13 Jan 2012 14:48:04 -0700 Eric Blake wrote: +

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
On Mon, 16 Jan 2012 15:18:37 -0200 Luiz Capitulino wrote: > On Mon, 16 Jan 2012 17:13:39 + > "Daniel P. Berrange" wrote: > > > On Mon, Jan 16, 2012 at 03:08:53PM -0200, Luiz Capitulino wrote: > > > On Fri, 13 Jan 2012 14:48:04 -0700 > > > Eric Blake wrote: > > > > > > > > + > > > > > +

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
On Mon, 16 Jan 2012 17:13:39 + "Daniel P. Berrange" wrote: > On Mon, Jan 16, 2012 at 03:08:53PM -0200, Luiz Capitulino wrote: > > On Fri, 13 Jan 2012 14:48:04 -0700 > > Eric Blake wrote: > > > > > > + > > > > +pid = fork(); > > > > +if (!pid) { > > > > +char buf[

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Daniel P. Berrange
On Mon, Jan 16, 2012 at 03:08:53PM -0200, Luiz Capitulino wrote: > On Fri, 13 Jan 2012 14:48:04 -0700 > Eric Blake wrote: > > > > + > > > +pid = fork(); > > > +if (!pid) { > > > +char buf[32]; > > > +FILE *sysfile; > > > +const char *arg; > > >

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
On Fri, 13 Jan 2012 14:48:04 -0700 Eric Blake wrote: > > + > > +pid = fork(); > > +if (!pid) { > > +char buf[32]; > > +FILE *sysfile; > > +const char *arg; > > +const char *pmutils_bin = "pm-is-supported"; > > + > > +if (

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Eric Blake
On 01/16/2012 03:51 AM, Jamie Lokier wrote: > > Since you mention async-signal-safety, execlp() isn't > async-signal-safe! Last time I checked, in Glibc execlp() could call > malloc(). Also reading PATH looks at the environment, which isn't > always thread-safe either, depending on what else is

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-16 Thread Luiz Capitulino
On Fri, 13 Jan 2012 14:48:04 -0700 Eric Blake wrote: > On 01/13/2012 12:15 PM, Luiz Capitulino wrote: > > The guest-suspend command supports three modes: > > > > o hibernate (suspend to disk) > > o sleep (suspend to ram) > > o hybrid(save RAM contents to disk, but suspend instead of >

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-13 Thread Eric Blake
On 01/13/2012 12:15 PM, Luiz Capitulino wrote: > The guest-suspend command supports three modes: > > o hibernate (suspend to disk) > o sleep (suspend to ram) > o hybrid(save RAM contents to disk, but suspend instead of > powering off) > > To reap terminated children, a ne

[Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-13 Thread Luiz Capitulino
The guest-suspend command supports three modes: o hibernate (suspend to disk) o sleep (suspend to ram) o hybrid(save RAM contents to disk, but suspend instead of powering off) Before trying to suspend, the command queries the guest in order to know whether a given mode is

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-05 Thread Luiz Capitulino
On Thu, 5 Jan 2012 12:46:56 + "Daniel P. Berrange" wrote: > On Wed, Jan 04, 2012 at 05:45:13PM -0200, Luiz Capitulino wrote: > > diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c > > index a09c8ca..19f29c6 100644 > > --- a/qga/guest-agent-commands.c > > +++ b/qga/guest-agen

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-05 Thread Daniel P. Berrange
On Wed, Jan 04, 2012 at 05:45:13PM -0200, Luiz Capitulino wrote: > diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c > index a09c8ca..19f29c6 100644 > --- a/qga/guest-agent-commands.c > +++ b/qga/guest-agent-commands.c > @@ -574,6 +574,61 @@ int64_t qmp_guest_fsfreeze_thaw(Error

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-05 Thread Luiz Capitulino
On Wed, 04 Jan 2012 13:03:26 -0700 Eric Blake wrote: > On 01/04/2012 12:45 PM, Luiz Capitulino wrote: > > +if (pid == 0) { > > +/* child */ > > +int fd; > > + > > +setsid(); > > +fclose(stdin); > > +fclose(stdout); > > +fclose(stderr); > > + > >

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-04 Thread Eric Blake
On 01/04/2012 12:45 PM, Luiz Capitulino wrote: > +if (pid == 0) { > +/* child */ > +int fd; > + > +setsid(); > +fclose(stdin); > +fclose(stdout); > +fclose(stderr); > + > +execlp(pmutils_bin, pmutils_bin, NULL); It's generally a bad idea

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-04 Thread Michael Roth
On 01/04/2012 01:45 PM, Luiz Capitulino wrote: For now it only supports the "hibernate" mode, which suspends the guest to disk. This command will try to execute the scripts provided by the pm-utils package. If that fails, it will try to suspend manually by writing to the "/sys/power/state" file.

[Qemu-devel] [PATCH 2/2] qemu-ga: Add the guest-suspend command

2012-01-04 Thread Luiz Capitulino
For now it only supports the "hibernate" mode, which suspends the guest to disk. This command will try to execute the scripts provided by the pm-utils package. If that fails, it will try to suspend manually by writing to the "/sys/power/state" file. To reap terminated children, a new signal handl