objective c - Launching app from root account -
i developing cocoa gui app has objective-c daemon. daemon launched launchdaemon, gui launched using loginitems each user.
when update deployed need update daemon, simple, , update gui. able exit gui, replace app, , relaunch on each user account running on. daemon of course running root.
how can either: 1) root, quit , re-launch app in user's interface? 2) root, quit , re-launch particular loginitem each user logged it?
i have tried searching , there lots of discussions including similar question, there doesn't appear working solution available.
any appreciated.
i believe nsdistributednotificationcenter should work this. note using nsdistributednotificationcenter communicate between processes in different user accounts not, in , of itself, require root privileges.
to coordination between user accounts, might distinguish instance of gui app , daemon active , in control, , instances passive. can use nsworkspace's notifications (nsworkspacesessiondidbecomeactivenotification, nsworkspacesessiondidresignactivenotification) determine when user switches between user accounts, etc. , have instances set accordingly.
say gui app , daemon have instances running in 3 different user accounts. if in active user account, want begin update process, use nsdistributednotificationcenter tell other instances shutdown immediately, example. that, you'd define following.
in .h file, declare names of different notifications:
extern nsstring * const mdshouldterminateimmediatelynotification;
in (an) implementation file, create names, , set class interested in distributed notification name, etc.:
nsstring * const mdshouldterminateimmediatelynotification = @"mdshouldterminateimmediately"; - (id)init { if (self = [super init]) { [[nsdistributednotificationcenter defaultcenter] addobserver:self selector:@selector(shouldterminateimmediately:) name:mdshouldterminateimmediatelynotification object:nil]; } return self; } - (void)dealloc { [[nsdistributednotificationcenter defaultcenter] removeobserver:self]; [super dealloc]; } - (void)shouldterminateimmediately:(nsnotification *)notification { if (ourinstanceisincontrol == no) { [nsapp terminate:nil]; } }
in class initiate update process, you'd send notification:
- (void)beginupdate { [[nsdistributednotificationcenter defaultcenter] postnotificationname:mdshouldterminateimmediatelynotification object:[self description] // or nil userinfo:nil options:nsnotificationdeliverimmediately | nsnotificationposttoallsessions]; // continue }
that should @ least beginning work with, i'd think....
actually, if talking having 1 single daemon instance running root in user accounts, may need consider factoring part out launchd agent type process (background process, runs @ user level, each user account have own instance).
for more info:
Comments
Post a Comment