Skip to content

Commit

Permalink
feat(cgroups): reassign apps from cgroups of a known launchers
Browse files Browse the repository at this point in the history
Some launcher applications are visible in the i3/sway IPC and receive
transient unit of their own. All the apps started from these were left
in the launcher transient unit and any overrides targeted to these apps
did not apply.
  • Loading branch information
alebastr committed Jul 4, 2021
1 parent 6ebc914 commit 5a9810f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/assign-cgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
LOG = logging.getLogger("assign-cgroups")
SD_BUS_NAME = "org.freedesktop.systemd1"
SD_OBJECT_PATH = "/org/freedesktop/systemd1"
SD_SLICE_FORMAT = "app-{app_id}.slice"
SD_UNIT_FORMAT = "app-{app_id}-{unique}.scope"
# Ids of known launcher applications that are not special surfaces. When the app is
# started using one of those, it should be moved to a new cgroup.
# Launcher should only be listed here if it creates cgroup of its own.
LAUNCHER_APPS = ["nwggrid"]


def get_cgroup(pid: int) -> Optional[str]:
Expand Down Expand Up @@ -173,7 +179,11 @@ def get_pid(self, con: Con) -> Optional[int]:

def cgroup_change_needed(self, cgroup: Optional[str]) -> bool:
"""Check criteria for assigning current app into an isolated cgroup"""
# TODO: check for known launchers
if cgroup is None:
return False
for launcher in LAUNCHER_APPS:
if SD_SLICE_FORMAT.format(app_id=launcher) in cgroup:
return True
return cgroup == self._compositor_cgroup

@retry(
Expand All @@ -187,8 +197,8 @@ async def assign_scope(self, app_id: str, proc: Process):
app-{app_id}.slice/app{app_id}-{pid}.scope cgroup
"""
app_id = escape_app_id(app_id)
sd_unit = f"app-{app_id}-{proc.pid}.scope"
sd_slice = f"app-{app_id}.slice"
sd_slice = SD_SLICE_FORMAT.format(app_id=app_id)
sd_unit = SD_UNIT_FORMAT.format(app_id=app_id, unique=proc.pid)
# Collect child processes as systemd assigns a scope only to explicitly
# specified PIDs.
# There's a risk of race as the child processes may exit by the time dbus call
Expand Down

0 comments on commit 5a9810f

Please sign in to comment.