Red Hat Bugzilla – Bug 982311
Default /etc/mailcap uses /usr/bin/xdg-open
Last modified: 2016-07-18 05:54:01 EDT
Description of problem:
Entries in the /etc/mailcap file shipped in the mailcap package use /usr/bin/xdg-open, which uses $BROWSER as a fallback, where $BROWSER may refer back to /etc/mailcap and thus launch /usr/bin/xdg-open again in an endless loop.
Furthermore, the mailcap entry is missing the "needsterminal" flag, which it needs in case $BROWSER needs a terminal.
Version-Release number of selected component (if applicable):
% rpm -q mailcap xdg-utils
Steps to Reproduce:
1. Set BROWSER to be a terminal-based Web browser that uses mailcap; e.g. `export BROWSER=elinks`.
2. Run `xdg-open document.pdf` where "document.pdf" is a PDF document, which causes $BROWSER to open.
3. Open the PDF document from $BROWSER.
Chaos as multiple instances of $BROWSER fight, along with whatever process initially launched xdg-open, for control of the terminal.
Harmony as the the PDF viewer runs in a separate window and the process that initially launched xdg-open retains control over the terminal.
In my particular situation, I am trying to view PDF attachments in my E-mail. I use Mutt for E-mail, ELinks for $BROWSER, JWM as my DE, and Evince as my PDF viewer as configured in ~/.local/share/applications/defaults.list:
% echo $BROWSER
% cat ~/.local/share/applications/defaults.list
% xdg-mime query default application/pdf
Mutt use /etc/mailcap to view documents that it does not natively handle, such as PDF files. /etc/mailcap associates /usr/bin/xdg-open with the application/pdf mimetype. Consequently, Mutt runs /usr/bin/xdg-open to open attachments.
/usr/bin/xdg-open uses the following function to determine what DE I am using:
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \\"xfce4\\"$' >/dev/null 2>&1; then DE=xfce;
Because I am not running KDE, GNOME, or XFCE, detectDE leaves DE unset. xdg-open invokes detectDE and then runs the following code:
if [ x"$DE" = x"" ]; then
# if BROWSER variable is not set, check some well known browsers instead
if [ x"$BROWSER" = x"" ]; then
I already have BROWSER set to 'elinks', and so after this line, we have $BROWSER = elinks and $DE = generic.
Because $DE = generic, xdg-open then runs its open_generic function, which first tries to open the PDF file using mimeopen. I do not have mimeopen (it is not installed on my RHEL63 system, and I cannot find a package that has mimeopen), and so open_generic next tries to open the PDF using run-mailcap. I likewise do not have run-mailcap, and so open_generic finally falls back to $BROWSER, which is 'elinks'.
Like Mutt, ELinks uses /etc/mailcap to view documents that it does not natively handle, which likewise includes PDF files. Consequently, ELinks runs /usr/bin/xdg-open to open PDF files. So at this point, Mutt has invoked xdg-open, which has invoked ELinks, which invokes xdg-open, which will invoke ELinks, which will invoke xdg-open, and so on.
Additionally, because /etc/mailcap is missing the "needsterminal" flag, Mutt and ELinks do not cede control of the terminal to xdg-open (or to each other), and so we get a situation where Mutt and ELinks are both reading input from the terminal and trying to draw to the terminal at the same time.
Fortunately, I have ELinks configured with its mime.mailcap.ask option enabled ("Ask before using the handlers defined by mailcap."). Otherwise, we'd probably have a forkbomb on our hands.
If xdg-open is potentially going to invoke a program that uses /etc/mailcap, then /etc/mailcap should not associate xdg-open with anything.
If xdg-open is potentially going to invoke a program that needs a terminal (whether it be $BROWSER or whether it be a viewer that needs a terminal) and xdg-open is used in entries in /etc/mailcap, then xdg-open needs the "needsterminal" flag.
I understand what the problem is, but I'm not sure if there is anything we could use instead of xdg-open and which wouldn't result in possibly using mailcap again.
Do you have a suggestion on how to fix it? Perhaps xdg-open should be able to detect the recursion via an environment variable?
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unable to address this
request at this time.
Red Hat invites you to ask your support representative to
propose this request, if appropriate, in the next release of
Red Hat Enterprise Linux.
As it seems there is no obvious fix for this problem and RHEL6 is now in the Production Phase 2, I'm closing this bug. There are multiple components involved and assumptions about their behaviour are made, so if there are any ideas it might be best to try them in Fedora first.