Poweroff does not work in upstart 0.5

Sandeep Puddupakkam (spuddupa) spuddupa at cisco.com
Tue Feb 24 05:28:17 GMT 2009


Hello all,

I was trying to fix a reboot problem in upstart and ran into an issue in
upstart for which there is a bug open [Bug 301715].

The reason this does not work is as follows.

When we do a proweoff "shutdown -P now", in the code in shutdown.c, we
set environment variable INIT_HALT="POWEROFF"

When rc0 is executed, the environment variables come in the order
INIT_HALT=POWEROFF RUNLEVEL=0 PREVLEVEL=3

 

In the upstart job file for rc0, we expect RUNLEVEL to be the first
environment variable. (start on runlevel 0). Since RUNLEVEL is not the
first variable, your rc0 job file is not executed.

Simply modifying the job file rc0's start on condition to 

start on runlevel RUNLEVEL=0

will make this work.

Alternatively, you can modify the shutdown.c file function
shutdown_now()

to do the following

 

    NIH_MUST (e = nih_sprintf (NULL, "RUNLEVEL=%s", runlevel));

    NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

    NIH_MUST (e = nih_sprintf (NULL, "PREVLEVEL=%s", prev_level()));

    NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

   /* set this environment variable after RUNLEVEL and PREVLEVEL are set
*/

    if (init_halt) {

        NIH_MUST (e = nih_sprintf (NULL, "INIT_HALT=%s", init_halt));

        NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

    }

instead of

    if (init_halt) {

        NIH_MUST (e = nih_sprintf (NULL, "INIT_HALT=%s", init_halt));

        NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

    }

 

    NIH_MUST (e = nih_sprintf (NULL, "RUNLEVEL=%s", runlevel));

    NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

    NIH_MUST (e = nih_sprintf (NULL, "PREVLEVEL=%s", prev_level()));

    NIH_MUST (nih_str_array_addp (&env, NULL, NULL, e));

 

This would pass the environment variable in the following order
RUNLEVEL, PREVLEVEL, INIT_HALT

 

The same fix applies when you do "shutdown -H now"

 

I have updated the bug with the same info I have provided here.

 

Thanks,

Sandeep

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/upstart-devel/attachments/20090223/35874138/attachment-0001.htm 


More information about the upstart-devel mailing list