autorun files on removable media can't be used if executable bit is not set
The Desktop Application Autostart Specification contains a section on Autostart files, which defines three filenames that can be placed at the root directory of removable media. If one of these files is present, the desktop can offer the user the chance to automatically run the program in question. This has been implemented in Nautilus since 2008 (dcd068fe), with quite minor changes since.
The shared-mime-info rules that match these files and mark the media with content type x-content/software
do not require that the files have the executable bit set. However the code in Nautilus which actually launches the autorun program does require that it have the executable bit set. This leads to confusing behaviour and error messages when you try to use the feature on a FAT-formatted removable drive, which does not support an executable bit natively, and whose Linux implementation does not expose files with the executable bit with the default mount options.
Affected version
- Nightly flatpak: Haven't tested it because I have read the Git history and the relevant code is unchanged
- Other: 41.2 in Endless OS development branch
Steps to reproduce
- Format a removable drive with a FAT filesystem
- Create a file named
autorun.sh
in the root directory of the removable drive with the following contents:
#!/bin/sh
zenity --info --text="I can hold my breath for 10 minutes!"
- Safely unmount the drive
- Remount the drive
- When offered the chance to run software from the drive, choose Run.
Current behaviour
Nautilus claims:
Oops! There was a problem running this software.
Unable to locate the program
This error message is very confusing. As far as I am concerned looking at what is on the screen, there is only one file on the device, the autorun file, and Nautilus obviously knows it's there because it gave me the option to run it!
Expected behaviour
Since 8978c637, Nautilus has handled autorun.sh
differently to .autorun
or autorun
: the latter two are executed directly, but autorun.sh
is run with /bin/sh
. The justification given in that commit is:
If the autorun file is called autorun.sh it is clearly meant for execution through a sh processor. The benefit of using /bin/sh as the executable is that autorun will also work on FAT formatted media (which does not allow autorun.sh to have +x permission set)
But this doesn't work because Nautilus is explicitly checking for the executable bit.
Additional information
Linux's relatively-new native support for exFAT exposes every regular file as having the executable bit, which avoids this issue.
The Desktop Application Autostart Specification's section on Autostart files does not say that there should be any difference in treatment between the three files, but that is another story.