[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#151992: start-stop-daemon broken "--test --stop" combination (patch)

Package: dpkg 
Version: 1.10
Severity: normal

I noticed the bug while trying to restart Tomcat (tomcat4 package). 

Due to the fact that the executable name, and command name of tomcat, is
not what start-stop-daemon sould try to match (daemon is started with
java), we can't use "--test --start" to test if daemon is running, 
because we want to ommit --name, --exec, so that s-s-d doesn't tries to
match this, but we can't do that with --start.

But in "--test --stop" mode (the only one we can use to test without
specifying --name or --exec or --startas), the return code actually
returned depends of the number of processes _actually_ killed, but this
number is zero, because we are in test mode.

Test case:
  - start tomcat4 with '/etc/init.d/tomcat4 start'
  - check it is actually running
  - run :

   start-stop-daemon --test --stop  --pidfile /var/run/tomcat4.pid --user
tomcat4  --verbose

   What we expect is that this command test if it would stop the process,
and returns zero if yes. 

Actual result:

  Would send signal 15 to 3025.
  No process in pidfile `/var/run/tomcat4.pid' found running; none killed.

  return code is 1  (echo $?)

Relevant code portions:

        anykilled = 0; 
        retry_nr = 0;

        if (schedule == NULL) {
                do_stop(signal_nr, quietmode, &n_killed, &n_notkilled, 0);
                if (n_notkilled > 0 && quietmode <= 0)
                        printf("%d pids were not killed\n", n_notkilled);
                if (n_killed)
                        anykilled = 1;
                goto x_finished;

        if (!anykilled) {
                if (quietmode <= 0)
                        printf("No %s found running; none killed.\n",
                return exitnodo;
        } else {
                return 0;

/* return 1 on failure */
static void
do_stop(int signal_nr, int quietmode, int *n_killed, int *n_notkilled, int
        struct pid_list *p;


        *n_killed = 0;
        *n_notkilled = 0;

        if (!found)


        for (p = found; p; p = p->next) {
                if (testmode)
                        printf("Would send signal %d to %d.\n",
                               signal_nr, p->pid);

[ We actually see this printf message in testcase output ]

                else if ...

So what happens is that in test mode, n_killed isn't increased (do_stop),
then anykilled (run_stop_schedule) still is zero after do_stop, then in
x_finished: the exit code is 0.

A solution is to increase n_killed, even if we are in test mode :

--- start-stop-daemon.c.orig	2002-07-05 11:29:31.000000000 +0200
+++ start-stop-daemon.c	2002-07-05 11:29:55.000000000 +0200
@@ -941,9 +941,11 @@
 	for (p = found; p; p = p->next) {
	if (testmode)
	if (testmode) {
		printf("Would send signal %d to %d.\n",
		       signal_nr, p->pid);
  		else if (kill(p->pid, signal_nr) == 0) {
		push(&killed, p->pid);

This modification actually solves the problem described here, I did not
test it further, but it is clear it only affect "--test" mode, and it
affects it lightly, so I wouldn't expect side effects.

To UNSUBSCRIBE, email to debian-dpkg-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Reply to: