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