Skip to content

Commit b66f9e4

Browse files
author
Egil
committed
Better exit code handling for components, and some documentation
1 parent cda55d6 commit b66f9e4

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Features:
4141
* Configuration
4242
* [Key bindings](docs/KEYMAP.md)
4343
* [Sessions](docs/SESSION.md)
44+
* [Components](docs/COMPONENTS.md)
4445
* [Command line](docs/COMMANDLINE.md)
4546
* [Integrations](docs/INTEGRATIONS.md)
4647
* [Themes](docs/THEMES.md)

docs/COMPONENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Implemented by: [`glass-components`](../glass-components)
2+
3+
The components configuration is done in
4+
[~/.config/glass/components.yml](../glass-config-init/glass_config_init/components.yml).
5+
6+
# Components
7+
8+
Components are applications to run during your session or at startup
9+
that provide some part of the desktop environment. As opposed to
10+
normal applications used by the user, they are not normally started
11+
and stopped by the user and do not provide windows managed by the
12+
user. In particular, they are not SMlib clients and do not store a
13+
RestartCommand with `glass-ghosts`.
14+
15+
However, each component is given a name, and can be restarted or
16+
replaced using the `glass-action component` subcommands with that
17+
name.

docs/SESSION.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,3 @@ pre-define some ghosts in the configuration file. This is
3939
particularly useful for windows of components (see above). To generate the correct json for such a ghost, the following command can be used
4040

4141
glass-action ghost export
42-
43-
# Components
44-
45-
Components are applications to run during your session or at startup
46-
that provide some part of the desktop environment. As opposed to
47-
normal applications used by the user, they are not normally started
48-
and stopped by the user and do not provide windows managed by the
49-
user. In particular, they are not SMlib clients and do not store a
50-
RestartCommand with glass-ghosts.
51-
52-
However, each component is given a name, and can be restarted or
53-
replaced using the 'glass-action component' subcommands with that
54-
name.

glass-components/glass_components/components.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,30 @@ def sigchild(self, signum, frame):
6464
if pid in self.components_by_pid:
6565
name = self.components_by_pid.pop(pid)
6666
del self.display.root["IG_COMPONENTPID_" + name]
67-
if ( not exitcode == 0
68-
and ( not os.WIFSIGNALED(exitcode)
69-
or os.WTERMSIG(exitcode) not in (signal.SIGHUP, signal.SIGINT, signal.SIGQUIT, signal.SIGKILL))):
70-
# This is a component, and it wasn't killed intentionally... restart it
71-
if name in self.components and self.restart_components:
72-
spec = self.components[name]["component"]
67+
68+
if name in self.components:
69+
spec = self.components[name]["component"]
70+
spec_actions = spec.get("exit_actions", {})
71+
default_actions = self.config.get("defaults", {}).get("exit_actions", {})
72+
73+
exit_action = spec_actions.get("exited", default_actions.get("exited", "nothing"))
74+
killed_action = spec_actions.get("killed", default_actions.get("killed", "nothing"))
75+
fail_action = spec_actions.get("failed", default_actions.get("failed", "restart"))
76+
77+
if exitcode == 0:
78+
action = exit_action
79+
elif (os.WIFSIGNALED(exitcode)
80+
and os.WTERMSIG(exitcode) in (signal.SIGHUP, signal.SIGINT, signal.SIGQUIT, signal.SIGKILL)):
81+
action = killed_action
82+
else:
83+
action = fail_action
84+
85+
if action == "restart":
7386
self.start_component(spec)
87+
elif action == "exit":
88+
self.display.exit()
89+
return
90+
7491
InfiniteGlass.debug.DEBUG("SIGCHLD", "Checking for more children in the same batch...\n")
7592
try:
7693
pid, exitcode, ru_child = os.wait4(-1, os.WNOHANG)

glass-components/glass_components/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def setup_annotator():
3131
@InfiniteGlass.profilable
3232
def main(**kw):
3333
setup_annotator()
34-
manager = None
34+
components = None
3535
try:
3636
with InfiniteGlass.Display() as display:
3737
overlay = display.root.composite_get_overlay_window().overlay_window
@@ -44,13 +44,13 @@ def main(**kw):
4444

4545
components = glass_components.components.Components(display, **kw)
4646

47-
manager.components.shutdown()
47+
components.shutdown()
4848
except Exception as e:
4949
print("Components manager systemic failure, restarting: %s" % (e,))
5050
traceback.print_exc()
5151
try:
52-
if manager is not None and hasattr(manager, "components") and hasattr(manager.components, "components_by_pid"):
53-
for pid in manager.components.components_by_pid.keys():
52+
if components is not None and hasattr(components, "components_by_pid"):
53+
for pid in components.components_by_pid.keys():
5454
os.kill(pid, signal.SIGINT)
5555
except Exception as e:
5656
print(e)
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
restart_components: true
1+
defaults:
2+
exit_actions:
3+
exited: nothing
4+
failed: restart
5+
killed: nothing
26

37
components:
4-
glass-input: {"command": ["glass-input"]}
5-
glass-theme: {"command": ["glass-theme"]}
6-
glass-widgets: {"command": ["glass-widgets"]}
8+
glass-ghosts:
9+
command: ["glass-ghosts"]
10+
exit_actions:
11+
exited: exit
12+
failed: exit
13+
glass-input: {"command": ["glass-input"]}
14+
glass-theme: {"command": ["glass-theme"]}
15+
glass-widgets: {"command": ["glass-widgets"]}
716
glass-animator: {"command": ["glass-animator"]}
817
glass-renderer: {"command": ["glass-renderer-wrapper.sh"]}
9-
glass-islands: {"command": ["glass-islands"]}
10-
xkb: {"command": ["setxkbmap", "-model", "pc101", "-layout", "us"]}
11-
root-cursor: {"command": ["xsetroot", "-cursor_name", "arrow"]}
18+
glass-islands: {"command": ["glass-islands"]}
19+
xkb: {"command": ["setxkbmap", "-model", "pc101", "-layout", "us"]}
20+
root-cursor: {"command": ["xsetroot", "-cursor_name", "arrow"]}
1221
panelterm:
1322
command: ["xterm", "-title", "panelterm", "-xrm", "XTerm.vt100.allowTitleOps: false"]
1423
environment: { "IG_APP_ID": "panelterm" }

0 commit comments

Comments
 (0)