home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / iutil / lock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  1.6 KB  |  79 lines

  1. # include    <stdio.h>
  2. # include    <sys/types.h>
  3. # include    <sys/socket.h>
  4. # include    <netinet/in.h>
  5. # include    <arpa/inet.h>
  6. # include    <netdb.h>
  7. # include    <signal.h>
  8. # include    <setjmp.h>
  9.  
  10. /*
  11. ** start_up_lock_driver
  12. **    Attempt to start up a connection to the lock driver.
  13. **    We connect to a know address (a socket server sits there).
  14. **    If we get a connection on this location, than we are talking 
  15. **    to the lock driver. If we timeout, then we assume the driver 
  16. **    isn't there.
  17. **
  18. ** Returns
  19. **    File descriptor attached to the lock driver
  20. **    -1 on any error.
  21. **
  22. ** Trace Flags
  23. **    28
  24. */
  25. start_up_lock_driver()
  26. {
  27.     struct    sockaddr_in    addr;        /* address to attach to for server */
  28.     register    int    to_driver;    /* we can talk to the lock driver on this one */
  29.     struct        servent    *ing_ser;
  30.  
  31.  
  32.     /*
  33.     ** Find out where the lock driver lives
  34.     */
  35.     if ( (ing_ser = getservbyname("ingreslock",(char *)0)) == 0 )
  36.     {
  37. #        ifdef xATR1
  38.         if ( tTf(28,4) )
  39.             perror("set_up_lock getservbyname");
  40. #        endif
  41.         return ( -1 );
  42.     }
  43.  
  44.     /*
  45.     ** Make our end of the socket
  46.     */
  47.     if ( (to_driver = socket(AF_INET,SOCK_STREAM,0)) == -1 )
  48.     {
  49. #        ifdef xATR1
  50.         if ( tTf(28,4) )
  51.             perror("set_up_lock socket");
  52. #        endif
  53.         return ( -1 );
  54.     }
  55.  
  56.     bzero((char *) &addr,sizeof (addr));
  57.     addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  58.     addr.sin_family = AF_INET;
  59.     addr.sin_port = ing_ser->s_port;
  60.  
  61.  
  62.     /*
  63.     ** Connect to the lock_driver
  64.     */
  65.     if ( connect(to_driver,(struct sockaddr *)&addr,sizeof (addr)) == -1 )
  66.     {
  67. #    ifdef xATR1
  68.         if ( tTf(28,4) )
  69.             perror("set_up_lock connect");
  70. #    endif
  71.         close(to_driver);
  72.         return ( -1 );
  73.     }
  74.  
  75.  
  76.     return ( to_driver );
  77. }/* start_up_lock_driver */
  78.  
  79.