aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-runserver
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-14 00:33:39 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-14 00:33:39 +0200
commit613f53b44279c44a8f53783d2dc4410584133431 (patch)
tree1f6bb8c959f523682294824681e9131ece27adfd /src/blogc-runserver
parent8664aa16e2df5d94a594785661283a39340db2fd (diff)
downloadblogc-613f53b44279c44a8f53783d2dc4410584133431.tar.gz
blogc-613f53b44279c44a8f53783d2dc4410584133431.tar.bz2
blogc-613f53b44279c44a8f53783d2dc4410584133431.zip
runserver: blogc/loader: improve strto*l handling
Diffstat (limited to 'src/blogc-runserver')
-rw-r--r--src/blogc-runserver/httpd.c5
-rw-r--r--src/blogc-runserver/main.c18
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();