[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 11 02:30:27 PDT 2011
On Tue, May 10, 2011 at 06:57:11PM +0200, Lennart Poettering wrote:
> 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!
Works for me. Tnx.
> > - 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.
Ok
> > - 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.
Yes, that looks better than my patch.
Michael
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the systemd-devel
mailing list