From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42619 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxGxH-000259-B7 for qemu-devel@nongnu.org; Wed, 09 Mar 2011 05:49:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxGxF-0004sj-WB for qemu-devel@nongnu.org; Wed, 09 Mar 2011 05:49:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:65241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxGxF-0004sQ-Ne for qemu-devel@nongnu.org; Wed, 09 Mar 2011 05:49:21 -0500 Message-ID: <4D775B13.1030401@redhat.com> Date: Wed, 09 Mar 2011 11:48:51 +0100 From: Jes Sorensen MIME-Version: 1.0 References: <1299528642-23631-1-git-send-email-mdroth@linux.vnet.ibm.com> <1299528642-23631-16-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1299528642-23631-16-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [RFC][PATCH v7 15/16] virtagent: qemu-va, system-level virtagent guest agent List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, markus_mueller@de.ibm.com, qemu-devel@nongnu.org, aliguori@linux.vnet.ibm.com, abeekhof@redhat.com On 03/07/11 21:10, Michael Roth wrote: > Signed-off-by: Michael Roth > --- > qemu-va.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 247 insertions(+), 0 deletions(-) > create mode 100644 qemu-va.c > > diff --git a/qemu-va.c b/qemu-va.c > new file mode 100644 > index 0000000..a9ff56f > --- /dev/null > +++ b/qemu-va.c > @@ -0,0 +1,247 @@ [snip] > +static void become_daemon(void) > +{ > + pid_t pid, sid; > + int pidfd; > + char *pidstr; > + > + pid = fork(); > + if (pid < 0) > + exit(EXIT_FAILURE); > + if (pid > 0) { > + exit(EXIT_SUCCESS); > + } > + > + pidfd = open(VA_PIDFILE, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); > + if (!pidfd || lockf(pidfd, F_TLOCK, 0)) > + errx(EXIT_FAILURE, "Cannot lock pid file"); > + > + if (ftruncate(pidfd, 0) || lseek(pidfd, 0, SEEK_SET)) > + errx(EXIT_FAILURE, "Cannot truncate pid file"); > + if (asprintf(&pidstr, "%d", getpid()) == -1) > + errx(EXIT_FAILURE, "Cannot allocate memory"); > + if (write(pidfd, pidstr, strlen(pidstr)) != strlen(pidstr)) > + errx(EXIT_FAILURE, "Failed to write pid file"); > + free(pidstr); Coding style - this needs to be fixed. > + umask(0); > + sid = setsid(); > + if (sid < 0) > + goto fail; > + if ((chdir("/")) < 0) > + goto fail; and again Cheers, Jes