[Freeipa-devel] [PATCH] detect failure to write ipa_kpasswd.pid file

Simo Sorce ssorce at redhat.com
Thu May 15 14:51:34 UTC 2008


On Thu, 2008-05-15 at 13:29 +0200, Jim Meyering wrote:
> In case you like that, here's the patch:
> 
> >From e9c342f7670c8120695e06351d3e895c2c907910 Mon Sep 17 00:00:00
> 2001
> From: Jim Meyering <meyering at redhat.com>
> Date: Sun, 4 May 2008 15:17:36 +0200
> Subject: [PATCH] detect failure to write ipa_kpasswd.pid file
> 
> * ipa_kpasswd.c (main): Detect not just open failure,
> but also any write failure.
> ---
>  ipa-server/ipa-kpasswd/ipa_kpasswd.c |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/ipa-server/ipa-kpasswd/ipa_kpasswd.c
> b/ipa-server/ipa-kpasswd/ipa_kpasswd.c
> index 5782367..2b82f18 100644
> --- a/ipa-server/ipa-kpasswd/ipa_kpasswd.c
> +++ b/ipa-server/ipa-kpasswd/ipa_kpasswd.c
> @@ -3,7 +3,7 @@
> 
>  /* Authors: Simo Sorce <ssorce at redhat.com>
>   *
> - * Copyright (C) 2007  Red Hat
> + * Copyright (C) 2007, 2008  Red Hat
>   * see file 'COPYING' for use and warranty information
>   *
>   * This program is free software; you can redistribute it and/or
> @@ -1188,13 +1188,18 @@ int main(int argc, char *argv[])
>         }
> 
>         /* Write out the pid file after the sigterm handler */
> -       FILE *f = fopen("/var/run/ipa_kpasswd.pid", "w");
> -       if (f == NULL) {
> -               syslog(LOG_ERR,"Couldn't create pid
> file /var/run/ipa_kpasswd.pid: %s", strerror(errno));
> +       const char *pid_file = "/var/run/ipa_kpasswd.pid";
> +       FILE *f = fopen(pid_file, "w");
> +       int fail = 1;
> +       if (f) {
> +               int n_bytes = fprintf(f, "%ld\n", (long) getpid());
> +               if (fclose(f) == 0 && 0 < n_bytes)
> +                       fail = 0;
> +       }
> +       if (fail) {
> +               syslog(LOG_ERR,"Couldn't create pid file %s: %s",
> +                      pid_file, strerror(errno));
>                 exit(1);
> -       } else {
> -               fprintf(f, "%ld\n", (long) getpid());
> -               fclose(f);
>         }
> 
>         tai = ai;
> --
> 1.5.5.1.216.g33c73


ack

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York




More information about the Freeipa-devel mailing list