Skip to contentSkip to conversation

git-daemon: don't ignore pid-file write failure

PATCH New Jim Meyering 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-daemon: don't ignore pid-file write failure

Note: since the consequence of failure is to call die, I don't bother to close "f".

---
 daemon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
daemon.c +2 -2
index e74ecac..674e30d 100644
@@ -970,8 +970,8 @@ static void store_pid(const char *path)
 	FILE *f = fopen(path, "w");
 	if (!f)
 		die("cannot open pid file %s: %s", path, strerror(errno));
-	fprintf(f, "%d\n", getpid());
-	fclose(f);
+	if (fprintf(f, "%d\n", getpid()) < 0 || fclose(f) != 0)
+		die("failed to write pid file %s: %s", path, strerror(errno));
 }
 
 static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)

--
1.5.2