+ if(flags & TRACKDB_MAY_CREATE) {
+ DIR *dp;
+ struct dirent *de;
+ struct stat st;
+ char *p;
+
+ /* create home directory if it does not exist */
+ mkdir(config->home, 0755);
+ /* Remove world/group permissions on any regular files already in the
+ * database directory. Actually we don't care about all of them but it's
+ * easier to just do the lot. This can be revisited if it's a serious
+ * practical inconvenience for anyone.
+ *
+ * The socket, not being a regular file, is excepted.
+ */
+ if(!(dp = opendir(config->home)))
+ fatal(errno, "error reading %s", config->home);
+ while((de = readdir(dp))) {
+ byte_xasprintf(&p, "%s/%s", config->home, de->d_name);
+ if(lstat(p, &st) == 0
+ && S_ISREG(st.st_mode)
+ && (st.st_mode & 077)) {
+ if(chmod(p, st.st_mode & (~(mode_t)077) & 07777) < 0)
+ fatal(errno, "cannot chmod %s", p);
+ }
+ xfree(p);
+ }
+ closedir(dp);
+ }
+