diff options
Diffstat (limited to 'src/blogc-runserver')
-rw-r--r-- | src/blogc-runserver/httpd.c | 5 | ||||
-rw-r--r-- | src/blogc-runserver/main.c | 18 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c index 195bad0..1312ec9 100644 --- a/src/blogc-runserver/httpd.c +++ b/src/blogc-runserver/httpd.c @@ -212,6 +212,11 @@ int br_httpd_run(const char *host, unsigned short port, const char *docroot, size_t max_threads) { + if (port == 0) { + fprintf(stderr, "Invalid port: 0\n"); + return 1; + } + thread_data_t threads[max_threads]; for (size_t i = 0; i < max_threads; i++) threads[i].initialized = false; diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c index 4563a66..0b8d0fe 100644 --- a/src/blogc-runserver/main.c +++ b/src/blogc-runserver/main.c @@ -54,6 +54,8 @@ main(int argc, char **argv) char *docroot = NULL; unsigned short port = 8080; size_t max_threads = 20; + char *ptr; + char *endptr; unsigned int args = 0; @@ -74,15 +76,23 @@ main(int argc, char **argv) break; case 'p': if (argv[i][2] != '\0') - port = strtoul(argv[i] + 2, NULL, 10); + ptr = argv[i] + 2; else - port = strtoul(argv[++i], NULL, 10); + ptr = argv[++i]; + port = strtoul(ptr, &endptr, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "blogc-runserver: warning: invalid value " + "for -p argument: %s. using %hu instead\n", ptr, port); break; case 'm': if (argv[i][2] != '\0') - max_threads = strtoul(argv[i] + 2, NULL, 10); + ptr = argv[i] + 2; else - max_threads = strtoul(argv[++i], NULL, 10); + ptr = argv[++i]; + max_threads = strtoul(argv[++i], NULL, 10); + if (*ptr != '\0' && *endptr != '\0') + fprintf(stderr, "blogc-runserver: warning: invalid value " + "for -m argument: %s. using %zu instead\n", ptr, max_threads); break; default: print_usage(); |