[pkg-fgfs-crew] Bug#757178: fgrun: does not export environment variables to fgfs

Ludovic Brenta ludovic at ludovic-brenta.org
Wed Aug 6 01:31:02 UTC 2014


Package: fgrun
Version: 3.0.0-1
Severity: normal

I have a laptop with hybrid graphics (Intel integrated and ATI Radeon
discrete) and I have finally taken the time to enable the discrete
graphics for FlightGear.  In a shell:

$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x80 cap: 0xb, Source Output, Sink Output, Sink Offload crtcs: 3 outputs: 8 associated providers: 1 name:Intel
Provider 1: id: 0x55 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 6 outputs: 0 associated providers: 1 name:radeon
$ xrandr --setprovideroffloadsink radeon Intel
$ DRI_PRIME=1 fgfs --enable-fullscreen

This works with a compositing window manager such as xfvwm4 (not
ratpoison, unfortunately).  (The next version of mesa should make this
work also in non-fullscreen and with non-compositing window managers).

Now I would like to do the same thing from fgrun.  In the last page, I
click "Advanced" then "Environment" then "New" then I type "DRI_PRIME=1"
then OK.

When I then click "Run", fgrun fails to pass the environment variable to
fgfs, resulting it its still using the Intel integrated graphics.  The
workaround is to call "DRI_PRIME=1 fgrun" from a command line but then
the 3D Preview on page 2 does not work because it is not fullscreen.

Browsing the sources of fgrun on gitorious, I have traced this to the
following buggy piece of code near run_posix.cxx:119:

// "export" any environment variables.
int iVal;
prefs.get( "env-count", iVal, 0 );
for (int i = 1; i <= iVal; ++i)
{
    buf[0] = 0;
    prefs.get( Fl_Preferences::Name("env-var-%d", i),
    buf, "", buflen-1 );
    char* s = strdup( buf );
    putenv( s );
    free( s );
}

The use of putenv(3) is buggy because its man page says: "In particular,
this string becomes part of the environment; changing it later will
change the environment.  (Thus, it is an error is to call putenv() with
an automatic variable as the argument, then return from the calling
function while string is still part of the environment.)".

fgrun passes the string to the environment and then deallocates it.

The man page of setenv(3) says: "This function makes copies of the
strings pointed to by name and value (by contrast with putenv(3))."
Therefore, fgrun should call setenv(3), not putenv(3).

Here is a suggested patch but note that I have not even tried to compile
it.

--- /tmp/run_posix.cxx.old	2014-08-06 03:13:53.351947269 +0200
+++ /tmp/run_posix.cxx	2014-08-06 03:25:49.983116275 +0200
@@ -124,9 +124,16 @@
 	    buf[0] = 0;
 	    prefs.get( Fl_Preferences::Name("env-var-%d", i),
 		       buf, "", buflen-1 );
-	    char* s = strdup( buf );
-	    putenv( s );
-            free( s );
+            const char* equals = strchr(buf, '=');
+            if (equals == NULL) { /* environment variable name without a value; unset it. */
+              unsetenv(buf);
+            }
+            else { /* value exists */
+              *equals = '\0'; /* replace '=' with a new terminator; the value follows. */
+              setenv(/* name: */ buf,
+                     /* value: */ equals + 1,
+                     /* overwrite: */ TRUE);
+            }
 	}
 	vector<string> argv;
 	argv.push_back( arg0 );

-- System Information:
Debian Release: jessie/sid
  APT prefers testing
  APT policy: (10000, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.14-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages fgrun depends on:
ii  libc6                 2.19-7
ii  libfltk-forms1.3      1.3.2-6
ii  libfltk-gl1.3         1.3.2-6
ii  libfltk-images1.3     1.3.2-6
ii  libfltk1.3            1.3.2-6
ii  libgcc1               1:4.9.1-1
ii  libopenscenegraph99   3.2.0~rc1-5.1
ii  libopenthreads14      3.2.0~rc1-5.1
ii  libsimgearcore3.0.0   3.0.0-4
ii  libsimgearscene3.0.0  3.0.0-4
ii  libstdc++6            4.9.1-1
ii  zlib1g                1:1.2.8.dfsg-1

Versions of packages fgrun recommends:
ii  flightgear  3.0.0-2

fgrun suggests no packages.

-- no debconf information



More information about the pkg-fgfs-crew mailing list