RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 982311 - Default /etc/mailcap uses /usr/bin/xdg-open
Summary: Default /etc/mailcap uses /usr/bin/xdg-open
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: mailcap
Version: 6.3
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Miroslav Lichvar
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-07-08 15:51 UTC by Miciah Dashiel Butler Masters
Modified: 2016-07-18 09:54 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-07-18 09:54:01 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Miciah Dashiel Butler Masters 2013-07-08 15:51:23 UTC
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
mailcap-2.1.31-2.el6.noarch
xdg-utils-1.0.2-17.20091016cvs.el6.noarch


How reproducible:

Entirely.


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.


Actual results:

Chaos as multiple instances of $BROWSER fight, along with whatever process initially launched xdg-open, for control of the terminal.

Expected results:

Harmony as the the PDF viewer runs in a separate window and the process that initially launched xdg-open retains control over the terminal.


Additional info:

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
elinks

% cat ~/.local/share/applications/defaults.list
[Default Applications]
application/pdf=evince.desktop

% xdg-mime query default application/pdf
evince.desktop

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:

detectDE()
{
    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;
    fi
}

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
        BROWSER=htmlview:firefox:mozilla:netscape:links:lynx
    fi
    DE=generic
fi

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.

Comment 2 Miroslav Lichvar 2013-07-08 16:50:27 UTC
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?

Comment 3 RHEL Program Management 2013-10-13 23:24:06 UTC
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.

Comment 4 Miroslav Lichvar 2016-07-18 09:54:01 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.