}
static int dir_is_mount_point(DIR *d, const char *subdir) {
- struct file_handle *h;
+ union file_handle_union h = { .handle.handle_bytes = MAX_HANDLE_SZ };
int mount_id_parent, mount_id;
int r_p, r;
- h = alloca(MAX_HANDLE_SZ);
-
- h->handle_bytes = MAX_HANDLE_SZ;
- r_p = name_to_handle_at(dirfd(d), ".", h, &mount_id_parent, 0);
+ r_p = name_to_handle_at(dirfd(d), ".", &h.handle, &mount_id_parent, 0);
if (r_p < 0)
r_p = -errno;
- h->handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(dirfd(d), subdir, h, &mount_id, 0);
+ h.handle.handle_bytes = MAX_HANDLE_SZ;
+ r = name_to_handle_at(dirfd(d), subdir, &h.handle, &mount_id, 0);
if (r < 0)
r = -errno;
}
static int write_one_file(Item *i, const char *path) {
- int e, flags;
+ int flags;
int fd = -1;
struct stat st;
int r = 0;
+ assert(i);
+ assert(path);
+
flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND :
i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
RUN_WITH_UMASK(0) {
label_context_set(path, S_IFREG);
fd = open(path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, i->mode);
- e = errno;
label_context_clear();
- errno = e;
}
if (fd < 0) {
unescaped = cunescape(i->argument);
if (unescaped == NULL) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return log_oom();
}
if (n < 0 || (size_t) n < l) {
log_error("Failed to write file %s: %s", path, n < 0 ? strerror(-n) : "Short write");
- close_nointr_nofail(fd);
+ safe_close(fd);
return n < 0 ? n : -EIO;
}
}
- close_nointr_nofail(fd);
+ safe_close(fd);
if (stat(path, &st) < 0) {
log_error("stat(%s) failed: %m", path);
}
static int create_item(Item *i) {
- int e;
struct stat st;
int r = 0;
label_context_set(i->path, S_IFLNK);
r = symlink(i->argument, i->path);
- e = errno;
label_context_clear();
- errno = e;
if (r < 0 && errno != EEXIST) {
log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
RUN_WITH_UMASK(0000) {
label_context_set(i->path, file_type);
r = mknod(i->path, i->mode | file_type, i->major_minor);
- e = errno;
label_context_clear();
- errno = e;
}
if (r < 0 && errno != EEXIST) {