如何从 macOS 上的启动守护程序中枚举所有已登录用户会话?

huangapple go评论66阅读模式
英文:

How to enumerate all logged in user sessions from a launch daemon on macOS?

问题

从一个互动用户会话中,对于已登录的用户,我可以使用SessionGetInfo函数来获取调用进程的会话ID:

SecuritySessionId sessID;
SessionAttributeBits flags;

if (SessionGetInfo(callerSecuritySession, &sessID, &flags) == errSecSuccess) {
    printf("会话ID=%d", sessID);
}

但是,我如何从我的启动守护程序中枚举所有这些会话ID?或者如何获取所有当前登录用户的会话ID。

英文:

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.

答案1

得分: 1

有一个文档很差的 utmpx.h 函数集。出于这个特定原因,您需要使用 setutxentgetutxentendutxent 函数。查看此处的示例代码

英文:

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.

huangapple
  • 本文由 发表于 2023年2月27日 00:50:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75573538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定