Debugging Daemons

Discussion in 'Mac Programming' started by mehdies, Jun 17, 2013.

  1. macrumors member

    Joined:
    Jun 10, 2012
    #1
    I have a daemon with source code.this daemon run with :
    Code:
    launchctl load /Library/LaunchDaemons/deamon.plist
    
    How can i debug that?
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    Debug what? The "deamon.plist" you didn't post, or the daemon source code you didn't post?
     
  3. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    Unit testing and logging statements to the console
     
  4. thread starter macrumors member

    Joined:
    Jun 10, 2012
    #4
    .plist source code.
    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
     
  5. macrumors 603

    Joined:
    Aug 9, 2009
    #5
    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/...al/BPSystemStartup/Chapters/Introduction.html

    TN2083 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).



    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.
     
  6. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #6
    Attach to it with lldb's "process attach" command.
     

Share This Page