Log XML/XSLT errors to yaz_log.
[pazpar2-moved-to-github.git] / src / pazpar2.c
1 /* $Id: pazpar2.c,v 1.94 2008-02-18 19:33:32 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #if HAVE_CONFIG_H
23 #include "cconfig.h"
24 #endif
25
26
27 #include <signal.h>
28 #include <assert.h>
29
30 #include "pazpar2.h"
31 #include "database.h"
32 #include "settings.h"
33 #include <yaz/daemon.h>
34
35 void child_handler(void *data)
36 {
37     start_proxy();
38     init_settings();
39
40     if (*global_parameters.settings_path_override)
41         settings_read(global_parameters.settings_path_override);
42     else if (global_parameters.server->settings)
43         settings_read(global_parameters.server->settings);
44     else
45         yaz_log(YLOG_WARN, "No settings-directory specified");
46     global_parameters.odr_in = odr_createmem(ODR_DECODE);
47     global_parameters.odr_out = odr_createmem(ODR_ENCODE);
48
49
50     pazpar2_event_loop();
51
52 }
53
54 static void show_version(void)
55 {
56     char yaz_version_str[80];
57     printf("Pazpar2 " VERSION "\n");
58
59     yaz_version(yaz_version_str, 0);
60
61     printf("Configuration:");
62 #if HAVE_ICU
63     printf(" icu:?");
64 #endif
65     printf(" yaz:%s", yaz_version_str);
66     printf("\n");
67     exit(0);
68 }            
69
70 int main(int argc, char **argv)
71 {
72     int daemon = 0;
73     int ret;
74     int log_file_in_use = 0;
75     char *arg;
76     const char *pidfile = 0;
77     const char *uid = 0;
78
79     if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
80         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
81
82     yaz_log_init_prefix("pazpar2");
83 #if YAZ_VERSIONL >= 0x03001B
84     yaz_log_xml_errors(0, YLOG_WARN);
85 #endif
86
87     while ((ret = options("dDf:h:l:p:t:u:VX", argv, argc, &arg)) != -2)
88     {
89         switch (ret)
90         {
91         case 'd':
92             global_parameters.dump_records = 1;
93             break;
94         case 'D':
95             daemon = 1;
96             break;
97         case 'f':
98             if (!read_config(arg))
99                 exit(1);
100             break;
101         case 'h':
102             strcpy(global_parameters.listener_override, arg);
103             break;
104         case 'l':
105             yaz_log_init_file(arg);
106             log_file_in_use = 1;
107             break;
108         case 'p':
109             pidfile = arg;
110             break;
111         case 't':
112             strcpy(global_parameters.settings_path_override, arg);
113             break;
114         case 'u':
115             uid = arg;
116             break;
117         case 'V':
118             show_version();
119         case 'X':
120             global_parameters.debug_mode = 1;
121             break;
122         default:
123             fprintf(stderr, "Usage: pazpar2\n"
124                     "    -d                      (show internal records)\n"
125                     "    -D                      Daemon mode (background)\n"
126                     "    -f configfile\n"
127                     "    -h [host:]port          (REST protocol listener)\n"
128                     "    -l file                 log to file\n"
129                     "    -p pidfile              PID file\n"
130                     "    -t settings\n"
131                     "    -u uid\n"
132                     "    -V                      show version\n"
133                     "    -X                      debug mode\n"
134                 );
135             exit(1);
136         }
137     }
138
139     yaz_log(YLOG_LOG, "Pazpar2 %s started", VERSION);
140     if (daemon && !log_file_in_use)
141     {
142         yaz_log(YLOG_FATAL, "Logfile must be given (option -l) for daemon "
143                 "mode");
144         exit(1);
145     }
146     if (!config)
147     {
148         yaz_log(YLOG_FATAL, "Load config with -f");
149         exit(1);
150     }
151     global_parameters.server = config->servers;
152
153     start_http_listener();
154     yaz_daemon("pazpar2",
155                (global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
156                (daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
157                child_handler, 0 /* child_data */,
158                pidfile, uid);
159     return 0;
160 }
161
162
163 /*
164  * Local variables:
165  * c-basic-offset: 4
166  * indent-tabs-mode: nil
167  * End:
168  * vim: shiftwidth=4 tabstop=8 expandtab
169  */