From 908ec2e69553afe3a566defa4ae3187243b2b7cf Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 7 Jun 2012 00:03:05 +0900 Subject: [PATCH] Made -D option work. Get private key and certificate file from cmd-line --- examples/shrpx.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/examples/shrpx.cc b/examples/shrpx.cc index df026ac..096030b 100644 --- a/examples/shrpx.cc +++ b/examples/shrpx.cc @@ -227,11 +227,13 @@ int event_loop() namespace { void fill_default_config() { + mod_config()->daemon = false; + mod_config()->server_name = "shrpx spdylay/"SPDYLAY_VERSION; mod_config()->host = "localhost"; mod_config()->port = 3000; - mod_config()->private_key_file = "server.key"; - mod_config()->cert_file = "server.crt"; + mod_config()->private_key_file = 0; + mod_config()->cert_file = 0; mod_config()->upstream_read_timeout.tv_sec = 30; 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]; if(get_config()->downstream_port == 80) { mod_config()->downstream_hostport = get_config()->downstream_host; @@ -415,6 +426,13 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } + if(get_config()->daemon) { + if(daemon(0, 0) == -1) { + perror("daemon"); + exit(EXIT_FAILURE); + } + } + struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); act.sa_handler = SIG_IGN;