fix: add "fattr" pledge for chmod(2) for cachefile - stagit-gopher - A git gopher frontend. (mirror)
git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
Log
Files
Refs
Tags
README
LICENSE
---
commit 181145cd95ae69fc4e54d98047aa1dc25d16b404
parent 77cc9b4e4f2c2d70880abf48090755902ee45c4f
Author: Hiltjo Posthuma 
Date:   Sun, 19 Nov 2017 14:57:01 +0100

fix: add "fattr" pledge for chmod(2) for cachefile

improve checks for when head is NULL (empty repo)

Diffstat:
  M stagit-gopher.c                     |      12 +++++-------

1 file changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/stagit-gopher.c b/stagit-gopher.c
@@ -1091,7 +1091,7 @@ main(int argc, char *argv[])
         size_t n;
         int i, fd;
 
-        if (pledge("stdio rpath wpath cpath", NULL) == -1)
+        if (pledge("stdio rpath wpath cpath fattr", NULL) == -1)
                 err(1, "pledge");
 
         setlocale(LC_CTYPE, "");
@@ -1111,6 +1111,8 @@ main(int argc, char *argv[])
                         cachefile = argv[++i];
                 }
         }
+        if (!cachefile && pledge("stdio rpath wpath cpath", NULL) == -1)
+                err(1, "pledge");
         if (!repodir)
                 usage(argv[0]);
 
@@ -1131,10 +1133,6 @@ main(int argc, char *argv[])
                 head = git_object_id(obj);
         git_object_free(obj);
 
-        /* don't cache if there is no HEAD */
-        if (!head)
-                cachefile = NULL;
-
         /* use directory name as name */
         if ((name = strrchr(repodirabs, '/')))
                 name++;
@@ -1196,7 +1194,7 @@ main(int argc, char *argv[])
         fprintf(fp, "%-50.50s  ", "Commit message");
         fprintf(fp, "%s\n", "Author");
 
-        if (cachefile) {
+        if (cachefile && head) {
                 /* read from cache file (does not need to exist) */
                 if ((rcachefp = fopen(cachefile, "r"))) {
                         if (!fgets(lastoidstr, sizeof(lastoidstr), rcachefp))
@@ -1258,7 +1256,7 @@ main(int argc, char *argv[])
         fclose(fp);
 
         /* rename new cache file on success */
-        if (cachefile) {
+        if (cachefile && head) {
                 if (rename(tmppath, cachefile))
                         err(1, "rename: '%s' to '%s'", tmppath, cachefile);
                 umask((mask = umask(0)));