summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>1997-10-12 20:29:56 +0000
committerBob Beck <beck@cvs.openbsd.org>1997-10-12 20:29:56 +0000
commit08eacca3df59e33e7e2f6e64e9b847cfb12441a4 (patch)
treefaf6e7027acf51af493e232560ffd63c4df46368
parent58730a8c4d7fc2396f447540a9a034d35dd7455b (diff)
ftruncate the lock file for supfilesrv -O before writing pid into it.
-rw-r--r--usr.bin/sup/src/scm.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.bin/sup/src/scm.c b/usr.bin/sup/src/scm.c
index 7f1cfb9f9f1..36a1a3408d5 100644
--- a/usr.bin/sup/src/scm.c
+++ b/usr.bin/sup/src/scm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scm.c,v 1.7 1997/10/11 23:34:20 beck Exp $ */
+/* $OpenBSD: scm.c,v 1.8 1997/10/12 20:29:55 beck Exp $ */
/*
* Copyright (c) 1992 Carnegie Mellon University
@@ -250,7 +250,7 @@ int lock_host_file(char *lockdir) {
}
free(dd);
if ((fd = open(lpath, O_CREAT | O_WRONLY, 0600)) < 0) {
- syslog(LOG_ERR, "Couldn't open/create lock file %s!", lpath);
+ syslog(LOG_ERR, "Couldn't open/create lock file %s (%m)", lpath);
free(lpath);
return(-1);
}
@@ -265,9 +265,16 @@ int lock_host_file(char *lockdir) {
close(fd);
return(-1);
}
+ if (ftruncate(fd, 0) < 0) {
+ syslog(LOG_ERR, "Couldn't ftruncate fd %d for lock file %s (%m)",
+ fd, lpath);
+ free(lpath);
+ close(fd);
+ return(-1);
+ }
f=fdopen(fd,"w");
if (f == NULL) {
- syslog(LOG_ERR, "Couldn't fopen fd %d for lock file %s!", fd, lpath);
+ syslog(LOG_ERR, "Couldn't fopen fd %d for lock file %s (%m)", fd, lpath);
free(lpath);
close(fd);
return(-1);