PDA

View Full Version : Debugging Daemons




mehdies
Jun 18, 2013, 01:23 AM
I have a daemon with source code.this daemon run with :
launchctl load /Library/LaunchDaemons/deamon.plist

How can i debug that?



chown33
Jun 18, 2013, 01:31 AM
I have a daemon with source code.this daemon run with :
launchctl load /Library/LaunchDaemons/deamon.plist

How can i debug that?

Debug what? The "deamon.plist" you didn't post, or the daemon source code you didn't post?

ArtOfWarfare
Jun 18, 2013, 06:53 AM
I have a daemon with source code.this daemon run with :
launchctl load /Library/LaunchDaemons/deamon.plist

How can i debug that?

Unit testing and logging statements to the console

mehdies
Jun 19, 2013, 07:52 AM
Debug what? The "deamon.plist" you didn't post, or the daemon source code you didn't post?
.plist source 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>

----------

I must be debug daemon in Xcode.with breakpoint.or logging messages to console.


Thanks

chown33
Jun 19, 2013, 01:44 PM
.plist source 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>

What user owns the program being run as a daemon? If it's not root, then launchd may not launch it.

Also, what are the read/write permissions on the directories leading to the executable? What about on the executable itself?


Exactly what have you read about making daemons? Be specific.

The central Apple document is this:
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html

TN2083 (https://developer.apple.com/library/mac/#technotes/tn2083/_index.html) also contains a wealth of information.

If you haven't read either document, you should do so.

From TN2083, under the heading title "Daemon Security Considerations":
When you install your daemon, make sure that you set the file system permissions correctly. Apple recommends that daemons be owned by root, have an owning group of wheel, and use permissions 755 (rwxr-xr-x) for executables and directories, and 644 (rw-r--r--) for files. In addition, every directory from your daemon up to the root directory must be owned by root and only writable by the owner (or owned by root and sticky). If you don't do this correctly, a non-admin user might be able to escalate their privileges by modifying your daemon (or shuffling it aside).




I must be debug daemon in Xcode.with breakpoint.or logging messages to console.

You should test and debug your program before trying to run it as a launch daemon. If it can only run with root privileges, then make a shell script that will run it as root, and test it that way.

You should also test and debug your plist by having it run a safe program that does nothing.

After both things have been tested and confirmed to work separately (your program and your plist), you can run your program as a launch daemon and confirm it works in that environment.

Catfish_Man
Jun 20, 2013, 02:46 AM
I have a daemon with source code.this daemon run with :
launchctl load /Library/LaunchDaemons/deamon.plist

How can i debug that?

Attach to it with lldb's "process attach" command.