summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2012-04-26 12:27:14 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-04-26 12:27:14 +0100
commitec3c8d27f3fa9fa472aa730e79d3cb914107c6cd (patch)
treec7156683c384d16a0a64cbd683ddbea4aa817f5b
parentf15718ae19a42dd4ffc7046142f27ff322d9878e (diff)
parent85512849860e4fa500ca74b34036bf270382c292 (diff)
Merge branch 'cygwin-patches-for-1.12' into cygwin-release-1.12xserver-cygwin-1.12.0-5
-rw-r--r--glx/glxdriswrast.c7
-rw-r--r--hw/xwin/winmultiwindowicons.c4
-rw-r--r--hw/xwin/winprefs.c151
3 files changed, 128 insertions, 34 deletions
diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index 9647f8a14..d064a0536 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -433,14 +433,9 @@ initializeExtensions(__GLXDRIscreen *screen)
static __GLXscreen *
__glXDRIscreenProbe(ScreenPtr pScreen)
{
- const char *driverName;
+ const char *driverName = "swrast";
__GLXDRIscreen *screen;
- if (getenv("GALLIUM_DRIVER"))
- driverName = "swrastg";
- else
- driverName = "swrast";
-
screen = calloc(1, sizeof *screen);
if (screen == NULL)
return NULL;
diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c
index b1b9a87b6..abac4709a 100644
--- a/hw/xwin/winmultiwindowicons.c
+++ b/hw/xwin/winmultiwindowicons.c
@@ -530,9 +530,9 @@ winXIconToHICON (Display *pDisplay, Window id, int iconSize)
if (xImageMask)
XDestroyImage(xImageMask);
- }
- XDestroyImage(xImageIcon);
+ XDestroyImage(xImageIcon);
+ }
}
XFree(hints);
}
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index 0209d51f5..f0d23d70f 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -37,6 +37,8 @@
#include <stdlib.h>
#ifdef __CYGWIN__
#include <sys/resource.h>
+#include <sys/wait.h>
+#include <pthread.h>
#endif
#include "win.h"
@@ -164,7 +166,6 @@ static wBOOL CALLBACK
ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam)
{
HICON hicon;
- Window wid;
if (!hwnd) {
ErrorF("ReloadEnumWindowsProc: hwnd==NULL!\n");
@@ -321,8 +322,120 @@ HandleCustomWM_INITMENU(unsigned long hwndIn,
CheckMenuItem (hmenu, pref.menu[i].menuItem[j].commandID, dwExStyle );
}
-
-/*
+
+#ifdef __CYGWIN__
+static void
+LogLineFromFd(int fd, const char *fdname, int pid)
+{
+#define BUFSIZE 512 /* must be less than internal buffer size used in LogVWrite */
+ char buf[BUFSIZE];
+ char *bufptr = buf;
+
+ /* read from fd until eof, newline or our buffer is full */
+ while ((read(fd, bufptr, 1) > 0) && (bufptr < &(buf[BUFSIZE-1])))
+ {
+ if (*bufptr == '\n')
+ break;
+ bufptr++;
+ }
+
+ /* null terminate and log */
+ *bufptr = 0;
+ if (strlen(buf))
+ ErrorF("(pid %d %s) %s\n", pid, fdname, buf);
+}
+
+static void *
+ExecAndLogThread(void *cmd)
+{
+ int pid;
+ int stdout_filedes[2];
+ int stderr_filedes[2];
+ int status;
+
+ /* Create a pair of pipes */
+ pipe(stdout_filedes);
+ pipe(stderr_filedes);
+
+ switch (pid = fork())
+ {
+ case 0: /* child */
+ {
+ struct rlimit rl;
+ unsigned int fd;
+
+ /* dup write end of pipes onto stderr and stdout */
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+
+ dup2(stdout_filedes[1], STDOUT_FILENO);
+ dup2(stderr_filedes[1], STDERR_FILENO);
+
+ /* Close any open descriptors except for STD* */
+ getrlimit (RLIMIT_NOFILE, &rl);
+ for (fd = STDERR_FILENO+1; fd < rl.rlim_cur; fd++)
+ close(fd);
+
+ /* Disassociate any TTYs */
+ setsid();
+
+ execl ("/bin/sh",
+ "/bin/sh",
+ "-c",
+ cmd,
+ NULL);
+ perror("execl failed");
+ exit(127);
+ }
+ break;
+
+ default: /* parent */
+ {
+ close(stdout_filedes[1]);
+ close(stderr_filedes[1]);
+
+ ErrorF("executing '%s', pid %d\n", (char *)cmd, pid);
+
+ /* read from pipes, write to log, until both are closed */
+ while (TRUE)
+ {
+ fd_set readfds, errorfds;
+ int nfds = max(stdout_filedes[0], stderr_filedes[0])+1;
+ FD_ZERO(&readfds);
+ FD_SET(stdout_filedes[0], &readfds);
+ FD_SET(stderr_filedes[0], &readfds);
+ errorfds = readfds;
+
+ if (select(nfds, &readfds, NULL, &errorfds, NULL) > 0)
+ {
+ if (FD_ISSET(stdout_filedes[0], &readfds))
+ LogLineFromFd(stdout_filedes[0], "stdout", pid);
+ if (FD_ISSET(stderr_filedes[0], &readfds))
+ LogLineFromFd(stderr_filedes[0], "stderr", pid);
+
+ if (FD_ISSET(stdout_filedes[0], &errorfds) &&
+ FD_ISSET(stderr_filedes[0], &errorfds))
+ break;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ waitpid(pid, &status, 0);
+ }
+ break;
+
+ case -1: /* error */
+ ErrorF("fork() to run command failed\n");
+ }
+
+ return (void *)status;
+}
+#endif
+
+ /*
* Searches for the custom WM_COMMAND command ID and performs action.
* Return TRUE if command is proccessed, FALSE otherwise.
*/
@@ -352,29 +465,15 @@ HandleCustomWM_COMMAND (unsigned long hwndIn,
{
#ifdef __CYGWIN__
case CMD_EXEC:
- if (fork()==0)
- {
- struct rlimit rl;
- unsigned long i;
-
- /* Close any open descriptors except for STD* */
- getrlimit (RLIMIT_NOFILE, &rl);
- for (i = STDERR_FILENO+1; i < rl.rlim_cur; i++)
- close(i);
-
- /* Disassociate any TTYs */
- setsid();
-
- execl ("/bin/sh",
- "/bin/sh",
- "-c",
- m->menuItem[j].param,
- NULL);
- exit (0);
- }
- else
- return TRUE;
- break;
+ {
+ pthread_t t;
+ if (!pthread_create(&t, NULL, ExecAndLogThread, m->menuItem[j].param))
+ pthread_detach(t);
+ else
+ ErrorF("Creating command output logging thread failed\n");
+ }
+ return TRUE;
+ break;
#else
case CMD_EXEC:
{