- old_umask = umask(0);
- for (p = tmp + 1; *p; p++) {
- if (*p == '/') {
- *p = 0;
- ret = mkdir(tmp, mode);
- if (ret < 0) {
- if (!(errno == EEXIST)) {
- perror("mkdir recursive");
- ret = errno;
- goto umask_error;
- }
- }
- *p = '/';
- }
- }
+ old_umask = umask(0);
+ for (p = tmp + 1; *p; p++) {
+ if (*p == '/') {
+ *p = 0;
+ ret = mkdir(tmp, mode);
+ if (ret < 0) {
+ if (!(errno == EEXIST)) {
+ PERROR("mkdir recursive");
+ ret = -errno;
+ goto umask_error;
+ }
+ } else if (ret == 0) {
+ /*
+ * We created the directory. Set its ownership to the
+ * user/group specified.
+ */
+ ret = chown(tmp, uid, gid);
+ if (ret < 0) {
+ PERROR("chown in mkdir recursive");
+ ret = -errno;
+ goto umask_error;
+ }
+ }
+ *p = '/';
+ }
+ }