site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com if ((ut = fopen(_PATH_UTMP, "r")) == NULL) err(1, "%s", _PATH_UTMP); This file utmp does not appear to exist on 10.5. - -- Terry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... 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: (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. This email sent to site_archiver@lists.apple.com