Skip to content

Preferences: Don't rely on shebangs to launch#1920

Merged
daniellandau merged 6 commits into
GSConnect:mainfrom
ferdnyc:prefs-launch
Mar 7, 2026
Merged

Preferences: Don't rely on shebangs to launch#1920
daniellandau merged 6 commits into
GSConnect:mainfrom
ferdnyc:prefs-launch

Conversation

@ferdnyc

@ferdnyc ferdnyc commented Feb 6, 2025

Copy link
Copy Markdown
Member

Since launching JS modules via shebangs relies on features of the /usr/bin/env utility that aren't universally available, avoid it where possible.

The gsconnect-preferences "executable" (actually a JS module with a shebang line) is renamed to gsconnect-preferences.js, and both prefs.js and daemon.js will launch it by running gjs -m gsconnect-preferences.js with the extension root dir as the working directory, using Gio.SubprocessLauncher.

A small replacement gsconnect-preferences shell script is provided to replace the old launcher, and tries to do the right thing with working directories. However, it should not be relied on too heavily.

Partially addresses: #1879 (only prefs, not daemon.js)

Since launching JS modules via shebangs relies on features of
the /usr/bin/env utility that aren't universally available,
avoid it where possible.

The `gsconnect-preferences` "executable" (actually a JS module
with a shebang line) is renamed to `gsconnect-preferences.js`, and
both `prefs.js` and `daemon.js` will launch it by running
`gjs -m gsconnect-preferences.js` with the extension root dir
as the working directory, using `Gio.SubprocessLauncher`.

A small replacement `gsconnect-preferences` shell script is
provided to replace the old launcher, and tries to do the right
thing with working directories. However, it should not be relied
on too heavily.

Partially addresses: GSConnect#1879 (only prefs, not daemon.js)
Comment thread src/gsconnect-preferences Outdated
@@ -1,104 +1,19 @@
#!/usr/bin/env -S gjs -m
#!/usr/bin/sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's guaranteed to exist at that path.

...is what I wanted to write, and then I made the mistake of going to actually look at what POSIX says, and now I'm just sad.

image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFC. 😵‍💫

I probably should use /bin/sh, to future-proof against /usr consolidation. I'm pretty sure that's "guaranteed" to exist on any system we'd encounter in the wild -- even distros that don't use Bourne as their shell have a link from /bin/sh to dash or busybox or whatever.

The only POSSIBLE exception I can imagine might be Nix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my Ubuntu system here both /bin/sh and /usr/bin/sh are symlinks to dash. I once set my login shell to /usr/bin/bash on a /usr merged Arch years ago and couldn't log in after that because /bin/bash was the canonical name even though both could execute it. I'd guess /bin/sh is perhaps slightly more safe.

I think an executable file with no shebang will get passed to sh https://utcc.utoronto.ca/~cks/space/blog/unix/EmptyFileWhyTrue, but that's also quite a silly way to do it, and then we'd perhaps need to have a non-shebang ya rly comment stating what we are doing.

@daniellandau

Copy link
Copy Markdown
Member

I think the issue reference should be #1897 with the last two numbers flipped.

@daniellandau daniellandau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was left hanging, but I don't see a reason why it couldn't go in now

@daniellandau daniellandau enabled auto-merge (rebase) March 7, 2026 18:02
@daniellandau daniellandau merged commit ed2f3a1 into GSConnect:main Mar 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants