[systemd-devel] [PATCH 2/4] special shutdown targets will now cause manager to exit.

Lennart Poettering lennart at poettering.net
Fri Oct 1 09:33:58 PDT 2010


On Fri, 01.10.10 11:44, Gustavo Sverzut Barbieri (barbieri at profusion.mobi) wrote:

> 
> On Fri, Oct 1, 2010 at 10:54 AM, Lennart Poettering
> <lennart at poettering.net> wrote:
> > On Fri, 01.10.10 02:28, Gustavo Sverzut Barbieri (barbieri at profusion.mobi) wrote:
> >
> >> +++ b/src/target.c
> >> @@ -172,6 +172,14 @@ static int target_start(Unit *u) {
> >>          assert(t->state == TARGET_DEAD);
> >>
> >>          target_set_state(t, TARGET_ACTIVE);
> >> +
> >> +        if (unit_has_name(u, SPECIAL_REBOOT_TARGET))
> >> +                t->meta.manager->exit_code = MANAGER_REBOOT;
> >> +        else if (unit_has_name(u, SPECIAL_POWEROFF_TARGET))
> >> +                t->meta.manager->exit_code = MANAGER_POWEROFF;
> >> +        else if (unit_has_name(u, SPECIAL_HALT_TARGET))
> >> +                t->meta.manager->exit_code = MANAGER_HALT;
> >> +
> >>          return 0;
> >>  }
> >
> > Please don't do this. Instead just place a normal service in these
> > targets that uses "systemctl" or "kill" to ask PID 1 to do the right
> > operation here...
> 
> yes, this is hackish, but your solution does need some replication as
> I need to have it specifically for dbus, then signals (which to use?),
> then socket then any other command interface we choose. At least this
> is ugly but at a central place that always work.

This isn't necessary. Just add this to systemctl, which already does the
D-Bus fallback properly, and implements this logic similar to "systemctl
daemon-reexec" and "systemctl daemon-exit" are already implemented. In
fact, the handling for exit.service (which is useful only for sessions)
should be almost identical to what you need to do for
reboot/poweroff/halt here.

> another option is to have one more entry in target units that specify
> the manager exit_code. Then the unit parser converts it to
> ManagerExitCode and if != _MANAGER_EXIT_CODE_INVALID then it applies
> to t->meta.manager->exit_code. It would be more generic, but really,
> we already named the others "special targets". If you want I can make
> this conversion to ManagerExitCode  at parse time.

I am not a fan of hardcoding numeric codes everywhere. Also, I strongly
in favour of using similar codepaths for session exit, daemon reexec,
poweroff, halt, reboot and kexec.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list