On 03/07/11 21:10, Michael Roth wrote:
> Signed-off-by: Michael Roth <mdr...@linux.vnet.ibm.com>
> ---
>  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

Reply via email to