2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 #include <threading/thread.h>
27 * Conftest globals struct
32 * Print usage information
34 static void usage(char *error
)
41 fprintf(out
, "%s\n", error
);
45 fprintf(out
, "strongSwan %s conftest\n", VERSION
);
47 fprintf(out
, "Usage:\n");
48 fprintf(out
, " --help show usage information\n");
49 fprintf(out
, " --version show conftest version\n");
50 fprintf(out
, " --suite <file> global testsuite configuration "
51 "(default: ./suite.conf)\n");
52 fprintf(out
, " --test <file> test specific configuration\n");
56 * Handle SIGSEGV/SIGILL signals raised by threads
58 static void segv_handler(int signal
)
60 fprintf(stderr
, "thread %u received %d", thread_current_id(), signal
);
65 * Load suite and test specific configurations
67 static bool load_configs(char *suite_file
, char *test_file
)
71 fprintf(stderr
, "Missing test configuration file.\n");
74 if (access(suite_file
, R_OK
) != 0)
76 fprintf(stderr
, "Reading suite configuration file '%s' failed: %s.\n",
77 suite_file
, strerror(errno
));
80 if (access(test_file
, R_OK
) != 0)
82 fprintf(stderr
, "Reading test configuration file '%s' failed: %s.\n",
83 test_file
, strerror(errno
));
86 conftest
->suite
= settings_create(suite_file
);
87 conftest
->test
= settings_create(test_file
);
92 * atexit() cleanup handler
96 DESTROY_IF(conftest
->suite
);
97 DESTROY_IF(conftest
->test
);
105 * Main function, starts the conftest daemon.
107 int main(int argc
, char *argv
[])
109 struct sigaction action
;
113 char *suite_file
= "suite.conf", *test_file
= NULL
;
114 file_logger_t
*logger
;
116 if (!library_init(NULL
))
119 return SS_RC_LIBSTRONGSWAN_INTEGRITY
;
121 if (!libhydra_init("conftest"))
125 return SS_RC_INITIALIZATION_FAILED
;
127 if (!libcharon_init())
132 return SS_RC_INITIALIZATION_FAILED
;
137 logger
= file_logger_create(stdout
, NULL
, FALSE
);
138 logger
->set_level(logger
, DBG_ANY
, LEVEL_CTRL
);
139 charon
->bus
->add_listener(charon
->bus
, &logger
->listener
);
140 charon
->file_loggers
->insert_last(charon
->file_loggers
, logger
);
146 struct option long_opts
[] = {
147 { "help", no_argument
, NULL
, 'h' },
148 { "version", no_argument
, NULL
, 'v' },
149 { "suite", required_argument
, NULL
, 's' },
150 { "test", required_argument
, NULL
, 't' },
153 switch (getopt_long(argc
, argv
, "", long_opts
, NULL
))
161 printf("strongSwan %s conftest\n", VERSION
);
170 usage("Invalid option.");
176 if (!load_configs(suite_file
, test_file
))
181 if (!charon
->initialize(charon
))
186 /* set up thread specific handlers */
187 action
.sa_handler
= segv_handler
;
189 sigemptyset(&action
.sa_mask
);
190 sigaddset(&action
.sa_mask
, SIGINT
);
191 sigaddset(&action
.sa_mask
, SIGTERM
);
192 sigaddset(&action
.sa_mask
, SIGHUP
);
193 sigaction(SIGSEGV
, &action
, NULL
);
194 sigaction(SIGILL
, &action
, NULL
);
195 sigaction(SIGBUS
, &action
, NULL
);
196 action
.sa_handler
= SIG_IGN
;
197 sigaction(SIGPIPE
, &action
, NULL
);
198 pthread_sigmask(SIG_SETMASK
, &action
.sa_mask
, NULL
);
200 /* start thread pool */
201 charon
->start(charon
);
203 /* handle SIGINT/SIGTERM in main thread */
205 sigaddset(&set
, SIGINT
);
206 sigaddset(&set
, SIGHUP
);
207 sigaddset(&set
, SIGTERM
);
208 sigprocmask(SIG_BLOCK
, &set
, NULL
);
210 while (sigwait(&set
, &sig
) == 0)
216 fprintf(stderr
, "\nshutting down...\n");