This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

mknod implementation clarification...thanks for the help


Here's the sample code that calls mknod.  I always do a bad job of
explaining in words what I'm trying to accomplish.
Hopefully the sample code does a better job of it.  I'm glad to hear that plans are in the work to include this
capability.

A series of "write" commands are made to gvFD to communicate with geomview.

Thanks again

Jim Barker

int GVdriver::StartGeomview()
{
     pipename = new char[40];
     sprintf(pipename,"/tmp/geomview/GVU%0iP%0i",getuid(),getpid());

     char *args[5];
     args[0] = "geomview";
     args[1] = "-Mcp";
     args[2] = pipename;
     args[3] = "-nopanels";
     args[4] = NULL;
     gvFD=-1;
     #ifndef __GNUC__
     if(access("/tmp/geomview",W_ACC) <0) {
     #else
     if(access("/tmp/geomview",W_OK) <0) {
     #endif
          mkdir("/tmp/geomview",0777);
          chmod("/tmp/geomview",0777);  //sometimes mkdir doesn't work!?
          }
     #ifndef __GNUC__
     if(access(pipename,E_ACC)<0) {
     #else
     if(access(pipename,F_OK)<0) {
     #endif
          mknod(pipename, S_IFIFO | 0660 , 0);
          }

     gvFD = open(pipename, O_WRONLY | O_NONBLOCK);
     if(gvFD >= 0) {
          #ifndef __GNUC__
          fcntl(gvFD, F_SETFL, fcntl(gvFD, F_GETFL, 0) & ~(FNDELAY|FNONBLOCK|O_NONBLOCK));
          #else
          fcntl(gvFD, F_SETFL, fcntl(gvFD, F_GETFL, 0) & ~(FNDELAY|FNONBIO|O_NONBLOCK));
          #endif
     } else if(errno == ENXIO) {
          gvPID=fork();
          if(gvPID==0) {
               close(0);
               #ifndef __GNUC__
               setpgrp(0,0);
               #else
               setpgrp();
               #endif
               execvp("geomview",args);
               perror("couldn't start geomview");
               kill(getppid(), SIGALRM);
               _exit(1);
               }

          alarm(60);
          gvFD = open(pipename, O_WRONLY);
          alarm(0);
          unlink(pipename);

          }

     if(gvFD<0) {
          fprintf(stderr,"Gotta give up trying to pipe to geomview: ");
          perror(pipename);
          }


     return 0;
     }



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]