1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-21 00:25:37 +00:00

bug 638: Save, set and restore the DISPLAY environment variable.

Thanks to this trick the appropriate handler is executed,
even in a mixed (X11, framebuffer) environment.
This commit is contained in:
Witold Filipczyk 2008-03-16 16:29:32 +01:00 committed by Kalle Olavi Niemitalo
parent 51a3d30017
commit 4eefa983de
2 changed files with 58 additions and 1 deletions

View File

@ -307,6 +307,7 @@ AC_CHECK_FUNCS(gettimeofday clock_gettime)
AC_CHECK_FUNCS([cygwin_conv_to_full_win32_path])
AC_CHECK_FUNCS(setenv putenv, HAVE_SETENV_OR_PUTENV=yes)
AC_CHECK_FUNCS(unsetenv)
AC_CHECK_FUNCS(getuid, HAVE_GETUID=yes)
AC_CHECK_FUNCS(geteuid, HAVE_GETEUID=yes)

View File

@ -646,8 +646,57 @@ get_mailcap_entry(unsigned char *type)
return entry;
}
#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
/* restore == 0 set DISPLAY
* restore == 1 restore DISPLAY
*/
static void
set_display(int xwin, int restore)
{
static unsigned char *display = NULL;
if (!restore) {
display = getenv("DISPLAY");
if (display) display = stracpy(display);
if (xwin) {
#ifdef HAVE_SETENV
setenv("DISPLAY", ":0", 1);
#else
putenv("DISPLAY=:0");
#endif
} else {
#ifdef HAVE_UNSETENV
unsetenv("DISPLAY");
#else
putenv("DISPLAY");
#endif
}
} else { /* restore DISPLAY */
if (display) {
#ifdef HAVE_SETENV
setenv("DISPLAY", display, 1);
#else
{
static unsigned char DISPLAY[1024] = { 'D','I','S','P','L','A','Y','=' };
strncpy(DISPLAY + 8, display, 1023 - 8);
putenv(DISPLAY);
}
#endif
mem_free(display);
} else {
#ifdef HAVE_UNSETENV
unsetenv("DISPLAY");
#else
putenv("DISPLAY");
#endif
}
}
}
#endif
static struct mime_handler *
get_mime_handler_mailcap(unsigned char *type, int options)
get_mime_handler_mailcap(unsigned char *type, int xwin)
{
struct mailcap_entry *entry;
struct mime_handler *handler;
@ -658,7 +707,14 @@ get_mime_handler_mailcap(unsigned char *type, int options)
|| (!mailcap_map && !init_mailcap_map()))
return NULL;
#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
set_display(xwin, 0);
#endif
entry = get_mailcap_entry(type);
#if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
set_display(xwin, 1);
#endif
if (!entry) return NULL;
program = format_command(entry->command, type, entry->copiousoutput);