Debugging Daemons

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

  1. mehdies macrumors member

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

    Aug 9, 2009
    Sailing beyond the sunset
    Debug what? The "deamon.plist" you didn't post, or the daemon source code you didn't post?
  3. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Unit testing and logging statements to the console
  4. mehdies thread starter macrumors member

    Jun 10, 2012
    .plist source code.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
    		<string>/Library/Application Support/</string>


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

  5. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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:

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


    Sep 13, 2001
    Portland, OR
    Attach to it with lldb's "process attach" command.

Share This Page