Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 299140 - sys-apps/preload-0.6.4-r1: race condition in init script
Summary: sys-apps/preload-0.6.4-r1: race condition in init script
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Pacho Ramos
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 310511
  Show dependency tree
 
Reported: 2009-12-31 17:34 UTC by Ambroz Bizjak
Modified: 2010-09-07 12:11 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch for preload init script (preload-0.6.4.init.in.patch,1013 bytes, patch)
2009-12-31 17:35 UTC, Ambroz Bizjak
Details | Diff
patch for preload init script (preload-0.6.4.init.in.patch,1011 bytes, patch)
2009-12-31 17:53 UTC, Ambroz Bizjak
Details | Diff
init script (preload,1.03 KB, text/plain)
2010-04-26 20:32 UTC, Ambroz Bizjak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ambroz Bizjak 2009-12-31 17:34:04 UTC
The init script in preload invokes start-stop-daemon to start the preload daemon, with the option to create a pid file, then attempts to ionice the pid in the pid file. This is wrong, as the pid file may not be available after start-stop-daemon returns. On my x86 system startup is randomly reported to fail because the pid file does not exist when ionice is called; the daemon is however started and the pid file eventually created.

Solution is to start the daemon with ionice. The pid of the daemon will be the same the pid of the ionice process, because it uses fork(), so this is correct.

Reproducible: Sometimes

Steps to Reproduce:
Comment 1 Ambroz Bizjak 2009-12-31 17:35:37 UTC
Created attachment 214782 [details, diff]
patch for preload init script

This patch solves the problem by starting preload with ionice.
Comment 2 Ambroz Bizjak 2009-12-31 17:53:06 UTC
Created attachment 214785 [details, diff]
patch for preload init script

expand options to arguments...
Comment 3 Wormo (RETIRED) gentoo-dev 2010-01-01 21:33:34 UTC
Thanks for the patch, looks like a good solution. Assigning to maintainer.
Comment 4 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2010-03-28 04:08:44 UTC
I no longer use this application and have dropped maintainer-ship.
Comment 5 Pacho Ramos gentoo-dev 2010-04-18 09:09:22 UTC
With your patch, preload no longer starts :-(, I simply get:
 * Starting preload ...                         [ !! ]

The problem is that I don't know where it is failing, I simply checked that, if I force it to run without ionice (I mean, I make it EXEC="/usr/sbin/preload" and ARGS=() ) it succeeds 
Comment 6 Ambroz Bizjak 2010-04-25 00:03:18 UTC
I cannot reproduce this. You may be giving invalid options to ionice. Try running the resulting command by hand.
Comment 7 Pacho Ramos gentoo-dev 2010-04-25 12:40:52 UTC
I have added the following to init.d to test:
        echo ${PIDFILE}
        echo "$EXEC"
        echo "${ARGS[@]}"
        echo ${PRELOAD_LOGFILE:-/var/log/preload.log}
        echo ${PRELOAD_VERBOSITY:-1}
        echo ${PRELOAD_NICE:-15}
        echo ${PRELOAD_STATEFILE:-""}
        echo ${PRELOAD_OPTS}

Resulting in:
 * Starting preload ...
/var/run/preload.pid
/usr/bin/ionice
-c3 /usr/sbin/preload
/var/log/preload.log
1
15
/var/lib/preload/preload.state
                                                                  [ !! ]

But it seems to run when manually running:
# start-stop-daemon --start --quiet --background --make-pidfile --pidfile /var/run/preload.pid --exec /usr/bin/ionice -- -c3 /usr/sbin/preload -l /var/log/preload.log -V 1 -n 15 -s /var/lib/preload/preload.state -f
# echo $?
0

:-/
Comment 8 Ambroz Bizjak 2010-04-26 20:32:02 UTC
Created attachment 229317 [details]
init script

Looks like something is having problems with arrays. Try this one.
Comment 9 Pacho Ramos gentoo-dev 2010-04-26 20:43:43 UTC
Sadly still the same :-(

Are you using baselayout-2/openrc ? I am still using baselayout-1 (that runs scripts using bash instead of dash)
Comment 10 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2010-09-06 16:47:18 UTC
The more correct approach is to start s-s-d through ionice (the priority descends to the child process). I've attached a fixed init.d script to bug #310511.
Comment 11 Pacho Ramos gentoo-dev 2010-09-07 12:11:32 UTC
+*preload-0.6.4-r2 (07 Sep 2010)
+
+  07 Sep 2010; Pacho Ramos <pacho@gentoo.org> +preload-0.6.4-r2.ebuild,
+  +files/preload-0.6.4.init.in-r1:
+  Revision bump to fix race condition (bug #299140 by Ambroz Bizjak) and
+  make it POSIX compliant (bug #310511 by Michał Górny), thanks a lot to
+  Michał for providing the new init.d script.