--- clock/disp.c	Thu Aug 27 15:58:04 1998
+++ clock-azz/disp.c	Fri Mar  9 21:19:17 2001
@@ -151,47 +151,42 @@
 	switch (fork()) {
 	case 0:	/* Child. */
 		close(ConnectionNumber(dpy));
-		switch (fork()) {
-		case 0:
-			close(0);
-			close(fds[0]);
-			dup2(fds[1], 1);
-			dup2(1, 2);
+		close(0);
+		close(fds[0]);
+		dup2(fds[1], 1);
+		dup2(1, 2);
 			
-			execl(sh, sh, "-c", command, 0);
-			fprintf(stderr, "%s: can't exec \"%s -c %s\"\n", argv0, sh,
-				command);
-			exit(EXIT_FAILURE);
-		case -1:
-			fprintf(stderr, "%s: couldn't fork\n", argv0);
-			exit(EXIT_FAILURE);
-		default:
-			exit(EXIT_SUCCESS);
-		}
+		execl(sh, sh, "-c", command, 0);
+		fprintf(stderr, "%s: can't exec \"%s -c %s\"\n", argv0, sh,
+			command);
+		exit(EXIT_FAILURE);
 	case -1:	/* Error. */
 		fprintf(stderr, "%s: couldn't fork\n", argv0);
+		string = "Couldn't fork";
 		break;
 	default: {
 		/* Read from the pipe. */
 		char buf[BUFSIZ];
-		int n;
+		int n, count = 0;
 		
 		close(fds[1]);
-		
-		while ((n = read(fds[0], buf, BUFSIZ)) > 0) {
-			int valid = 0;
-			char * p = buf;
 
-			/* How many of the characters do we want? */
-			while (*p++ >= ' ') valid++;
-			
-			string = (char *) malloc(valid + 1);
-			if (string != 0)
-				strncpy(string, buf, valid);
-			else
-				string = "Out of memory";
+		/* Read as much as possible into the buffer. */
+		while ((n = read(fds[0], buf + count, BUFSIZ - count)) > 0) {
+			count += n;
 		}
+
+		/* Replace the first control character (or, failing that,
+		   the last character in the buffer) with \0. */
+		n = 0;
+		while (n < (count - 1) && buf[n] >= ' ') n++;
+		buf[n] = '\0';
 		
+		/* Return a copy of the buffer. */
+		string = (char *)malloc(n + 1);
+		strncpy(string, buf, n + 1);
+
+		/* Wait for the child to exit. */		
 		wait(0);
 		}
 	}
