bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: who -r


From: ray hammond
Subject: RE: who -r
Date: Sun, 16 Apr 2006 14:13:49 +0100

Thanks Bob, that helps a lot.  

I should give myself a kick as I should have known "S" stood for single user
mode (obvious when someone points it out).  By the way I am running Suse 10
OSS, which uses /var/run/utmp.  

After I emailed you I grabbed the source for both. 
Extracts from the source are below.  

---------------------------------------------
runlevel source

if (ut->ut_type == RUN_LVL) 
{
prev = ut->ut_pid / 256;
if (prev == 0) prev = 'N';
printf("%c %c\n", prev, ut->ut_pid % 256);
......;
}

---------------------------------------------
who -r source

static void print_runlevel (const STRUCT_UTMP *utmp_ent)
{
static char *runlevline, *comment;
unsigned char last = UT_PID (utmp_ent) / 256;
unsigned char curr = UT_PID (utmp_ent) % 256;

if (!runlevline)
runlevline = xmalloc (strlen (_("run-level")) + 3);
sprintf (runlevline, "%s %c", _("run-level"), curr);

if (!comment)
comment = xmalloc (strlen (_("last=")) + 2);
sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);

print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
"", "", comment, "");

return;
}

----------------END OF SOURCE -----------------------------

As you can see, both commands print different values for the previous
runlevel.  It would be great if both adhered to the same logic, however as
you indicate "legacy" must explain the differences.

Also you pointed out that the manual for runlevel stats "If there is no
previous system runlevel, the letter N will be printed instead".  

My understanding of the code for "who -r" is that the code uses tenary
operator i.e. (last == 'N') ? 'S' : last)), to substitute the value of "N"
(when found) for the value of "S".  Again I guess legacy, or do all
Linux/Unix O/S boot into single user mode first?


Thanks

Ray Hammond

-----Original Message-----
From: Bob Proulx [mailto:address@hidden 
Sent: 16 April 2006 05:59
To: ray h
Cc: address@hidden
Subject: Re: who -r

ray h wrote:
> I was trying to find out what the result of "who -r" means, I underatand  
> it prints the current and previous runlevel, however "info who" yeilds no

> explanation of what "S" means for the previous runlevel.
> 
>      run-level 5  Apr 15 20:33                   last=S

You did not say what system you are using.  The results are somewhat
system dependent.

The who command digs information from the system utmp file.  (In old
systems this used to be /etc/utmp and various information was logged
there.  In modern systems that is usually /var/run/utmp or other
"var"iable location.)  On my Debian system some documentation on utmp
may be found in the Linux Programmer's Manual (e.g. man utmp).

  man utmp

The 'who -r' command reports information logged to utmp about the run
level.  The run level logged to utmp indicates the state of the "init"
process.  The init process logs its runlevel to the utmp file whenever
it changes.  Information about init may be found in the init man page.

  man init

> The runlevel command does not print "S" for the last runlevel, it prints  
> N.  Why are these different and can we have the switch added to the  
> docuementation.

The "S" runlevel is the single user mode runlevel.  It is meant for
system activities.

The runlevel manual says:

  If there is no previous system runlevel, the letter N will be
  printed instead.

The who command prints "S" if the last runlevel is "N".  This is most
likely for compatibility with legacy Unix systems which print S for
the previous runlevel.  [But it may be the legacy systems tend to boot
to Single user mode first and from there continue to multiuser.]

Bob


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.4.1/313 - Release Date: 15/04/2006






reply via email to

[Prev in Thread] Current Thread [Next in Thread]