Module Name: src
Committed By: hannken
Date: Thu Dec 21 15:52:19 UTC 2017
Modified Files:
src/usr.sbin/fssconfig: fssconfig.c
Log Message:
Use stat() information to decide if the backing store is a directory.
Depending on open() returning EISDIR fails for mount points.
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/fssconfig/fssconfig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/fssconfig/fssconfig.c
diff -u src/usr.sbin/fssconfig/fssconfig.c:1.12 src/usr.sbin/fssconfig/fssconfig.c:1.13
--- src/usr.sbin/fssconfig/fssconfig.c:1.12 Sun Jul 31 02:13:26 2016
+++ src/usr.sbin/fssconfig/fssconfig.c Thu Dec 21 15:52:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fssconfig.c,v 1.12 2016/07/31 02:13:26 pgoyette Exp $ */
+/* $NetBSD: fssconfig.c,v 1.13 2017/12/21 15:52:19 hannken Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -130,16 +130,19 @@ config(int argc, char **argv)
prog_stat(argv[1], &sbuf) != 0)
err(1, "stat %s", argv[1]);
mountdev = sbuf.st_dev;
- if (stat(argv[2], &sbuf) == 0 &&
- S_ISREG(sbuf.st_mode) &&
- sbuf.st_dev == mountdev) {
- if ((sbuf.st_flags & SF_SNAPSHOT) == 0)
- errx(1, "%s: exists and is not a snapshot", argv[2]);
- if (argc != 3)
- usage();
- isreg = ispersistent = 1;
+ if (stat(argv[2], &sbuf) == 0) {
+ if (S_ISREG(sbuf.st_mode) && sbuf.st_dev == mountdev) {
+ if ((sbuf.st_flags & SF_SNAPSHOT) == 0)
+ errx(1, "%s: exists and is not a snapshot",
+ argv[2]);
+ if (argc != 3)
+ usage();
+ isreg = ispersistent = 1;
- goto configure;
+ goto configure;
+ } else if (S_ISDIR(sbuf.st_mode)) {
+ istmp = 1;
+ }
}
if (argc > 5)
@@ -155,18 +158,17 @@ config(int argc, char **argv)
bssize = (off_t)fsbuf.f_blocks*fsbuf.f_frsize;
/*
- * Create the backing store. If it is a directory, create a temporary
- * file and set the unlink flag.
+ * Create the backing store.
*/
- fd = prog_open(fss.fss_bstore, O_CREAT|O_TRUNC|O_WRONLY, 0600);
- if (fd < 0) {
- if (errno != EISDIR)
- err(1, "create: %s", fss.fss_bstore);
- snprintf(path, sizeof(path), "%s/XXXXXXXXXX", fss.fss_bstore);
- if ((fd = mkstemp(path)) < 0)
- err(1, "mkstemp: %s", path);
+ if (istmp) {
+ snprintf(path, sizeof(path), "%s/XXXXXXXXXX", argv[2]);
fss.fss_bstore = path;
- istmp = 1;
+ fd = mkstemp(fss.fss_bstore);
+ } else {
+ fd = prog_open(fss.fss_bstore, O_CREAT|O_TRUNC|O_WRONLY, 0600);
+ }
+ if (fd < 0) {
+ err(1, "create: %s", fss.fss_bstore);
}
if (prog_fstat(fd, &sbuf) < 0)
err(1, "stat: %s", fss.fss_bstore);