开发者

LSCopyApplicationURLsForURL is not working with root

LSCopyApplicationURLsForURL is not returning all applications when I run the xcode with debug executable as root.If run with admin it is returning all install开发者_StackOverflow中文版ed apps.

Why is this strange behaviour any ideas.

Regards, Akbar


Each user on a Mac OS X system has their own Launch Services database cache file. The exact set of currently "installed" (or known) applications for one user may not necessarily match the set of known apps for another user, including the root user. You will likely need to wrap your LS commands like in the following code:

int err = 0;
uid_t uid = getuid();
uid_t euid = geteuid();

if (uid != euid) {
    err = seteuid(uid);
    if (err != 0) {
        NSLog(@"seteuid(uid) returned %d", err);
    }
}

// do your LS commands, etc.

// then restore root privs:
err = seteuid(euid);
if (err != 0) {
    NSLog(@"seteuid(euid) returned %d", err);
}

(Note that I am assuming here that you are not logged in the GUI as the root user, in which case the above method isn't going to work since both the uid and the euid would be the same).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜