#include "log.h"
#include "util.h"
#include "mkdir.h"
+#include "path-util.h"
#include "strv.h"
#include "label.h"
#include "set.h"
+#include "conf-files.h"
/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
* them in the file system. This is intended to be used to create
}
static int create_item(Item *i) {
- int r;
+ int r, e;
mode_t u;
struct stat st;
i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC : 0;
u = umask(0);
+ label_context_set(i->path, S_IFREG);
fd = open(i->path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY|O_NOFOLLOW, i->mode);
+ e = errno;
+ label_context_clear();
umask(u);
+ errno = e;
if (fd < 0) {
if (i->type == WRITE_FILE && errno == ENOENT)
iovec[1].iov_len = 1;
n = writev(fd, iovec, 2);
- if (n < 0 || (size_t) n != l+1) {
- log_error("Failed to write file %s: %s", i->path, n < 0 ? strerror(-n) : "Short");
+
+ /* It's OK if we don't write the trailing
+ * newline, hence we check for l, instead of
+ * l+1 here. Files in /sys often refuse
+ * writing of the trailing newline. */
+ if (n < 0 || (size_t) n < l) {
+ log_error("Failed to write file %s: %s", i->path, n < 0 ? strerror(-n) : "Short write");
close_nointr_nofail(fd);
return n < 0 ? n : -EIO;
}
case CREATE_SYMLINK: {
char *x;
+ 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);
return -errno;
case CREATE_CHAR_DEVICE: {
u = umask(0);
+ label_context_set(i->path, CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR);
r = mknod(i->path, i->mode | (i->type == CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR), i->major_minor);
+ e = errno;
+ label_context_clear();
umask(u);
+ errno = e;
if (r < 0 && errno != EEXIST) {
log_error("Failed to create device node %s: %m", i->path);
umask(0022);
- label_init();
+ label_init(NULL);
items = hashmap_new(string_hash_func, string_compare_func);
globs = hashmap_new(string_hash_func, string_compare_func);
"/usr/lib/tmpfiles.d",
NULL);
if (r < 0) {
- r = EXIT_FAILURE;
log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
+ r = EXIT_FAILURE;
goto finish;
}