Made -D option work. Get private key and certificate file from cmd-line

This commit is contained in:
Tatsuhiro Tsujikawa 2012-06-07 00:03:05 +09:00
parent 8e0a1c91a3
commit 908ec2e695
1 changed files with 20 additions and 2 deletions

View File

@ -227,11 +227,13 @@ int event_loop()
namespace { namespace {
void fill_default_config() void fill_default_config()
{ {
mod_config()->daemon = false;
mod_config()->server_name = "shrpx spdylay/"SPDYLAY_VERSION; mod_config()->server_name = "shrpx spdylay/"SPDYLAY_VERSION;
mod_config()->host = "localhost"; mod_config()->host = "localhost";
mod_config()->port = 3000; mod_config()->port = 3000;
mod_config()->private_key_file = "server.key"; mod_config()->private_key_file = 0;
mod_config()->cert_file = "server.crt"; mod_config()->cert_file = 0;
mod_config()->upstream_read_timeout.tv_sec = 30; mod_config()->upstream_read_timeout.tv_sec = 30;
mod_config()->upstream_read_timeout.tv_usec = 0; mod_config()->upstream_read_timeout.tv_usec = 0;
@ -402,6 +404,15 @@ int main(int argc, char **argv)
} }
} }
if(argc-optind < 2) {
print_usage(std::cerr);
std::cerr << "Too few arguments" << std::endl;
exit(EXIT_FAILURE);
}
mod_config()->private_key_file = argv[optind++];
mod_config()->cert_file = argv[optind++];
char hostport[NI_MAXHOST]; char hostport[NI_MAXHOST];
if(get_config()->downstream_port == 80) { if(get_config()->downstream_port == 80) {
mod_config()->downstream_hostport = get_config()->downstream_host; mod_config()->downstream_hostport = get_config()->downstream_host;
@ -415,6 +426,13 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(get_config()->daemon) {
if(daemon(0, 0) == -1) {
perror("daemon");
exit(EXIT_FAILURE);
}
}
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(struct sigaction)); memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = SIG_IGN; act.sa_handler = SIG_IGN;