summaryrefslogtreecommitdiff
path: root/src/firestart
diff options
context:
space:
mode:
Diffstat (limited to 'src/firestart')
-rwxr-xr-xsrc/firestart40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/firestart b/src/firestart
new file mode 100755
index 0000000..5cc1c92
--- /dev/null
+++ b/src/firestart
@@ -0,0 +1,40 @@
1#!/bin/bash
2
3UNIT=firefox@$DISPLAY
4
5if systemctl --user is-active "$UNIT" >/dev/null
6then
7 echo "Attemping to contact existing Firefox instance." >&2
8 # Ask the existing firefox to open a new window.
9
10 # Firefox does not include an official API to do this in a way that
11 # is not racy. If we merely do this:
12 #
13 # exec firefox "$@"
14 #
15 # ...then the unit could become inactive after our check, in which
16 # case this launches a new firefox outside the container!
17 #
18 # So instead, we launch the same command using a systemd container
19 # that prevents Firefox from forking off a new process.
20 #
21 # Well, actually, we let it fork off _one_ process, since otherwise
22 # it segfaults. But this _does_ happen to prevent it starting a new
23 # firefox instance! Firefox safely segfaults if it is limited this
24 # way while trying to start a new instance.
25 #
26 # A more "correct" approach is available here:
27 # https://github.com/ayosec/findfox
28 exec systemd-run \
29 --user \
30 --property Environment="DISPLAY=$DISPLAY" \
31 --property Environment=XAUTHORITY="$XAUTHORITY" \
32 --property TasksMax=2 \
33 --wait \
34 --pipe \
35 -q \
36 -- /bin/sh -c 'exec firefox "$@"' sh "$@"
37else
38 systemctl --user reset-failed "$UNIT" 2>/dev/null
39 systemctl --user start "$UNIT"
40fi