static int site_misc_create_dir(const char *dir) { struct stat st; int res; pr_fs_clear_cache(); res = pr_fsio_stat(dir, &st); if (res == -1 && errno != ENOENT) { pr_log_debug(DEBUG2, MOD_SITE_MISC_VERSION ": error checking '%s': %s", dir, strerror(errno)); return -1; } if (res == 0) return 0; if (pr_fsio_mkdir(dir, 0777) < 0) { pr_log_debug(DEBUG2, MOD_SITE_MISC_VERSION ": error creating '%s': %s", dir, strerror(errno)); return -1; } return 0; }
static int create_dir(const char *dir, uid_t uid, gid_t gid, mode_t mode) { mode_t prev_mask; struct stat st; int res = -1; pr_fs_clear_cache2(dir); res = pr_fsio_stat(dir, &st); if (res == -1 && errno != ENOENT) { int xerrno = errno; pr_log_pri(PR_LOG_WARNING, "error checking '%s': %s", dir, strerror(xerrno)); errno = xerrno; return -1; } /* The directory already exists. */ if (res == 0) { pr_trace_msg(trace_channel, 8, "'%s' already exists", dir); pr_log_debug(DEBUG3, "CreateHome: '%s' already exists", dir); return 0; } /* The given mode is absolute, not subject to any Umask setting. */ prev_mask = umask(0); if (pr_fsio_mkdir(dir, mode) < 0) { int xerrno = errno; umask(prev_mask); pr_log_pri(PR_LOG_WARNING, "error creating '%s': %s", dir, strerror(xerrno)); errno = xerrno; return -1; } umask(prev_mask); if (pr_fsio_chown(dir, uid, gid) < 0) { int xerrno = errno; pr_log_pri(PR_LOG_WARNING, "error setting ownership of '%s': %s", dir, strerror(xerrno)); errno = xerrno; return -1; } pr_trace_msg(trace_channel, 8, "directory '%s' created", dir); pr_log_debug(DEBUG6, "CreateHome: directory '%s' created", dir); return 0; }
static int create_dir(const char *dir) { struct stat st; int res = -1; pr_fs_clear_cache2(dir); res = pr_fsio_stat(dir, &st); if (res < 0 && errno != ENOENT) { int xerrno = errno; pr_log_pri(PR_LOG_WARNING, MOD_COPY_VERSION ": error checking '%s': %s", dir, strerror(xerrno)); errno = xerrno; return -1; } /* The directory already exists. */ if (res == 0) { pr_trace_msg(trace_channel, 9, "path '%s' already exists", dir); return 1; } if (pr_fsio_mkdir(dir, 0777) < 0) { int xerrno = errno; pr_log_pri(PR_LOG_WARNING, MOD_COPY_VERSION ": error creating '%s': %s", dir, strerror(xerrno)); errno = xerrno; return -1; } pr_log_debug(DEBUG6, MOD_COPY_VERSION ": directory '%s' created", dir); return 0; }