From: Greg Hudson Date: Fri, 29 Mar 2013 06:22:12 +0000 (-0400) Subject: Fix errno hygiene in kadmind write_pid_file X-Git-Tag: krb5-1.12-alpha1~238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb473d814d5b422c67f2e2e69764edee1fdd9783;p=thirdparty%2Fkrb5.git Fix errno hygiene in kadmind write_pid_file fclose() might overwrite the errno value from fprintf, causing us to return success when we shouldn't. Record the errno value at the time of the fprintf failure. --- diff --git a/src/kadmin/server/ovsec_kadmd.c b/src/kadmin/server/ovsec_kadmd.c index a1fee7e3aa..dad7248696 100644 --- a/src/kadmin/server/ovsec_kadmd.c +++ b/src/kadmin/server/ovsec_kadmd.c @@ -194,9 +194,9 @@ write_pid_file(const char *pid_file) if (file == NULL) return errno; pid = (unsigned long) getpid(); - st1 = fprintf(file, "%ld\n", pid); - st2 = fclose(file); - return (st1 < 0 || st2 == EOF) ? errno : 0; + st1 = (fprintf(file, "%ld\n", pid) < 0) ? errno : 0; + st2 = (fclose(file) == EOF) ? errno : 0; + return st1 ? st1 : st2; } /* XXX yuck. the signal handlers need this */