summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2008-05-15 13:29:56 +0200
committerSimo Sorce <ssorce@redhat.com>2008-05-15 13:10:38 -0400
commit498b96617e16e56229374389db9a09cacb78f099 (patch)
tree8ee015547e5ba79d478b1382a1dd22bd49823004
parenta8ae72800be32b29c36189ad0edc95bd8ae8c185 (diff)
downloadfreeipa-498b96617e16e56229374389db9a09cacb78f099.tar.gz
freeipa-498b96617e16e56229374389db9a09cacb78f099.tar.xz
freeipa-498b96617e16e56229374389db9a09cacb78f099.zip
detect failure to write ipa_kpasswd.pid file
* ipa_kpasswd.c (main): Detect not just open failure, but also any write failure.
-rw-r--r--ipa-server/ipa-kpasswd/ipa_kpasswd.c19
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 898cffa4..a5a82cc9 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@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
@@ -1186,13 +1186,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;