+/** @brief Create the jukebox state directory
+ *
+ * If the home directory does not exist then creates it and assigns
+ * it suitable permissions.
+ */
+void make_home(void) {
+ struct stat sb;
+ struct passwd *pw;
+ char *home, *p;
+
+ if(stat(config->home, &sb) < 0) {
+ /* create parent directories */
+ home = xstrdup(config->home);
+ p = home;
+ while(*p) {
+ if(*p == '/' && p > home) {
+ *p = 0;
+ mkdir(home, 0755);
+ *p = '/';
+ }
+ ++p;
+ }
+ /* create the directory itself */
+ if(mkdir(config->home, 02755) < 0)
+ fatal(errno, "error creating %s", config->home);
+ /* make sure it has the right ownership */
+ if(config->user) {
+ if(!(pw = getpwnam(config->user)))
+ fatal(0, "cannot find user %s", config->user);
+ if(chown(config->home, pw->pw_uid, pw->pw_gid) < 0)
+ fatal(errno, "error chowning %s", config->home);
+ }
+ }
+}
+