child_sync.c (1294B)
1 /* ----------------------------------------------------------------------- 2 child process synchronization functions 3 4 part of XfreeCD 5 6 Copyright 1998 by Brian C. Lane 7 nexus@tatoosh.com 8 http://www.tatoosh.com/nexus 9 10 ==========================[ HISTORY ]================================== 11 05/09/98 Moved these functions into this seperate file 12 13 ----------------------------------------------------------------------- */ 14 #include <stdio.h> 15 #include <fcntl.h> 16 #include <sys/ioctl.h> 17 #include <sys/types.h> 18 #include <sys/socket.h> 19 #include <unistd.h> 20 21 22 23 /* 24 Synchronize with the parent process. Wait until we receive a 'P' 25 from the parent. Send a 'C' to the parent in response 26 27 Return a 0 if all went ok 28 Return a -1 if something went wrong 29 */ 30 int parent_sync( int fd ) 31 { 32 char c; 33 34 if( read( fd, &c, 1 ) != 1 ) 35 return(-1); 36 37 if( write( fd, "C", 1 ) != 1 ) 38 return(-1); 39 40 return(0); 41 } 42 43 44 45 /* 46 Synchronize with the child process. Send a 'P' to the child and wait 47 until a 'C' is received back. 48 49 Return a 0 if all went ok 50 Return a -1 if something went wrong 51 */ 52 int child_sync( int fd ) 53 { 54 char c; 55 56 if( write( fd, "P", 1 ) != 1 ) 57 return(-1); 58 59 if( read( fd, &c, 1 ) != 1 ) 60 return(-1); 61 62 if( c != 'C' ) 63 return(-1); 64 65 return(0); 66 }