]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libopensrf/opensrf.c
LP#1243841: quiet a misleading indentation warning
[OpenSRF.git] / src / libopensrf / opensrf.c
1 #include "opensrf/osrf_system.h"
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6
7 /**
8         @brief Run an OSRF server as defined by the command line and a config file.
9         @param argc Number of command line arguments, plus one.
10         @param argv Ragged array of command name plus command line arguments.
11         @return 0 if successful, or 1 if failure.
12
13         Command line parameters:
14         - Full network name of the host where the process is running; or 'localhost' will do.
15         - Name of the configuration file; normally '/openils/conf/opensrf_core.xml'.
16         - Name of an aggregate within the configuration file, containing the relevant subset
17         of configuration stuff.
18 */
19 int main( int argc, char* argv[] ) {
20
21     char* host    = NULL;
22     char* config  = NULL;
23     char* context = NULL;
24     char* piddir  = NULL;
25     char* action  = NULL;
26     char* service = NULL;
27     opterr = 0;
28
29         /* values must be strdup'ed because init_proc_title / 
30      * set_proc_title are evil and overwrite the argv memory */
31
32     int c;
33     while ((c = getopt(argc, argv, "h:c:x:p:a:s:")) != -1) {
34         switch (c) {
35             case 'h':
36                 host = strdup(optarg);
37                 break;
38             case 'c':
39                 config = strdup(optarg);
40                 break;
41             case 'x':
42                 context = strdup(optarg);
43                 break;
44             case 'p':
45                 piddir = strdup(optarg);
46                 break;
47             case 'a':
48                 action = strdup(optarg);
49                 break;
50             case 's':
51                 service = strdup(optarg);
52                 break;
53             default:
54                 continue;
55         }
56     }
57
58
59     if (!(host && config && context && piddir && action)) {
60                 fprintf(stderr, "Usage: %s -h <host> -c <config> "
61             "-x <config_context> -p <piddir>\n", argv[0]);
62                 return 1;
63         }
64
65     // prepare the proc title hack
66     init_proc_title(argc, argv);
67
68     // make sure the service name is valid
69     if (service && strlen(service) == 0) {
70         free(service);
71         service = NULL;
72     }
73
74     int ret = osrf_system_service_ctrl(
75         host, config, context, piddir, action, service);
76
77         if (ret != 0) {
78                 osrfLogError(
79                         OSRF_LOG_MARK,
80                         "Server Loop returned an error condition, exiting with %d",
81                         ret
82                 );
83         }
84
85         free(host);
86         free(config);
87         free(context);
88     free(piddir);
89     free(action);
90     if (service) free(service);
91
92         return ret;
93 }
94
95