OpenDNSSEC-signer  2.0.4
ods-signerd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 NLNet Labs. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
32 #include "config.h"
33 #include "daemon/engine.h"
34 
35 #include <getopt.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <libxml/parser.h>
39 
40 
41 #define AUTHOR_NAME "Matthijs Mekking"
42 #define COPYRIGHT_STR "Copyright (C) 2008-2010 NLnet Labs OpenDNSSEC"
43 
44 
49 static void
50 usage(FILE* out)
51 {
52  fprintf(out, "Usage: %s [OPTIONS]\n", "ods-signerd");
53  fprintf(out, "Start the OpenDNSSEC signer engine daemon.\n\n");
54  fprintf(out, "Supported options:\n");
55  fprintf(out, " -c | --config <cfgfile> Read configuration from file.\n");
56  fprintf(out, " -d | --no-daemon Do not daemonize the signer "
57  "engine.\n");
58  fprintf(out, " -1 | --single-run Run once, then exit.\n");
59  fprintf(out, " -h | --help Show this help and exit.\n");
60  fprintf(out, " -i | --info Print configuration and exit.\n");
61  fprintf(out, " -v | --verbose Increase verbosity.\n");
62  fprintf(out, " -V | --version Show version and exit.\n");
63  fprintf(out, "\nBSD licensed, see LICENSE in source package for "
64  "details.\n");
65  fprintf(out, "Version %s. Report bugs to <%s>.\n",
66  PACKAGE_VERSION, PACKAGE_BUGREPORT);
67 }
68 
69 
74 static void
75 version(FILE* out)
76 {
77  fprintf(out, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
78  fprintf(out, "Written by %s.\n\n", AUTHOR_NAME);
79  fprintf(out, "%s. This is free software.\n", COPYRIGHT_STR);
80  fprintf(out, "See source files for more license information\n");
81  exit(0);
82 }
83 
84 static void
85 program_setup(int cmdline_verbosity)
86 {
87  ods_log_init("ods-signerd", 0, NULL, cmdline_verbosity);
88  ods_log_verbose("[engine] starting signer");
89 
90  /* initialize */
91  xmlInitGlobals();
92  xmlInitParser();
93  xmlInitThreads();
94 
95  tzset(); /* for portability */
96 }
97 
98 static void
99 program_teardown()
100 {
101  xmlCleanupParser();
102  xmlCleanupGlobals();
103  xmlCleanupThreads();
104  ods_log_close();
105 }
106 
111 int
112 main(int argc, char* argv[])
113 {
114  int c, returncode;
115  int options_index = 0;
116  int info = 0;
117  int single_run = 0;
118  int daemonize = 1;
119  int cmdline_verbosity = 0;
120  char *time_arg = NULL;
121  const char* cfgfile = ODS_SE_CFGFILE;
122  static struct option long_options[] = {
123  {"single-run", no_argument, 0, '1'},
124  {"config", required_argument, 0, 'c'},
125  {"no-daemon", no_argument, 0, 'd'},
126  {"help", no_argument, 0, 'h'},
127  {"info", no_argument, 0, 'i'},
128  {"verbose", no_argument, 0, 'v'},
129  {"version", no_argument, 0, 'V'},
130  {"set-time", required_argument, 0, 256},
131  { 0, 0, 0, 0}
132  };
133 
134  /* parse the commandline */
135  while ((c=getopt_long(argc, argv, "1c:dhivV",
136  long_options, &options_index)) != -1) {
137  switch (c) {
138  case '1':
139  single_run = 1;
140  break;
141  case 'c':
142  cfgfile = optarg;
143  break;
144  case 'd':
145  daemonize = 0;
146  break;
147  case 'h':
148  usage(stdout);
149  exit(0);
150  break;
151  case 'i':
152  info = 1;
153  break;
154  case 'v':
155  cmdline_verbosity++;
156  break;
157  case 'V':
158  version(stdout);
159  exit(0);
160  break;
161  case 256:
162  time_arg = optarg;
163  break;
164  default:
165  usage(stderr);
166  exit(2);
167  break;
168  }
169  }
170  argc -= optind;
171  argv += optind;
172  if (argc != 0) {
173  usage(stderr);
174  exit(2);
175  }
176 
177  if (time_arg) {
178  if(set_time_now_str(time_arg)) {
179  fprintf(stderr, "Error: Failed to interpret start time argument. Daemon not started.\n");
180  return 1;
181  }
182  }
183 
184  /* main stuff */
185  fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION);
186 
187  program_setup(cmdline_verbosity);
188  returncode = engine_start(cfgfile, cmdline_verbosity, daemonize,
189  info, single_run);
190  program_teardown();
191 
192  return returncode;
193 }
int engine_start(const char *cfgfile, int cmdline_verbosity, int daemonize, int info, int single_run)
Definition: engine.c:945
#define AUTHOR_NAME
Definition: ods-signerd.c:41
int main(int argc, char *argv[])
Definition: ods-signerd.c:112
#define COPYRIGHT_STR
Definition: ods-signerd.c:42