[systemd-devel] [PATCH 2/2] user-sessions: don't report errors unless /{etc, run}/nologin exists and cannot be removed

Lennart Poettering lennart at poettering.net
Tue May 10 09:57:11 PDT 2011


On Wed, 04.05.11 11:01, Michael Olbrich (m.olbrich at pengutronix.de) wrote:

> 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 now commited a different fix for this. Please test!

> -                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;
>                  }

/run/nologin *must* be writable, hence this check is not really applicable.

> -                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;
>                  }

access(F_OK) is usually nicer than stat() for this purpose. Also, I
think we should do unlink() first, and suppress the error message for
EROFS only if the file really doesn't exist. The patch I commited now
does that.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list