diff options
author | Debian Live user <user@debian-BULLSEYE-live-builder-AMD64> | 2023-04-28 23:17:48 -0400 |
---|---|---|
committer | Debian Live user <user@debian-BULLSEYE-live-builder-AMD64> | 2023-04-28 23:17:48 -0400 |
commit | f7c49dac7360615f4700c9eea6f630f278c1251e (patch) | |
tree | b3493bc49b46e1d88775e33a355dc83f399d6586 | |
parent | fa4b765120fa7638e8737d6783eedeb1a65fe83c (diff) |
fix firestart race condition
-rwxr-xr-x | firestart | 35 |
1 files changed, 30 insertions, 5 deletions
@@ -1,13 +1,38 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CMD=firefox | 3 | UNIT=firefox@$DISPLAY |
4 | UNIT=$CMD@$DISPLAY | ||
5 | 4 | ||
6 | if systemctl --user is-active "$UNIT" >/dev/null | 5 | if systemctl --user is-active "$UNIT" >/dev/null |
7 | then | 6 | then |
8 | # Asks existing firefox to open a new window. Technically is racy, | 7 | # Ask the existing firefox to open a new window. |
9 | # since the unit could become active after our check. | 8 | |
10 | exec "$CMD" "$@" | 9 | # Firefox does not include an official API to do this in a way that |
10 | # is not racy. If we merely do this: | ||
11 | # | ||
12 | # exec firefox "$@" | ||
13 | # | ||
14 | # ...then the unit could become inactive after our check, in which | ||
15 | # case this launches a new firefox outside the container! | ||
16 | # | ||
17 | # So instead, we launch the same command using a systemd container | ||
18 | # that prevents Firefox from forking off a new process. | ||
19 | # | ||
20 | # Well, actually, we let it fork off _one_ process, since otherwise | ||
21 | # it segfaults. But this _does_ happen to prevent it starting a new | ||
22 | # firefox instance! Firefox safely segfaults if it is limited this | ||
23 | # way while trying to start a new instance. | ||
24 | # | ||
25 | # A more "correct" approach is available here: | ||
26 | # https://github.com/ayosec/findfox | ||
27 | exec systemd-run \ | ||
28 | --user \ | ||
29 | --property Environment="DISPLAY=$DISPLAY" \ | ||
30 | --property Environment=XAUTHORITY="$XAUTHORITY" \ | ||
31 | --property TasksMax=2 \ | ||
32 | --wait \ | ||
33 | --pipe \ | ||
34 | -q \ | ||
35 | -- /bin/sh -c 'exec firefox "$@"' sh "$@" | ||
11 | else | 36 | else |
12 | systemctl --user reset-failed "$UNIT" 2>/dev/null | 37 | systemctl --user reset-failed "$UNIT" 2>/dev/null |
13 | systemctl --user start "$UNIT" | 38 | systemctl --user start "$UNIT" |