From 663764ea8b9e547d1e422a7e7a335415405945ab Mon Sep 17 00:00:00 2001 From: Debian Live user Date: Sat, 29 Apr 2023 06:30:25 -0400 Subject: normalize file locations --- src/firestart | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 src/firestart (limited to 'src/firestart') diff --git a/src/firestart b/src/firestart new file mode 100755 index 0000000..5cc1c92 --- /dev/null +++ b/src/firestart @@ -0,0 +1,40 @@ +#!/bin/bash + +UNIT=firefox@$DISPLAY + +if systemctl --user is-active "$UNIT" >/dev/null +then + echo "Attemping to contact existing Firefox instance." >&2 + # Ask the existing firefox to open a new window. + + # Firefox does not include an official API to do this in a way that + # is not racy. If we merely do this: + # + # exec firefox "$@" + # + # ...then the unit could become inactive after our check, in which + # case this launches a new firefox outside the container! + # + # So instead, we launch the same command using a systemd container + # that prevents Firefox from forking off a new process. + # + # Well, actually, we let it fork off _one_ process, since otherwise + # it segfaults. But this _does_ happen to prevent it starting a new + # firefox instance! Firefox safely segfaults if it is limited this + # way while trying to start a new instance. + # + # A more "correct" approach is available here: + # https://github.com/ayosec/findfox + exec systemd-run \ + --user \ + --property Environment="DISPLAY=$DISPLAY" \ + --property Environment=XAUTHORITY="$XAUTHORITY" \ + --property TasksMax=2 \ + --wait \ + --pipe \ + -q \ + -- /bin/sh -c 'exec firefox "$@"' sh "$@" +else + systemctl --user reset-failed "$UNIT" 2>/dev/null + systemctl --user start "$UNIT" +fi -- cgit v1.2.3