Re: getutxent() not returning values when using 10.4u SDK
Re: getutxent() not returning values when using 10.4u SDK
- Subject: Re: getutxent() not returning values when using 10.4u SDK
- From: Terry Lambert <email@hidden>
- Date: Fri, 25 Jul 2008 12:45:30 -0700
On Jul 24, 2008, at 11:11 PM, Rosyna wrote:
I tried using the utmp code in http://www.opensource.apple.com/darwinsource/10.5.4/shell_cmds-118/w/w.c
but it gives an error, "/var/run/utmp: No such file or directory"
when attempting:
if ((ut = fopen(_PATH_UTMP, "r")) == NULL)
err(1, "%s", _PATH_UTMP);
This file utmp does not appear to exist on 10.5.
(Basically, my only goal here is to find how long the current user
has been logged in and doing it from a daemon safe framework/library.
The "w" source is bad example code for you to use, since it implies a
dependency on underlying implementation, depending on the manifest
constants you have in scope.
You could make the code variant based on getting the current version
by using the uname(3) library call and examining the "release" field
of the returned "struct utsname", and make your function decide to
either use utmp or utmpx based on that.
But really, the easiest way to make the code portable (including to
other platforms) is going to be to popen(3) the "last" command with
appropriate arguments, and parse its output using whitespace as field/
token separators.
-
Apropros the problem you are trying to solve, you are likely not going
to be happy doing this from a daemon in any case, since it's possible
to have multiple simultaneous sessions for the console user, it's
possible to have non-console users (ssh, telnet, ftp, etc.), and,
using Fast User Switching, its possible to have multiple concurrent
(but non-simultaneous) console users.
The problem is that daemons are effectively their own session, and are
not specifically associated with any particular user session,
including the one that started them (unless it's started by a
particular session, and you grab the information before the daemon
actually backgrounds itself to disassociate itself from the user
session).
Unless you have the session information about the user you are asking
about, you are unlikely to get the answer you want. You may get *A*
answer, but you won't get *THE* answer.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden