Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/fssconfig Use stat() information to decide if the b...



details:   https://anonhg.NetBSD.org/src/rev/302373af7518
branches:  trunk
changeset: 358324:302373af7518
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Dec 21 15:52:19 2017 +0000

description:
Use stat() information to decide if the backing store is a directory.
Depending on open() returning EISDIR fails for mount points.

diffstat:

 usr.sbin/fssconfig/fssconfig.c |  42 ++++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 20 deletions(-)

diffs (66 lines):

diff -r 10590c9431d0 -r 302373af7518 usr.sbin/fssconfig/fssconfig.c
--- a/usr.sbin/fssconfig/fssconfig.c    Thu Dec 21 15:51:39 2017 +0000
+++ b/usr.sbin/fssconfig/fssconfig.c    Thu Dec 21 15:52:19 2017 +0000
@@ -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 @@
            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 @@
                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 (istmp) {
+               snprintf(path, sizeof(path), "%s/XXXXXXXXXX", argv[2]);
+               fss.fss_bstore = path;
+               fd = mkstemp(fss.fss_bstore);
+       } else {
+               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);
-               fss.fss_bstore = path;
-               istmp = 1;
+               err(1, "create: %s", fss.fss_bstore);
        }
        if (prog_fstat(fd, &sbuf) < 0)
                err(1, "stat: %s", fss.fss_bstore);



Home | Main Index | Thread Index | Old Index