1999-02-22 Alexandre Oliva <oliva@dcc.unicamp.br>
+ * ltmain.in: create on-demand executable as $progdir/$$-$program,
+ and rename it to $progdir/$program only when it's finished, to
+ avoid race conditions. We can still get the program linked
+ multiple times, if multiple instances are started simultaneously
+ and the program does not exist, but they are very unlikely to
+ interfere with each other. There's still a possibility that one
+ process removes the $program another has just created, and doesn't
+ replace it before the other tries to run it, in a system whose
+ `mv' is not atomic, so it will $rm then $mv, but so what? :-)
+ Locking files have been avoided to prevent dead-locks in case they
+ are left over after a reboot or crash.
+
* TODO: removed ILD, soon to be merged, and added convenience
libraries docs
fi
if test "$shlibpath_overrides_runpath" != yes; then
- compile_for_build_command=`echo "X$compile_command" | $Xsed -e "s%@BUILD_LIBDIRS_FLAGS@%$build_libdirs_flags%" -e "s%@BUILD_RPATH@%$build_rpath%" -e "s%@HARDCODE_BUILD_LIBDIRS@%$build_libdirs%" -e 's%@THISDIR@%\$thisdir%g' -e 's%@OUTPUT@%\$progdir/\$program%g'`
+ compile_for_build_command=`echo "X$compile_command" | $Xsed -e "s%@BUILD_LIBDIRS_FLAGS@%$build_libdirs_flags%" -e "s%@BUILD_RPATH@%$build_rpath%" -e "s%@HARDCODE_BUILD_LIBDIRS@%$build_libdirs%" -e 's%@THISDIR@%\$thisdir%g' -e 's%@OUTPUT@%\$progdir/\$file%g'`
fi
# Replace the output file specification.
progdir=\"\$thisdir/$objdir/$objdir\"
if test ! -f \"\$progdir/\$program\" || \\
- { newestfile=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | sed 1q\`; \\
- test \"X\$newestfile\" != \"X\$progdir/\$program\"; }; then
- if test ! -d \"\$progdir\"; then
- $mkdir \"\$progdir\"
+ { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | sed 1q\`; \\
+ test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+ file=\"\$\$-\$program\"
+
+ $rm \"\$progdir/\$file\""
+
+ echo >> $output "\
+
+ # link executable that uses uninstalled libraries
+ if (cd \"\$thisdir\" && $compile_for_build_command); then :
else
- $rm \"\$progdir/\$program\"
+ $rm \"\$progdir/\$file\"
+ exit 1
fi
- # link executable that uses uninstalled libraries
- (cd \$thisdir && $compile_for_build_command) || exit 1
+ $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+ { $rm \"\$progdir/\$program\";
+ $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+ $rm \"\$progdir/\$file\"
fi"
fi