Comment 7 for bug 303574

Revision history for this message
Sandeep (spuddupa) wrote : Re: poweroff does nothing (beside writting message)

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
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 is also true if you do "shutdown -H now"