[systemd-devel] [PATCH 2/2] user-sessions: don't report errors unless /{etc, run}/nologin exists and cannot be removed
Michael Olbrich
m.olbrich at pengutronix.de
Wed May 4 02:01:55 PDT 2011
on a read-only file-system 'unlink' returns EROFS (Read-only file
system) even if the file does not exists. To avoid false errors,
check if the file exists first.
---
I'm not sure if this is the correct fix, but generating an error when
/etc/nologin never existed is certainly a bug.
Regards,
Michael
src/user-sessions.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/user-sessions.c b/src/user-sessions.c
index 4518d95..c48b6c1 100644
--- a/src/user-sessions.c
+++ b/src/user-sessions.c
@@ -41,13 +41,14 @@ int main(int argc, char*argv[]) {
if (streq(argv[1], "start")) {
int q = 0, r = 0;
+ struct stat buffer;
- if (unlink("/run/nologin") < 0 && errno != ENOENT) {
+ if (stat("/run/nologin", &buffer) == 0 && unlink("/run/nologin") < 0 && errno != ENOENT) {
log_error("Failed to remove /run/nologin file: %m");
r = -errno;
}
- if (unlink("/etc/nologin") < 0 && errno != ENOENT) {
+ if (stat("/etc/nologin", &buffer) == 0 && unlink("/etc/nologin") < 0 && errno != ENOENT) {
log_error("Failed to remove /etc/nologin file: %m");
q = -errno;
}
--
1.7.2.3
More information about the systemd-devel
mailing list