Re: how to run NSApplicationMain() in child process?
Re: how to run NSApplicationMain() in child process?
- Subject: Re: how to run NSApplicationMain() in child process?
- From: "Stephen J. Butler" <email@hidden>
- Date: Fri, 10 May 2013 01:14:57 -0500
I didn't look at your code, but... one thing to note is that it is
absolutely not secure to run your daemon as root and display a GUI. I hope
that isn't part of your plan.
The OS X way to do this sort of thing is to write your daemon as a Launch
Agent (since it needs to interact with a logged in user). Using a launchd
plist file, you can tell launchd to monitor a TCP port/unix socket/mach
port/watched directory/etc and run your agent when there is activity. This
is nice since your agent can exit when it doesn't have anything to do, and
the system will regain resources.
Good place to start would be here:
http://developer.apple.com/library/mac/#technotes/tn2083/_index.html
And then here:
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html#//apple_ref/doc/uid/10000172i-SW1-SW1
On Wed, May 8, 2013 at 5:41 AM, Ondrej Holecek <email@hidden>wrote:
> Hi,
>
> I'm creating a picture viewer controlled from command-line (I call it
> xqiv which sould be an equivalent to http://www.klografx.net/qiv/ on
> linux). However, xqiv is slightly different.
>
> You have to run xqiv-daemon, which is the window-based application
> which handles global notifications sent by xqiv-command-line and
> displays the image(s). My idea is to have just one application xqiv
> which acts as both daemon and/or command-line tool together. If you
> run xqiv and the deamon is not running yet it forks and run the
> daemon. Parent would act as a commandline tool and child would be the
> daemon which stay on background. Parent would sent a notification to
> the forked child what image to display and exit. If the daemon is
> already running, then fork is not needed and it would just sent the
> notification.
>
> The question is, how to force NSApplicationMain() to run in child.
>
> The basic idea is to do something like this:
>
> if (already running) {
> return cmd_main(argc, argv);
> } else {
> if (fork() == 0) {
> return NSApplicationMain(argc, (const char **)argv);
> } else {
> return cmd_main(argc, argv);
> }
> }
>
> The real code is there: http://pastebin.com/7LD2dPK8
>
> When I run NSApplicationMain() in child process, it simply does
> nothing. What's wrong?
>
> I have already functional application there:
> https://github.com/smrt28/xqiv
>
> It is functional but daemon and command-line tool are two applications.
>
> let me note I'm the beginner in objc/cocoa development and this is my
> very first cocoa application.
>
> thanks,
>
> Ondrej
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden