Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Feb 2003 17:01:31 -0500
From:      taxman <taxman@acd.net>
To:        Mike Meyer <mwm-dated-1046887059.c1545d@mired.org>, Cliff Sarginson <cls@raggedclown.net>
Cc:        FreeBSD Questions <FreeBSD-questions@FreeBSD.org>
Subject:   Re: single user mode
Message-ID:  <200302281701.31777.taxman@acd.net>
In-Reply-To: <15967.41747.67024.941224@guru.mired.org>
References:  <20030227202359.GA4488@raggedclown.net> <15967.41747.67024.941224@guru.mired.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 28 February 2003 12:57 pm, Mike Meyer wrote:
> Since nobody else stepped forward with an answer, I'll try....
>
> In <20030227202359.GA4488@raggedclown.net>, Cliff Sarginson 
<cls@raggedclown.net> typed:
> > No I can think of kludgy ways to do this, but I want to know the way
> > it should be done. How can you tell from with a shell script whether you
> > are in single-user mode or not ?
>
> The difference between starting single-user and starting multi-user is
> that init just starts a shell in one case, and in the other it runs
> /etc/rc then deals with /etc/ttys. Shutting down to single-user shuts
> down the things in /etc/ttys - and anything else - then launches a
> shell.  There doesn't appear to be a way to ask init if it's running
> in single-user or multi-user mode.
>
> I'd say the best way is to look for a shell process with a ppid of
> 1. This can be fooled by having a shell started in /etc/ttys. Looking
> for things to be running in multi-user mode depends on them running,
> which may fail during (ab)normal system operation.
>
>
> Might I suggest that you're not really worried about being
> single-user, but instead worried about some condition that is usually
> true in single-user mode (quiescent file systems, no network daemons,
> etc)? If that's the case, you'd probably be better off checking that
> condition than checking for single-user mode. After all, given any
> assumption you make about single-user mode, I can violate that
> assumption if I really want to.

Mike, good points.  I don't think there is an elegant way of doing it either. 
To that end I don't think there is a truly important distinction anyway. If 
you're just looking for the simple answer, Cliff, checking if you can switch 
to another virtual terminal, and looking at the output of ps and perhaps 
mount, should tell you which one you're in.  Presuming you get use to the 
output of those commands in both scenarios.

Tim

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302281701.31777.taxman>