#include #include #include "dat.h" #include "fns.h" /* makes pipe (3) files */ int makepipe(char *pipename) { int pipefd; char *pipe; ulong mode = 0777L; pipe="#|"; if(verbosity == UP){ print("-making pipe %s-", pipename); } if((pipefd = create(pipename, OREAD, DMDIR | mode)) < 0){ sysfatal("couldnt create pipe!\n"); } bind(pipe, pipename, MREPL); close(pipefd); return pipefd; } /* creates a pipe and opens name/data1 for reading, allowing user processes to claim name/data for writing */ int mkrdfd(char *name) { int fd; char fullname[SMBUF]; sprint(fullname, "%s/data1", name); makepipe(name); if((fd = open(fullname, OREAD)) < 0){ sysfatal("cant make pipe for reading\n"); } if(verbosity == UP){ print("-opened %s for reading on fd %d-", fullname, fd); } if((nohold != 'y') && (fdcounter < MAXHOLD)){ sprint(fullname, "%s/data",name); if(verbosity == UP){ print("holding %s-", fullname); } extrafds[fdcounter] = open(fullname, OREAD); if(extrafds[fdcounter] < 0){ print("problems grabbing spare fd to hold \n"); } fdcounter++; } return fd; } /* creates a pipe and opens name/data for writing, allowing user processes to claim name/data1 for reading */ int mkwrfd(char *name) { int fd; char fullname[SMBUF]; sprint(fullname, "%s/data", name); makepipe(name); if ((fd = open(fullname, OWRITE)) < 0){ sysfatal("cant make pipe for writing\n"); } if(verbosity == UP){ print("-opened %s for writing on fd %d-", fullname, fd); } if((nohold != 'y') && (fdcounter < MAXHOLD)){ strcat(fullname, "1"); if(verbosity == UP){ print("holding %s-", fullname); } extrafds[fdcounter] = open(fullname, OREAD); if(extrafds[fdcounter] < 0){ print("problems grabbing spare fd to hold \n"); } fdcounter++; } return fd; } /* connects a new fd to a Hub for output from the Hub */ int newout(Hub *h, char *name) { if(h->outfdcount == MAXFDS - 1){ print("TOO MANY FILE OUTPUT DESCRIPTORS!\n"); return -1; } h->outfds[h->outfdcount] = mkwrfd(name); h->outfdcount++; return 0; } /* connects a new fd to a Hub for input to the Hub */ int newin(Hub *h, char *name) { if(h->infdcount == MAXFDS - 1){ print("TOO MANY INPUT FILE DESCRIPTORS!\n"); return -1; } h->infds[h->infdcount] = mkrdfd(name); h->infdcount++; return 0; }