After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 725651 - GSubprocessLauncher: Does not copy the calling process environment.
GSubprocessLauncher: Does not copy the calling process environment.
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.39.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-03-04 13:23 UTC by Yanko Kaneti
Modified: 2014-03-04 15:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GSubprocessLauncher: don't get empty environment (894 bytes, patch)
2014-03-04 13:56 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gsubprocess: test environment a bit more (2.82 KB, patch)
2014-03-04 14:09 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Yanko Kaneti 2014-03-04 13:23:33 UTC
glib2-2.39.91-1.fc21.x86_64

Run the following test program in a environment with SSH_ASKPASS,SSH_AUTH_SOCK set

#include <gio/gio.h>

GPtrArray *args = NULL;

int main() {

  GSubprocessLauncher *launcher;
  GError *local_error = NULL;
  GError **error = &local_error;

  args = g_ptr_array_new_with_free_func (g_free);

  g_ptr_array_add (args, "/usr/bin/printenv");
  g_ptr_array_add (args, "SSH_ASKPASS");
  g_ptr_array_add (args, "SSH_AUTH_SOCK");
  g_ptr_array_add (args, NULL);

  launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
  g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata,
}

Expected result: the contents of the SSH_ASKPASS,SSH_AUTH_SOCK variables on two lines

Actual result: nothing
Comment 1 Matthias Clasen 2014-03-04 13:37:46 UTC
seems g_subprocess_launcher_init should use g_get_environ instead of g_listenv
Comment 2 Allison Karlitskaya (desrt) 2014-03-04 13:56:39 UTC
Created attachment 270902 [details] [review]
GSubprocessLauncher: don't get empty environment

Use g_get_environ() to get the environment variables with their values
instead of g_listenv() which only lists off the keys.
Comment 3 Allison Karlitskaya (desrt) 2014-03-04 14:09:40 UTC
Created attachment 270903 [details] [review]
gsubprocess: test environment a bit more

Add a test for GSubprocess to test setting, unsetting and inheritance of
environment variables.  Use communicate() to give it a bit more of a
workout as well.
Comment 4 Matthias Clasen 2014-03-04 14:45:42 UTC
Review of attachment 270903 [details] [review]:

::: gio/tests/gsubprocess.c
@@ +1232,3 @@
+  g_assert_no_error (error);
+
+  g_assert_cmpstr (out, ==, "C=D\nE=F\n");

I wonder if the order is actually guaranteed here, or if you could also get "E=F\nC=d\n".

I guess we can wait for this to fail on some exotic system
Comment 5 Matthias Clasen 2014-03-04 14:45:58 UTC
Review of attachment 270902 [details] [review]:

sure
Comment 6 Allison Karlitskaya (desrt) 2014-03-04 15:39:35 UTC
Review of attachment 270903 [details] [review]:

::: gio/tests/gsubprocess.c
@@ +1232,3 @@
+  g_assert_no_error (error);
+
+  g_assert_cmpstr (out, ==, "C=D\nE=F\n");

It is guaranteed because its our own implementation of printenv, from the test utility program.  See the other file in the patch.
Comment 7 Allison Karlitskaya (desrt) 2014-03-04 15:48:25 UTC
Attachment 270902 [details] pushed as e767204 - GSubprocessLauncher: don't get empty environment
Attachment 270903 [details] pushed as 2b11af4 - gsubprocess: test environment a bit more


Thanks for the report!