From an interactive user session for a logged in user I can use SessionGetInfo function to obtain the calling process' session ID:
SecuritySessionId sessID;
SessionAttributeBits flags;
if(SessionGetInfo(callerSecuritySession,
&sessID,
&flags) == errSecSuccess)
{
printf("session ID=%d", sessID);
}
But how do I enumerate all such session IDs from my launch daemon? Or session IDs for all currently logged in users.
There's a badly documented utmpx.h
set of functions. And for that specific reason you would need to use setutxent
, getutxent
, endutxent
functions. Check a code example here.