File: child_sync.c

package info (click to toggle)
xfreecd 0.9.0.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze
  • size: 1,572 kB
  • ctags: 333
  • sloc: ansic: 5,253; makefile: 59
file content (65 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* -----------------------------------------------------------------------
   child process synchronization functions

   part of XfreeCD

   Copyright 1998 by Brian C. Lane
   http://www.brianlane.com/

   ==========================[ HISTORY ]==================================
   05/09/98    Moved these functions into this seperate file

   ----------------------------------------------------------------------- */
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>



/*
   Synchronize with the parent process. Wait until we receive a 'P'
   from the parent. Send a 'C' to the parent in response

   Return a 0 if all went ok
   Return a -1 if something went wrong
*/
int parent_sync( int fd )
{
  char c;

  if( read( fd, &c, 1 ) != 1 )
    return(-1);

  if( write( fd, "C", 1 ) != 1 )
    return(-1);

  return(0);
}



/*
   Synchronize with the child process. Send a 'P' to the child and wait
   until a 'C' is received back.

   Return a 0 if all went ok
   Return a -1 if something went wrong
*/
int child_sync( int fd )
{
  char c;

  if( write( fd, "P", 1 ) != 1 )
    return(-1);

  if( read( fd, &c, 1 ) != 1 )
    return(-1);

  if( c != 'C' )
    return(-1);

  return(0);
}