osx - Daemon to know when a user logs into the MAC -


I have a daemon (written in obje c), and I do some action when some users log in Is it possible to know this for a daemon when a specific user logs in or out of OSX? Are any notifications thrown when logged in? I would like to avoid using logging items or launch agents. And I would like to avoid voting on the timer to check the logging user. Use SCDynamicStoreCopyConsoleUser to get the console user name.

  CFFRing console console username = zero; UID_TUID; Gid_t gid; consoleUserName = SCDynamicStoreCopyConsoleUser (NULL, & amp; uid, & amp; gid);   

store consoleUserName in a member variable now SCDynamicStoreCreate

  system configuration using SCDynamicStoreRef Store Creates a session to interact with the dynamic store created by the server; CFStringRef key; CFArrayRef key; CFRunLoopSourceRef rls; store = SCDynamicStoreCreate (NULL, CFSTR ("com.apple.dts.ConsoleUser"), callback function, NULL); // Set up this to inform us when the console changes the user value key = SCDynamicStoreKeyCreateConsoleUser (NULL); Emphasize (key! = Null); Keys = CFRCR (faucet, (denote zero **) and key, 1, and KCTAPEreel books); // emphasis (keys! = Null); Success = SCDynamicStoreSetNotificationKeys (stores, keys, NULL); // emphasis (success); // Add it to Ralph; rls = SCDynamicStoreCreateRunLoopSource (Zero, Store, 0); // emphasis (rls! = NULL); CFRunLoopAddSource (CFRunLoopGetCurrent (), rls, kCFRunLoopDefaultMode); MConsoleUserName = CopyCurrentConsole username (store); CFRunLoopRun (); CFRunLoopSourceInvalidate (RLS); CFRelease (RLS); CFRelease (key); CFRelease (key); CFRelease (store);   

The implementation callBackFunction function. You will get a callback when the console user value changes

  Fixed zero callback function (SCDynamicStoreRef Store, CFArrayRef is changed, zero * info) {CFStringRef currentConsoleUser; Boolean revenge; // Get current console user CurrentConsoleUser = CopyCurrentConsole username (store); If (currentConsoleUser == faucet) {return; } DidChange =! CFQW (stored value, current resource user); If (! [CurrentConsoleUser isEqualToString: @ "loginwindow"]) {// Pass this method in some method}}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -