On Sun, Apr 30, 2006 at 12:32:18AM +0200, Ola Lundqvist wrote: > Thanks for the patch. It would be nice if you could update the > changelog items as well in the patch.
Done. > On Sat, Apr 29, 2006 at 03:59:40PM +0200, Marc Haber wrote: > > 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. > > Shouldn't the locking be moved to after the sleep? Yes. Stupid me. New patch attached. > I also think that we should have it configurable if it should break or > wait, when if finds a previous lock. If it finds a previous lock, it waits for ten iterations, which is about five minutes. If another cron-apt is really running, it should be finished in that time, which causes "our" process to just start another iteration right after the last one finished. If the other cron-apt has not finished by that time, and we break, no harm is done since a cron-apt run has just finished. Stale locks cannot happen since we use -p. To make it short - this does not need to be configurable. > > 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. > > Yes it is a bit hidden... But there are some documentation... Thanks for trying to explain. I didn't fully understand it, maybe because it is late and I am not at my full concentration rate. I'll re-read it tomorrow. 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-30 00:53:19.147721000 +0200 @@ -20,6 +20,9 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Changes: +# 2006-04-30 Marc Haber <[EMAIL PROTECTED]> +# Move dotlock code so that now the entire cron-apt run +# is protected by locking # 2005-10-09 Marc Haber <[EMAIL PROTECTED]> # Add $APTCOMMAND to the CRON-APT line output. # 2005-10-07 Ola Lundqvist <[EMAIL PROTECTED]> @@ -270,6 +273,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. @@ -401,6 +407,25 @@ fi fi +################## try to take out a lock, terminate if unsuccessful ########## + +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 + +################## initialize various log files ############################## + cp "$INITLOG" "$RUNMAIL" cp "$INITLOG" "$RUNLOG" cp "$INITLOG" "$RUNSYSLOG" @@ -424,34 +449,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