OpenDNSSEC-signer  1.3.16
ods-signerd.c
Go to the documentation of this file.
1 /*
2  * $Id: ods-signerd.c 5984 2012-01-02 14:50:59Z 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 
86 
87 
92 int
93 main(int argc, char* argv[])
94 {
95  int c;
96  int options_index = 0;
97  int info = 0;
98  int single_run = 0;
99  int daemonize = 1;
100  int cmdline_verbosity = 0;
101  const char* cfgfile = ODS_SE_CFGFILE;
102  static struct option long_options[] = {
103  {"single-run", no_argument, 0, '1'},
104  {"config", required_argument, 0, 'c'},
105  {"no-daemon", no_argument, 0, 'd'},
106  {"help", no_argument, 0, 'h'},
107  {"info", no_argument, 0, 'i'},
108  {"verbose", no_argument, 0, 'v'},
109  {"version", no_argument, 0, 'V'},
110  { 0, 0, 0, 0}
111  };
112 
113  /* parse the commandline */
114  while ((c=getopt_long(argc, argv, "1c:dhivV",
115  long_options, &options_index)) != -1) {
116  switch (c) {
117  case '1':
118  single_run = 1;
119  break;
120  case 'c':
121  cfgfile = optarg;
122  break;
123  case 'd':
124  daemonize = 0;
125  break;
126  case 'h':
127  usage(stdout);
128  exit(0);
129  break;
130  case 'i':
131  info = 1;
132  break;
133  case 'v':
134  cmdline_verbosity++;
135  break;
136  case 'V':
137  version(stdout);
138  exit(0);
139  break;
140  default:
141  usage(stderr);
142  exit(2);
143  break;
144  }
145  }
146  argc -= optind;
147  argv += optind;
148  if (argc != 0) {
149  usage(stderr);
150  exit(2);
151  }
152 
153 #ifdef ENFORCER_TIMESHIFT
154  if (getenv("ENFORCER_TIMESHIFT")) {
155  fprintf(stdout, "WARNING: timeshift %s detected, running once only\n",
156  getenv("ENFORCER_TIMESHIFT"));
157  single_run = 1;
158  } else {
159  fprintf(stdout, "DEBUG: timeshift mode enabled, but not set.\n");
160  }
161 #endif /* ENFORCER_TIMESHIFT */
162 
163  /* main stuff */
164  fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION);
165  engine_start(cfgfile, cmdline_verbosity, daemonize, info, single_run);
166 
167  /* done */
168  return 0;
169 }
#define AUTHOR_NAME
Definition: ods-signerd.c:42
void engine_start(const char *cfgfile, int cmdline_verbosity, int daemonize, int info, int single_run)
Definition: engine.c:1022
int main(int argc, char *argv[])
Definition: ods-signer.c:340
#define COPYRIGHT_STR
Definition: ods-signerd.c:43