Skip to content

Commit

Permalink
tmpfiles: try to handle read-only file systems gracefully
Browse files Browse the repository at this point in the history
On read-only filesystems trying to create the target will not fail with
EEXIST but with EROFS. Handle EROFS by checking if the target already
exists, and if empty when truncating.
This avoids reporting errors if tmpfiles doesn't actually needs to do
anything.

[zj: revert condition to whitelist rather then blacklisting, and add goto
to avoid stat'ting twice.]
  • Loading branch information
michaelolbrich authored and keszybz committed May 6, 2015
1 parent 3e7f33a commit f44b28f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tmpfiles/tmpfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,12 @@ static int write_one_file(Item *i, const char *path) {
return 0;
}

log_error_errno(errno, "Failed to create file %s: %m", path);
return -errno;
r = -errno;
if (!i->argument && errno == EROFS && stat(path, &st) == 0 &&
(i->type == CREATE_FILE || st.st_size == 0))
goto check_mode;

return log_error_errno(r, "Failed to create file %s: %m", path);
}

if (i->argument) {
Expand All @@ -1012,6 +1016,7 @@ static int write_one_file(Item *i, const char *path) {
if (stat(path, &st) < 0)
return log_error_errno(errno, "stat(%s) failed: %m", path);

check_mode:
if (!S_ISREG(st.st_mode)) {
log_error("%s is not a file.", path);
return -EEXIST;
Expand Down Expand Up @@ -1154,6 +1159,10 @@ static int create_item(Item *i) {

log_debug("Copying tree \"%s\" to \"%s\".", resolved, i->path);
r = copy_tree(resolved, i->path, false);

if (r == -EROFS && stat(i->path, &st) == 0)
r = -EEXIST;

if (r < 0) {
struct stat a, b;

Expand Down

0 comments on commit f44b28f

Please sign in to comment.