[systemd-devel] Cleaning up transient scopes

Alexander Larsson alexl at redhat.com
Thu Mar 5 01:12:07 PST 2015


On tor, 2015-03-05 at 00:00 +0100, Lennart Poettering wrote:
> On Wed, 04.03.15 18:51, Alexander Larsson (alexl at redhat.com) wrote:
> 
> > If i run a transient scope on the user systemd instance like:
> > 
> > $ systemd-run --user --scope true
> > 
> > Then the scope seems to live past the end of the process. Is there any
> > way to make it automatically go away with the last process in the
> > cgroup?
> 
> Well, yes, the idea is that that just works. However, this is kinda
> broken if the systemd instance managing your scope is not PID 1, as we
> don't get SIGCHLD then. 
> 
> Do you create any subcgroups? presumably not?
> 
> Normally it should just work then, but I must admit that --user scopes
> got much less testing that system scopes...

Oh, i'm not doing anything special at all:

$ systemd-run --user --scope sleep 10 &
[1] 10613
$ Running as unit run-10613.scope.
systemd-ctl status --user run-10613.scope 
● run-10613.scope - /usr/bin/sleep 10
   Loaded: loaded (/run/user/1000/systemd/user/run-10613.scope; static)
  Drop-In: /run/user/1000/systemd/user/run-10613.scope.d
           └─50-Description.conf
   Active: active (running) since tor 2015-03-05 10:06:24 CET; 8s ago
   CGroup: /user.slice/user-1000.slice/user at 1000.service/run-10613.scope
           └─10613 /usr/bin/sleep 10

mar 05 10:06:24 localhost.localdomain systemd[1405]: Starting /usr/bin/sleep 10.
mar 05 10:06:24 localhost.localdomain systemd[1405]: Started /usr/bin/sleep 10.
$ sleep 10
[1]+  Done                    systemd-run --user --scope sleep 10
$ systemctl status --user run-10613.scope 
● run-10613.scope - /usr/bin/sleep 10
   Loaded: loaded (/run/user/1000/systemd/user/run-10613.scope; static)
  Drop-In: /run/user/1000/systemd/user/run-10613.scope.d
           └─50-Description.conf
   Active: active (running) since tor 2015-03-05 10:06:24 CET; 25s ago

mar 05 10:06:24 localhost.localdomain systemd[1405]: Starting /usr/bin/sleep 10.
mar 05 10:06:24 localhost.localdomain systemd[1405]: Started /usr/bin/sleep 10.

See, even when the sleep command died the scope still exists, and is
even ACTIVE.

Also, while we're on the topic of scopes. Is there any way to hang some
random metadata off a unit during creation, that can be read back? For
xdg-app I'd like to put information like the app id, the exact version,
the security level, etc into the scope. Then anyone talking to the app
could go: 
  getpeercred => cgroup => scope => unfakable (by the app) data about
  the application.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
       alexl at redhat.com            alexander.larsson at gmail.com 
He's an uncontrollable coffee-fuelled filmmaker for the 21st century. 
She's an enchanted tomboy doctor with a song in her heart and a spring in 
her step. They fight crime! 



More information about the systemd-devel mailing list