Apologies in advance as this is only indirectly a Cocoa question (in that I’m 
trying to incorporate this data into my Cocoa app). Suggestions for a more 
suitable home for this question are welcome.

My app needs to display the login and logout times of all users on the mac (for 
macos 10.10 onwards). I’ve been playing with last and getutxent(), but I’m 
finding them very unreliable. last appears to roll over a new wtmp file quite 
at random, and often just as soon as I call it (via NSTask), giving me no info 
at all.

getutxent() doesn’t seem to record the last logout time of the current user at 
all. When I log out of my current session and call getutxent() after logging in 
again, I don’t get the last logout time (I also tried lastlogx, but that just 
kept returning NULL).

Here’s what I’m using for getutxent():

struct utmpx *bp;
time_t time;
setutxent_wtmp(0); 
while ((bp = getutxent()) != NULL)
{
        time = (time_t) bp->ut_tv.tv_sec;

        switch (bp->ut_type)
        {
                    
                case USER_PROCESS:
NSLog(@“\nUSER_PROCESS (login): %s\t%s\t%d\t%hd\t%s\t%s\t%s\t\n", bp->ut_user, 
bp->ut_id, bp->ut_pid, bp->ut_type, ctime(&time), bp->ut_host, bp->ut_line);    
         

break;
                    
                case DEAD_PROCESS:
                NSLog(@“\nDEAD_PROCESS (logout): 
%s\t%s\t%d\t%hd\t%s\t%s\t%s\t\n", bp-
                >ut_user, bp->ut_id, bp->ut_pid, bp->ut_type, ctime(&time), 
bp->ut_host, bp->ut_line);
                
                break;

          case LOGIN_PROCESS:
                        NSLog(@“\nLOGIN_PROCESS (?):  
%s\t%s\t%d\t%hd\t%s\t%s\t%s\t\n", bp->ut_user, 
                        bp->ut_id, bp->ut_pid, bp->ut_type, ctime(&time), 
bp->ut_host, bp->ut_line);
                        
                        break;
        
                default:
                       break;

        }
}

endutxent();


Does anyone know of a reliable way to get users' last logout times?


TIA


Phil


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to