GRASS on Linux 0.96c

Michael Shapiro shapiro at zorro.cecer.army.mil
Wed Jul 22 17:51:53 EDT 1992


This is a mistake on my part. I wrote a version of popen() to allow
multiple popens simultaneously. We should have called it G_popen() and
G_pclose().

A solution is to add -Dpopen=G_popen -Dpclose=G_pclose to the definition
of CFLAGS in the header for gamek4.0 and recompile everything.

|When I run GISGEN or gmake4.0 in the src/libes/gis directory I get the 
|following
|
|rm -f OBJ/popen.o
|cc -O -DGETHOSTNAME_OK -I/grass/src/libes -DUSE_TERMIO -c popen.c
|
|popen.c: In function 'popen':
|popen.c:15: argument 'cmd' doesn't match prototype
|popen.c:15: argument 'mode' doesn't match prototype
|popen.c: In function 'pclose':
|popen.c:54: warning: assignment from incompatible pointer type
|popen.c:55:   "          "        "       "          "      "
|popen.c:56:   "          "	  " 	  "	     "      "
|popen.c:64: warning: passing arg 2 of 'signal' from incompatible pointer
|type
|popen.c:65:   "
|popen.c:66:   "
|
|make: *** [OBJ/popen.o] Error 1.
|
|
|I'm no C wizard so please politely tell me if I should go home and read up
|on functions first!. I have included the popen.c file below. Thanks for any
|help.
|
|Alastair J. Small
|asmall2 at mach1.wlu.ca 
|
|-------------------------------------------------------------------------
|#include <stdio.h>
|#include <signal.h>
|#define tst(a,b)        (*mode == 'r'? (b) : (a))
|
|#define READ      0
|#define WRITE     1
|
|static  int     popen_pid[50];
|
|FILE *
|popen(cmd,mode)
|    char    *cmd;
|    char    *mode;
|{
|    int p[2];
|    int me, you, pid;
|
|    fflush (stdout);
|    fflush (stderr);
|
|    if(pipe(p) < 0)
|	return NULL;
|    me = tst(p[WRITE], p[READ]);
|    you = tst(p[READ], p[WRITE]);
|    if((pid = fork()) == 0)
|    {
|/* me and you reverse roles in child */
|	close(me);
|	close(tst(0, 1));
|	dup(you);
|	close(you);
|	execl("/bin/sh", "sh", "-c", cmd, 0);
|	_exit(1);
|    }
|
|    if(pid == -1)
|	return NULL;
|    popen_pid[me] = pid;
|    close(you);
|
|    return(fdopen(me, mode));
|}
|
|pclose(ptr)
|    FILE *ptr;
|{
|    int f, r, (*sighup)(), (*sigint)(), (*sigquit)();
|    int status;
|
|    f = fileno(ptr);
|    fclose(ptr);
|
|    sigint  = signal(SIGINT, SIG_IGN);
|    sigquit = signal(SIGQUIT, SIG_IGN);
|    sighup  = signal(SIGHUP, SIG_IGN);
|
|    while((r = wait(&status)) != popen_pid[f] && r != -1)
|	    ;
|
|    if(r == -1)
|	status = -1;
|
|    signal(SIGINT, sigint);
|    signal(SIGQUIT, sigquit);
|    signal(SIGHUP, sighup);
|
|    return(status);
|}
|
|



Michael



More information about the grass-user mailing list