On Wed, Mar 22, 2006 at 10:15:40PM +0100, Ola Lundqvist wrote: > Patch is welcome.
A first try is attached. This basically moves the lock that we already use to a more global level, and work rudimenatarily. It is not well tested though. One thing I have not gotten right is message handling: The message printed if /usr/bin/dotlockfile is not found seems to go nowhere if the cron-apt run won't generate output otherwise. I have not yet understood the message/log file handling with the createdivinfo stuff. It is kind of underdocumented. Greetings Marc -- ----------------------------------------------------------------------------- Marc Haber | "I don't trust Computers. They | Mailadresse im Header Mannheim, Germany | lose things." Winona Ryder | Fon: *49 621 72739834 Nordisch by Nature | How to make an American Quilt | Fax: *49 621 72739835
--- cron-apt 2006-04-29 15:32:33.424994750 +0200 +++ /usr/sbin/cron-apt 2006-04-29 15:53:24.551185250 +0200 @@ -270,6 +270,9 @@ if [ -d "$TMPDIR" ] ; then rmdir "$TMPDIR" fi + if [ -x "/usr/bin/dotlockfile" ]; then + dotlockfile -u $LOCKFILE + fi } # Do the actual msg transfer. This reduce some duplications. @@ -386,9 +389,26 @@ exit 0 fi -############################### sleep ######################################### +################## try to take out a lock, terminate if unsuccessful ########## echo "CRON-APT RUN [$CONFIG]: $(date)" > $INITLOG +if [ -x /usr/bin/dotlockfile ] ; then + if ! dotlockfile -l -p -r 10 $LOCKFILE; then + # create log entry + echo > $MAIL "cannot acquire cron-apt lock." + onexit + exit 1 + fi +else + if [ -z "$NOLOCKWARN" ]; then + echo > $TEMP "WARNING: dotlockfile not installed. If you don't want to see this" + echo >> $TEMP " Warning any more, set NOLOCKWARN in the configuration file." + createerrorinfo "startup" + fi +fi + +############################### sleep ######################################### + if [ -n "$RUNSLEEP" ] ; then if [ $RUNSLEEP -gt 0 ] ; then if [ -z "$RANDOM" ] ; then @@ -424,34 +444,14 @@ grep -v "^[[:space:]]*$" | { while read LINE ; do echo "CRON-APT LINE: $APTCOMMAND $LINE" > "$TEMP" - if [ -x /usr/bin/dotlockfile ] ; then - if ! dotlockfile -l -p -r 10 $LOCKFILE; then - echo > $TEMP "cannot acquire apt lock." - RET=1 - else - UMASK_SAVE=$(umask) - umask $UMASK_RELAXED - $APTCOMMAND $OPTIONS $LINE >> $TEMP 2>&1 - RET=$? - umask $UMASK_SAVE - fi - dotlockfile -u $LOCKFILE - else - if [ -z "$NOLOCKWARN" ]; then - echo > $TEMP "WARNING: dotlockfile not installed. If you don't want to see this" - echo >> $TEMP " Warning any more, set NOLOCKWARN in the configuration file." - fi - UMASK_SAVE=$(umask) - umask $UMASK_RELAXED - $APTCOMMAND $OPTIONS $LINE >> $TEMP 2>&1 - RET=$? - umask $UMASK_SAVE - fi + UMASK_SAVE=$(umask) + umask $UMASK_RELAXED + $APTCOMMAND $OPTIONS $LINE >> $TEMP 2>&1 + RET=$? + umask $UMASK_SAVE if [ "$FILTERCTRLM" = "true" ]; then CTRLM="$(echo -e \\r)" < "$TEMP" sed "s/.*$CTRLM\(.\+\)/\1/" > "$FILTER" - #grep -v " -#" "$TEMP" > "$FILTER" cp "$FILTER" "$TEMP" fi if [ $RET -ne 0 ]; then