Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
I have an application with 2 class in 2 files and 2 method in classes!

I use NSRunloop and NSTimer to create a daemon.I add one of the methods to nsrunloop(this method call second method in another class).

i create a plist file for loading and startuping daemon.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>Label</key>
	<string>com.daemon.user</string>
	<key>OnDemand</key>
	<false/>
	<key>ProgramArguments</key>
	<array>
		<string>/Library/Application Support/daemon.app/Contents/MacOS/daemon</string>
	</array>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>

when i loading daemon work good.but when i logout and login or reboot the Mac OS X, daemon not work and status of daemon is -6.

Code:
launchctl list | grep com.daemon
-	-6	com.daemon.user

what's wrong?
 
Last edited:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
when i loading daemon work good.but when i logout and login or reboot the Mac OS X, daemon not work and status of daemon is -6.

If the status is negative it represents the negative of the signal that killed the job. See the man page.

The signal that match your number according to the kill man page is:

6 ABRT (abort)
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
If the status is negative it represents the negative of the signal that killed the job. See the man page.

The signal that match your number according to the kill man page is:

6 ABRT (abort)

What this happen? I want my Daemon work forever! i want the daemon stop only when system is reboot.and after reboot again startup.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
What this happen? I want my Daemon work forever! i want the daemon stop only when system is reboot.and after reboot again startup.

I don't know I did not write the daemon, but if you look at the man page of launchctl you see this:

The second column displays the last exit status of the job. If the number in this column is negative, it represents the negative of the signal which killed the job. Thus, "-15" would indicate that the job was terminated with SIGTERM. The third column is the job's label.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I missed one thing in your plist. What version of OS X are you using? The OnDemand key has been deprecated in 10.5 and replaced with KeepAlive. So if you are using 10.5 or a more recent version, change it.
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
I missed one thing in your plist. What version of OS X are you using? The OnDemand key has been deprecated in 10.5 and replaced with KeepAlive. So if you are using 10.5 or a more recent version, change it.

Read about the RunAtLoad key for launchd plists.

I use both of them together.but face with same problem.
* After logout and login when i unload the daemon and load again works properly!
Any idea?
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
Solved

in source code i used stringByAppendingString when i logout and login again value of appending string is null.so application aborted!


Thanks all
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
Sorry but new problem

in source code i used stringByAppendingString when i logout and login again value of appending string is null.so application aborted!
I use this code snippet in application source code :

Code:
NSDictionary *activeApp = [[NSWorkspace sharedWorkspace] activeApplication];
            appName = (NSString*)[activeApp objectForKey:@"NSApplicationName"];

i use this code for getting active(focused application's) name.application works good but when i logout and login again appName variable got null value!

* this code snippet exist in a method.i add method to nsrunloop.
* .plist file exist in first post
 

mehdies

macrumors member
Original poster
Jun 10, 2012
41
0
I use this code snippet in application source code :

Code:
NSDictionary *activeApp = [[NSWorkspace sharedWorkspace] activeApplication];
            appName = (NSString*)[activeApp objectForKey:@"NSApplicationName"];

i use this code for getting active(focused application's) name.application works good but when i logout and login again appName variable got null value!

* this code snippet exist in a method.i add method to nsrunloop.
* .plist file exist in first post

I find out when restart the daemon,it's works well! first i unload the daemon and load again with blow commands :

Code:
launchctl unload /Library/LaunchDaemons/daemon.plist
Code:
launchctl load /Library/LaunchDaemons/daemon.plist
I have another daemon(second daemon) like mentioned daemon when first daemon got null second daemon restart first daemon.but not works!

i use mentioned commands in second daemon like below :

Code:
 system("launchctl unload /Library/LaunchDaemons/daemon.plist");
Code:
  system("/bin/launchctl load /Library/LaunchDaemons/daemon.plist");

but these commands can't restart daemon.when i remove load command unload command works.

any solution?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.