Setting environment variables under Snow Leopard advice.

View: New views
4 Messages — Rating Filter:   Alert me  

Setting environment variables under Snow Leopard advice.

by Benjamin Donnachie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I currently use a patched version of gpg-agent under launchd control,
which previously set the necessary environment variables so that they
were accessible system-wide using IPC and SetUserEnvironment.  The
plist looks like this:

<?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>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>com.sourceforge.macgpg2.gpg-agent</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/bin/gpg-agent</string>
                <string>--launchd</string>
                <string>--use-standard-socket</string>
                <string>--write-env-file</string>
        </array>
        <key>LimitLoadToSessionType</key>
        <string>Aqua</string>
        <key>ServiceIPC</key>
        <true/>
</dict>
</plist>

This worked fine under Leopard but under Snow Leopard the environment
variables are not being set.  I have had a look through the launchd
source, and ServiceIPC and SetUserEnvironment are still present and
the developer docs do not seem to cover this case.  As gpg-agent
caches passphrases it is not suitable for running on demand.  I could
modify the patch to accept paths from launchd but I would prefer to
leave gpg-agent with its default behaviour and just pass the necessary
environment variables back to Snow Leopard.

Consequently, I should be grateful for any advice regarding the
correct implementation under 10.6.  Below is an extract of Stéphane
Corthésy's gpg-agent launchd patch showing the IPC behaviour.

Many thanks,

Ben



Extract from the gpg-agent launchd patch:

        // Pass environment variables back to launchd.
         launch_data_t resp, tmp, tmpv, msg;

         msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
         tmp = launch_data_alloc(LAUNCH_DATA_DICTIONARY);

         tmpv = launch_data_new_string(strchr(infostr, '=') + 1); //
Skip variable name and equal sign
         launch_data_dict_insert(tmp, tmpv, "GPG_AGENT_INFO");
         launch_data_dict_insert(msg, tmp, "SetUserEnvironment");

         resp = launch_msg(msg);
         launch_data_free(msg); // Do NOT launch_data_free() on tmp, nor tmpv

         if (resp)
           {
             launch_data_free(resp);
           }
         else
           {
             log_error ("failed to pass environment variable
GPG_AGENT_INFO to launchd: %s\n", strerror (errno));
             kill (pid, SIGTERM);
             exit (1);
           }

         if (opt.ssh_support)
           {
             msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
             tmp = launch_data_alloc(LAUNCH_DATA_DICTIONARY);

             tmpv = launch_data_new_string(strchr(infostr_ssh_sock,
'=') + 1); // Skip variable name and equal sign
             launch_data_dict_insert(tmp, tmpv, "SSH_AUTH_SOCK");
             launch_data_dict_insert(msg, tmp, "SetUserEnvironment");

             resp = launch_msg(msg);
             launch_data_free(msg); // Do NOT launch_data_free() on
tmp, nor tmpv

             if (resp)
               {
                 launch_data_free(resp);
               }
             else
               {
                 log_error ("failed to pass environment variable
SSH_AUTH_SOCK to launchd: %s\n", strerror (errno));
                 kill (pid, SIGTERM);
                 exit (1);
               }
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: Setting environment variables under Snow Leopard advice.

by Benjamin Donnachie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/25 Benjamin Donnachie <benjamin@...>:
> I currently use a patched version of gpg-agent under launchd control,
> which previously set the necessary environment variables so that they
> were accessible system-wide using IPC and SetUserEnvironment.

Please ignore my message!  I continued looking into it after I posted
and it works again after changing the session type to System.

I think it was set to Aqua previously to ensure that Tiger systems ignored it!

Take care,

Ben
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: Setting environment variables under Snow Leopard advice.

by Benjamin Donnachie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/25 Benjamin Donnachie <benjamin@...>:
> Please ignore my message!  I continued looking into it after I posted
> and it works again after changing the session type to System.

Bit more testing and reading and it seems that background is the
session type I needed.

Ben
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev

Re: Setting environment variables under Snow Leopard advice.

by Benjamin Donnachie-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For the mailing list archives in case anyone has similar issues...

I just tested with LimitLoadToSessionType set back to Aqua, restarted
my system and Launchd under Snow Leopard is now behaving as it did
under Leopard.

Perhaps part of the 10.6.1 update?

Ben
_______________________________________________
launchd-dev mailing list
launchd-dev@...
http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev