Feature Request ID: 1669025
[csql.git] / src / server / Server.c
blob01582eed56af6af5475908cb6b56e8c8dcf7f36b
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<CSql.h>
17 #include<SessionImpl.h>
18 #include<Debug.h>
20 int srvStop =0;
21 static void sigTermHandler(int sig)
23 printf("Received signal %d\nStopping the server\n", sig);
24 srvStop = 1;
26 //TODO::user process registration and deregistration
27 int main()
29 SessionImpl session;
30 DbRetVal rv = session.readConfigFile();
31 if (rv != OK)
33 printf("Unable to read the configuration file \n");
34 return -1;
36 os::signal(SIGINT, sigTermHandler);
37 os::signal(SIGTERM, sigTermHandler);
38 rv = logger.startLogger(config.getLogFile(), true);
39 if (rv != OK)
41 printf("Unable to start the logger\n");
42 return -1;
45 logFinest(logger, "Server Started");
46 int ret = session.initSystemDatabase();
47 if (0 != ret)
49 printf(" System Database Initialization failed\n");
50 return -1;
52 printf("System Database initialized\n");
55 printf("Database server started\n");
56 bool end = false;
58 struct timeval timeout;
59 timeout.tv_sec = 5;
60 timeout.tv_usec = 0;
62 while(!srvStop)
64 os::select(0, 0, 0, 0, &timeout);
66 printf("Server Exiting\n");
67 session.destroySystemDatabase();
68 logFinest(logger, "Server Ended");
69 return 0;