mux/src/sqlslave.cpp

Go to the documentation of this file.
00001 // sqlslave.cpp -- This slave does SQL queries.
00002 //
00003 // $Id: sqlslave.cpp,v 1.3 2006/01/02 07:34:18 sdennis Exp $
00004 //
00005 #include "autoconf.h"
00006 #include "config.h"
00007 #include <dbi/dbi.h>
00008 
00009 #define MAX_STRING 1000
00010 
00011 int main(int argc, char *argv[])
00012 {
00013     pid_t parent_pid = getppid();
00014     if (parent_pid == 1)
00015     {
00016         // Our real parent process is gone, and we have been inherited by the
00017         // init process.
00018         //
00019         return 1;
00020     }
00021 
00022     dbi_conn conn;
00023     dbi_initialize(NULL);
00024 
00025     for (;;)
00026     {
00027         char arg[MAX_STRING];
00028         int len = read(0, arg, sizeof(arg)-1);
00029         if (len == 0)
00030         {
00031             break;
00032         }
00033 
00034         if (len < 0)
00035         {
00036             if (EINTR == errno)
00037             {
00038                 errno = 0;
00039                 continue;
00040             }
00041             break;
00042         }
00043 
00044         arg[len] = '\0';
00045 
00046         write(1, "OK", 2);
00047     }
00048 
00049     dbi_shutdown();
00050     return 0;
00051 }

Generated on Mon May 28 04:40:11 2007 for MUX by  doxygen 1.4.7