$FreeBSD: ports/x11-wm/uwm/files/patch-ab,v 1.2 2002/09/25 14:58:56 trevor Exp $
$NetBSD: patch-ab,v 1.2 2000/01/19 07:24:07 itohy Exp $

--- uwm.c.orig	Sun Oct 23 13:21:55 1988
+++ uwm.c	Wed Sep 25 14:53:13 2002
@@ -41,9 +41,18 @@
 
 #include "uwm.h"
 #include <ctype.h>
+#include <signal.h>
+
+#ifdef CSRG_BASED
+#undef MIN
+#undef MAX
+#include <sys/param.h>
+#if defined(BSD) && BSD >= 199306
+#define HAVE_MKSTEMP
+#endif
+#endif
 
 #ifdef PROFIL
-#include <signal.h>
 /*
  * Dummy handler for profiling.
  */
@@ -53,6 +62,27 @@
 }
 #endif
 
+#ifdef SIGCHLD
+#include <sys/wait.h>
+/*
+ * clear (probably inherited) children which are dead or will die.
+ */
+clear_children()
+{
+	int status, pid;
+
+	do {
+#ifdef CSRG_BASED
+		pid = wait3(&status, WNOHANG, (struct rusage *) 0);
+#else	/* SVR4 */
+		pid = waitpid(-1, &status, WNOHANG);
+#endif
+	} while (pid != 0 && pid != -1);
+
+	signal(SIGCHLD, clear_children);
+}
+#endif
+
 #define gray_width 16
 #define gray_height 16
 static char gray_bits[] = {
@@ -103,7 +133,6 @@
     GC gc;			/* graphics context for gray background */
     XImage grayimage;		/* for gray background */
     XGCValues xgc;		/* to create font GCs */
-    char *malloc();
     Bool fallbackMFont = False,	/* using default GC font for menus, */
          fallbackPFont = False,	/* popups, */
          fallbackIFont = False;	/* icons */
@@ -115,6 +144,10 @@
 #ifdef PROFIL
     signal(SIGTERM, ptrap);
 #endif
+#ifdef SIGCHLD
+    /* no zombies */
+    clear_children();
+#endif
 
     /*
      * Set up internal defaults.
@@ -369,7 +402,7 @@
     if (IFontInfo == NULL) {
         fprintf(stderr, "uwm: Unable to open icon font '%s', using server default.\n",
                 IFontName);
-	IFontInfo = XQueryFont(dpy, DefaultGC(dpy, scr)->gid);
+	IFontInfo = XQueryFont(dpy, XGContextFromGC(DefaultGC(dpy, scr)));
 	fallbackIFont = True;
     }
     PFontInfo = XLoadQueryFont(dpy, PFontName);
@@ -379,7 +412,7 @@
 	if (fallbackIFont)
 	    PFontInfo = IFontInfo;
 	else
-	    PFontInfo = XQueryFont(dpy, DefaultGC(dpy, scr)->gid);
+	    PFontInfo = XQueryFont(dpy, XGContextFromGC(DefaultGC(dpy, scr)));
 	fallbackPFont = True;
     }
     MFontInfo = XLoadQueryFont(dpy, MFontName);
@@ -389,7 +422,7 @@
 	if (fallbackIFont || fallbackPFont)
 	    MFontInfo = fallbackPFont ? PFontInfo : IFontInfo;
 	else
-	    MFontInfo = XQueryFont(dpy, DefaultGC(dpy, scr)->gid);
+	    MFontInfo = XQueryFont(dpy, XGContextFromGC(DefaultGC(dpy, scr)));
 	fallbackMFont = True;
     }
 
@@ -685,7 +718,11 @@
  */
 InitBindings()
 {
+#ifdef HAVE_MKSTEMP
+    int fd;
+#else
     char *mktemp();
+#endif
     char *tempfile;		/* Temporary filename. */
     register FILE *fp;		/* Temporary file pointer. */
     register char **ptr;	/* Default bindings string array pointer. */
@@ -699,15 +736,26 @@
 	exit (1);
     }
     strcpy (tempfile, TEMPFILE);
+#ifdef HAVE_MKSTEMP
+    if ((fd = mkstemp(tempfile)) < 0 || (fp = fdopen(fd, "r+")) == NULL) {
+        perror("uwm: cannot create temp file");
+        exit(1);
+    }
+#else
     sfilename = mktemp(tempfile);
     if ((fp = fopen(tempfile, "w")) == NULL) {
         perror("uwm: cannot create temp file");
         exit(1);
     }
+#endif
     for (ptr = DefaultBindings; *ptr; ptr++) {
         fputs(*ptr, fp);
         fputc('\n', fp);
     }
+#ifdef HAVE_MKSTEMP
+    rewind(fp);
+    yyin = fp;
+#else
     fclose(fp);
 
     /*
@@ -717,6 +765,7 @@
         perror("uwm: cannot open temp file");
         exit(1);
     }
+#endif
     Lineno = 1;
     yyparse();
     fclose(yyin);
