1 bug 638: Save, set and restore the DISPLAY environment variable.
3 Thanks to this trick the appropriate handler is executed,
4 even in a mixed (X11, framebuffer) environment.
7 commit 65a3518a912d6cc6aa38cee4a4142299d7a25cc7
8 tree 47b6a1c4af22420fef498ac26dd0955e79428024
9 parent 81f8ee1fa2b94ef40460eb4a42710e1ed9e22c98
10 author Witold Filipczyk <witekfl@poczta.onet.pl> Sun, 16 Mar 2008 16:29:32 +0100
11 committer Witold Filipczyk <nobody@nowhere> Sun, 16 Mar 2008 16:29:32 +0100
14 src/mime/backend/mailcap.c | 58 +++++++++++++++++++++++++++++++++++++++++++-
15 2 files changed, 58 insertions(+), 1 deletions(-)
17 diff --git a/configure.in b/configure.in
18 index 0a867ae..5cfeaa9 100644
21 @@ -307,6 +307,7 @@ AC_CHECK_FUNCS(gettimeofday clock_gettime)
22 AC_CHECK_FUNCS([cygwin_conv_to_full_win32_path])
24 AC_CHECK_FUNCS(setenv putenv, HAVE_SETENV_OR_PUTENV=yes)
25 +AC_CHECK_FUNCS(unsetenv)
26 AC_CHECK_FUNCS(getuid, HAVE_GETUID=yes)
27 AC_CHECK_FUNCS(geteuid, HAVE_GETEUID=yes)
29 diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c
30 index 76ea78b..70e270d 100644
31 --- a/src/mime/backend/mailcap.c
32 +++ b/src/mime/backend/mailcap.c
33 @@ -646,8 +646,57 @@ get_mailcap_entry(unsigned char *type)
37 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
38 +/* restore == 0 set DISPLAY
39 + * restore == 1 restore DISPLAY
42 +set_display(int xwin, int restore)
44 + static unsigned char *display = NULL;
47 + display = getenv("DISPLAY");
48 + if (display) display = stracpy(display);
51 + setenv("DISPLAY", ":0", 1);
53 + putenv("DISPLAY=:0");
57 + unsetenv("DISPLAY");
62 + } else { /* restore DISPLAY */
65 + setenv("DISPLAY", display, 1);
68 + static unsigned char DISPLAY[1024] = { 'D','I','S','P','L','A','Y','=' };
70 + strncpy(DISPLAY + 8, display, 1023 - 8);
77 + unsetenv("DISPLAY");
86 static struct mime_handler *
87 -get_mime_handler_mailcap(unsigned char *type, int options)
88 +get_mime_handler_mailcap(unsigned char *type, int xwin)
90 struct mailcap_entry *entry;
91 struct mime_handler *handler;
92 @@ -658,7 +707,14 @@ get_mime_handler_mailcap(unsigned char *type, int options)
93 || (!mailcap_map && !init_mailcap_map()))
96 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
97 + set_display(xwin, 0);
99 entry = get_mailcap_entry(type);
101 +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
102 + set_display(xwin, 1);
104 if (!entry) return NULL;
106 program = format_command(entry->command, type, entry->copiousoutput);