summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-16 06:58:33 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:58:58 +0200
commitbe2283cf9e565994ae6db0db57a555c6db704fe0 (patch)
treeed271eeac4c0a0bc07256a2dd5d7d4d53c80ac2d /src/basic/fs-util.c
parent6aa3ef01f65ac3ca0d949d4534f8bcd796f1a053 (diff)
login,user-sessions: always warn when we fail to remove nologin file
This usually is very annoying to users who then cannot log in, so make sure we always warn if that happens (selinux, or whatever other reason). This reverts a790812cb349c5cef95d1b4a20fc80ca08d3a145.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index a72f47912..87116d618 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -567,6 +567,17 @@ int tmp_dir(const char **ret) {
return tmp_dir_internal("/tmp", ret);
}
+int unlink_or_warn(const char *filename) {
+ if (unlink(filename) < 0 && errno != ENOENT)
+ /* If the file doesn't exist and the fs simply was read-only (in which
+ * case unlink() returns EROFS even if the file doesn't exist), don't
+ * complain */
+ if (errno != EROFS || access(filename, F_OK) >= 0)
+ return log_error_errno(errno, "Failed to remove \"%s\": %m", filename);
+
+ return 0;
+}
+
#if 0 /// UNNEEDED by elogind
int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
char path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];