OpenDNSSEC-signer  1.4.6
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 
39 
40 #define AUTHOR_NAME "Matthijs Mekking"
41 #define COPYRIGHT_STR "Copyright (C) 2008-2010 NLnet Labs OpenDNSSEC"
42 
43 
48 static void
49 usage(FILE* out)
50 {
51  fprintf(out, "Usage: %s [OPTIONS]\n", "ods-signerd");
52  fprintf(out, "Start the OpenDNSSEC signer engine daemon.\n\n");
53  fprintf(out, "Supported options:\n");
54  fprintf(out, " -c | --config <cfgfile> Read configuration from file.\n");
55  fprintf(out, " -d | --no-daemon Do not daemonize the signer "
56  "engine.\n");
57  fprintf(out, " -1 | --single-run Run once, then exit.\n");
58  fprintf(out, " -h | --help Show this help and exit.\n");
59  fprintf(out, " -i | --info Print configuration and exit.\n");
60  fprintf(out, " -v | --verbose Increase verbosity.\n");
61  fprintf(out, " -V | --version Show version and exit.\n");
62  fprintf(out, "\nBSD licensed, see LICENSE in source package for "
63  "details.\n");
64  fprintf(out, "Version %s. Report bugs to <%s>.\n",
65  PACKAGE_VERSION, PACKAGE_BUGREPORT);
66 }
67 
68 
73 static void
74 version(FILE* out)
75 {
76  fprintf(out, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
77  fprintf(out, "Written by %s.\n\n", AUTHOR_NAME);
78  fprintf(out, "%s. This is free software.\n", COPYRIGHT_STR);
79  fprintf(out, "See source files for more license information\n");
80  exit(0);
81 }
82 
83 
88 int
89 main(int argc, char* argv[])
90 {
91  int c;
92  int options_index = 0;
93  int info = 0;
94  int single_run = 0;
95  int daemonize = 1;
96  int cmdline_verbosity = 0;
97  const char* cfgfile = ODS_SE_CFGFILE;
98  static struct option long_options[] = {
99  {"single-run", no_argument, 0, '1'},
100  {"config", required_argument, 0, 'c'},
101  {"no-daemon", no_argument, 0, 'd'},
102  {"help", no_argument, 0, 'h'},
103  {"info", no_argument, 0, 'i'},
104  {"verbose", no_argument, 0, 'v'},
105  {"version", no_argument, 0, 'V'},
106  { 0, 0, 0, 0}
107  };
108 
109  /* parse the commandline */
110  while ((c=getopt_long(argc, argv, "1c:dhivV",
111  long_options, &options_index)) != -1) {
112  switch (c) {
113  case '1':
114  single_run = 1;
115  break;
116  case 'c':
117  cfgfile = optarg;
118  break;
119  case 'd':
120  daemonize = 0;
121  break;
122  case 'h':
123  usage(stdout);
124  exit(0);
125  break;
126  case 'i':
127  info = 1;
128  break;
129  case 'v':
130  cmdline_verbosity++;
131  break;
132  case 'V':
133  version(stdout);
134  exit(0);
135  break;
136  default:
137  usage(stderr);
138  exit(2);
139  break;
140  }
141  }
142  argc -= optind;
143  argv += optind;
144  if (argc != 0) {
145  usage(stderr);
146  exit(2);
147  }
148 
149 #ifdef ENFORCER_TIMESHIFT
150  if (getenv("ENFORCER_TIMESHIFT")) {
151  fprintf(stdout, "WARNING: timeshift %s detected, running once only\n",
152  getenv("ENFORCER_TIMESHIFT"));
153  single_run = 1;
154  } else {
155  fprintf(stdout, "DEBUG: timeshift mode enabled, but not set.\n");
156  }
157 #endif /* ENFORCER_TIMESHIFT */
158 
159  /* main stuff */
160  fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION);
161  engine_start(cfgfile, cmdline_verbosity, daemonize, info, single_run);
162 
163  /* done */
164  return 0;
165 }
#define AUTHOR_NAME
Definition: ods-signerd.c:40
int main(int argc, char *argv[])
Definition: ods-signerd.c:89
void engine_start(const char *cfgfile, int cmdline_verbosity, int daemonize, int info, int single_run)
Definition: engine.c:981
#define COPYRIGHT_STR
Definition: ods-signerd.c:41