Library search paths, daemon startupitem and launchd

Bradley Giesbrecht brad at pixilla.com
Mon Jan 25 13:23:22 PST 2010


On Jan 25, 2010, at 1:16 PM, Tom Davis wrote:

> Hello,
>
> I'm trying to write a portfile for iguanaIR (http://iguanaworks.net/projects/IguanaIR 
> ). I'm having difficulties starting a daemon using  
> startupitem.executable. When I try to start the daemon with:
>
> 	sudo launchctl load -w /Library/LaunchDaemons/ 
> org.macports.iguanaIR.plist
>
> igdaemon crashes. Here's part of the CrashReporter log:
>
> 	Dyld Error Message:
> 	  Library not loaded: libiguanaIR.dylib
> 	  Referenced from: /opt/local/bin/igdaemon
> 	  Reason: image not found
>
> The libiguanaIR.dylib library is part of the iguanaIR distribution  
> and is in /opt/local/lib after a port install. otool shows that  
> libiguanaIR.dylib is the only library without an absolute path:
>
> 	Rett:~ tom$ otool -L /opt/local/bin/igdaemon
> 	/opt/local/bin/igdaemon:
> 	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/ 
> CoreFoundation (compatibility version 150.0.0, 			current version  
> 550.13.0)
> 	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit  
> (compatibility version 1.0.0, current version 275.0.0)
> 	libiguanaIR.dylib (compatibility version 1.0.0, current version  
> 1.0.0)
> 	/opt/local/lib/libpopt.0.dylib (compatibility version 1.0.0,  
> current version 1.0.0)
> 	/opt/local/lib/libusb-0.1.4.dylib (compatibility version 9.0.0,  
> current version 9.4.0)
> 	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current  
> version 125.0.0)
>
> I'm guessing this is because it's not linked with the -l switch  
> because libiguanaIR.dylib is not installed at the time igdaemon is  
> built.
>
> My .profile is setup to search /opt/local/lib for libraries:
>
> 	Rett:~ tom$ env | grep LIB
> 	DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:
> 	LIBRARY_PATH=/opt/local/lib
> 	DYLD_LIBRARY_PATH=/Applications/MATLAB_R2009a.app/bin/mac:/ 
> Applications/MATLAB_R2009a.app/sys/os/mac:
>
> If I run igdaemon from the command line, everything works fine.
>
> If I copy libiguanaIR.dylib to /usr/local/lib and use launchctl,  
> everything works fine.  If I add the following lines to  
> org.macports.iguanaIR.plist:
>
> 	<key>EnvironmentVariables</key>
> 	<dict>
> 	 <key>DYLD_FALLBACK_LIBRARY_PATH</key> <string>/opt/local/lib</ 
> string>
> 	 </dict>
>
> or
> 	<key>WorkingDirectory</key>
> 	<string>/opt/local/lib</string>
>
> then everything works fine.
>
> /Library/LaunchDaemons must be started by sudo, But sudo strips  
> environmental variables such as DYLD_FALLBACK_LIBRARY_PATH for  
> security reasons.
>
> So, what is the correct way to get a daemon to search /op/local/lib?  
> Is there a way to add the EnvironmentVariables key to the launchctl  
> plist using portfile settings?

Don't know but greping turns up things like this that might be a  
direction to look in:

grep -R startupitem /opt/local/var/macports/sources/rsync.macports.org/ 
release/ports/

/opt/local/var/macports/sources/rsync.macports.org/release/ports/ 
databases/openldap/Portfile:startupitem.init	"PID=${prefix}/var/run/ 
slapd.pid"
/opt/local/var/macports/sources/rsync.macports.org/release/ports/ 
databases/openldap/Portfile:startupitem.start       "${prefix}/libexec/ 
slapd -u ldap -f ${prefix}/etc/openldap/slapd.conf"

Also might look at "man portfile".

// Brad



More information about the macports-dev mailing list