]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
makedirs: pass subsystem, add mstrict command, fixes #3459
authorJaroslav Kysela <perex@perex.cz>
Mon, 8 Feb 2016 09:26:17 +0000 (10:26 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 8 Feb 2016 09:26:17 +0000 (10:26 +0100)
src/config.c
src/dvr/dvr_rec.c
src/settings.c
src/timeshift/timeshift_filemgr.c
src/tvheadend.h
src/tvhlog.h
src/utils.c

index 0e6ee9fee6c92a86027b7358c4d4948cc38fb0e7..4487060e649ac7400c331f3b13d4181869dfccdc 100644 (file)
@@ -1443,7 +1443,7 @@ dobackup(const char *oldver)
   }
 
   snprintf(outfile, sizeof(outfile), "%s/backup", root);
-  if (makedirs(outfile, 0700, -1, -1))
+  if (makedirs("config", outfile, 0700, 1, -1, -1))
     goto fatal;
   if (chdir(root)) {
     tvherror("config", "unable to find directory '%s'", root);
@@ -1647,7 +1647,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid )
   /* Ensure directory exists */
   if (stat(path, &st)) {
     config_newcfg = 1;
-    if (makedirs(path, 0700, gid, uid)) {
+    if (makedirs("config", path, 0700, 1, gid, uid)) {
       tvhwarn("START", "failed to create settings directory %s,"
                        " settings will not be saved", path);
       return;
index 0662ce3ae6400bbc6baba1e8f556c4725b23e98c..fd21b030356474c2be4473351cfe2b24d64cdc95 100644 (file)
@@ -746,7 +746,8 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
     dirsep = path + l;
   }
   htsstr_unescape_to(path, filename, sizeof(filename));
-  if (makedirs(filename, cfg->dvr_muxcnf.m_directory_permissions, -1, -1) != 0)
+  if (makedirs("dvr", filename,
+               cfg->dvr_muxcnf.m_directory_permissions, 0, -1, -1) != 0)
     return -1;
   max = pathconf(filename, _PC_NAME_MAX);
   if (max < 8)
index 120f5a1bf1a48d665bf04aa6419cd2a551648c11..0b00e684ad00c6ea46063ba1268995934e16c2f0 100644 (file)
@@ -82,7 +82,7 @@ hts_settings_makedirs ( const char *inpath )
     }
     x--;
   }
-  return makedirs(path, 0700, -1, -1);
+  return makedirs("settings", path, 0700, 1, -1, -1);
 }
 
 /**
index f00b81f55677c4837bb0ba8738e2d082369034ba..0af05b942af3536c6acf2ba15c0c38ec629fca8d 100644 (file)
@@ -159,7 +159,7 @@ int timeshift_filemgr_makedirs ( int index, char *buf, size_t len )
   if (timeshift_filemgr_get_root(buf, len))
     return 1;
   snprintf(buf+strlen(buf), len-strlen(buf), "/%d", index);
-  return makedirs(buf, 0700, -1, -1);
+  return makedirs("timeshift", buf, 0700, 0, -1, -1);
 }
 
 /*
index 0b2079963ecc367051bb2e33f516d6e4c6c07fe7..89cd2fb5c30c47445d38758a51b2f5b9cffc8e27 100644 (file)
@@ -777,7 +777,7 @@ static inline uint8_t *sbuf_peek(sbuf_t *sb, int off) { return sb->sb_data + off
 
 char *md5sum ( const char *str );
 
-int makedirs ( const char *path, int mode, gid_t gid, uid_t uid );
+int makedirs ( const char *subsys, const char *path, int mode, int mstrict, gid_t gid, uid_t uid );
 
 int rmtree ( const char *path );
 
index 16441423f2c218c089377376393e9265f4bb3180..8b19bec188b78eb1e7878cae5100ebda57947ca4 100644 (file)
@@ -128,6 +128,7 @@ static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; }
 #define tvhwarn(...)   tvhlog(LOG_WARNING, ##__VA_ARGS__)
 #define tvhnotice(...) tvhlog(LOG_NOTICE,  ##__VA_ARGS__)
 #define tvherror(...)  tvhlog(LOG_ERR,     ##__VA_ARGS__)
+#define tvhalert(...)  tvhlog(LOG_ALERT,   ##__VA_ARGS__)
 
 time_t dispatch_clock_update(struct timespec *ts);
 
index e8042b19341e4124dfc3c0ef3b216d9f1fd37211..3e558bdf207f7395571d5b598e5f773749e21995 100644 (file)
@@ -484,7 +484,8 @@ md5sum ( const char *str )
 #define FILE_MODE_BITS(x) (x&(S_IRWXU|S_IRWXG|S_IRWXO))
 
 int
-makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
+makedirs ( const char *subsys, const char *inpath, int mode,
+           int mstrict, gid_t gid, uid_t uid )
 {
   int err, ok;
   size_t x;
@@ -506,17 +507,25 @@ makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
         if (!err && gid != -1 && uid != -1)
           err = chown(path, uid, gid);
         if (!err && !stat(path, &st) &&
-            FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode))
+            FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode)) {
           err = chmod(path, mode); /* override umode */
-        tvhtrace("settings", "Creating directory \"%s\" with octal permissions "
-                             "\"%o\" gid %d uid %d", path, mode, gid, uid);
+          if (!mstrict) {
+            err = 0;
+            tvhwarn(subsys, "Unable to change directory permissions "
+                            "to \"%o\" for \"%s\" (keeping \"%o\")",
+                            mode, path, FILE_MODE_BITS(st.st_mode));
+            mode = FILE_MODE_BITS(st.st_mode);
+          }
+        }
+        tvhtrace(subsys, "Creating directory \"%s\" with octal permissions "
+                         "\"%o\" gid %d uid %d", path, mode, gid, uid);
       } else {
         err   = S_ISDIR(st.st_mode) ? 0 : 1;
         errno = ENOTDIR;
       }
       if (err) {
-        tvhlog(LOG_ALERT, "settings", "Unable to create dir \"%s\": %s",
-               path, strerror(errno));
+        tvhalert(subsys, "Unable to create dir \"%s\": %s",
+                 path, strerror(errno));
         return -1;
       }
       path[x] = '/';