Bug 494360 - DISPLAY entry is listed twice in environ
DISPLAY entry is listed twice in environ
Product: Fedora
Classification: Fedora
Component: glib2 (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Matthias Clasen
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2009-04-06 10:40 EDT by Mamoru TASAKA
Modified: 2009-04-06 12:00 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-04-06 12:00:12 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
proposal patch (421 bytes, patch)
2009-04-06 10:40 EDT, Mamoru TASAKA
no flags Details | Diff

  None (edit)
Description Mamoru TASAKA 2009-04-06 10:40:35 EDT
Created attachment 338340 [details]
proposal patch

Description of problem:

Look at the following simple code:
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv){
  extern char **environ;
  int i = 0;

  while (environ[i]){
    if (environ[i] == strstr(environ[i], "DISPLAY"))
      fprintf (stderr, "argv[%i] is \"%s\"\n", i, environ[i]);
  return 0;

When I
- login to GNOME session, launch xterm
- execute the code above on the xterm
the code above simply shows:
argv[45] is "DISPLAY=:0.0"
for example.

However when I
- login to GNOME session
- right click on GNOME panel, select "Add to panel"
- select "custom application launcher" and select
  the binary generated from the code above
- click the icon newly added on the panel
- watch ~/.xsession-errors
then the following appears:
argv[34] is "DISPLAY=:0.0"
argv[45] is "DISPLAY=:0.0"

This shows char **environ has two "DISPLAY" item??

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. See above
Actual results:
This causes that pcmanfm (which I maintain) cannot launch
any commands when pcmanfm is launched from GNOME menu
(sourceforge bug id 2313286)

Expected results:
"DISPLAY" item should appear only once

Additional info:
The attached patch seems to work.
Actually on static gboolean is_env (const char *a, const char *b)
in gio/gdesktopappinfo.c:
   828  static gboolean
   829  is_env (const char *a,
   830          const char *b)
   831  {
   832    while (*a == *b)
   833    {
   834      if (*a == 0 || *b == 0)
   835        return FALSE;
   837      if (*a == '=')
   838        return TRUE;
   840      a++;
   841      b++;
   842    }
   844    return FALSE;
   845  }
suppose a="DISPLAY=:0.0" and b="DISPLAY"
I guess this should return TRUE but actually this returns
- because after a,b both points to 'Y', at lines 840-841
  now *a='=' while *b=0, then while (*a == *b) at 832 fails.
Comment 1 Mamoru TASAKA 2009-04-06 10:45:43 EDT
(In reply to comment #0)
>       fprintf (stderr, "argv[%i] is \"%s\"\n", i, environ[i]);

This should be
fprintf (stderr, "environ[%i is ....... 
but the result is the same.
Comment 2 Matthias Clasen 2009-04-06 12:00:12 EDT
This is not a bug, it is just the way environ works

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