tcreate polls/ and improve error messaging - vote - simple cgi voting system fo… | |
git clone git://src.adamsgaard.dk/vote | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 7be65d231cd9ea138f2aaa8e06a1ad6c2dc496be | |
parent 71c26ce31eeddf5ccbc2e56c10281ca742648364 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sun, 27 Sep 2020 00:45:20 +0200 | |
create polls/ and improve error messaging | |
Diffstat: | |
M vote.c | 11 ++++++++++- | |
1 file changed, 10 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/vote.c b/vote.c | |
t@@ -2,6 +2,8 @@ | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
+#include <sys/stat.h> | |
+#include <errno.h> | |
#define OUT(s) (fputs((s), stdout)) | |
t@@ -38,11 +40,18 @@ main() { | |
char *query; | |
char *q; | |
- if (pledge("stdio", NULL) == -1) { | |
+ if (pledge("stdio cpath", NULL) == -1) { | |
+ fprintf(stderr, "pledge: %s\n", strerror(errno)); | |
OUT("Status: 500 Internal Server Error\r\n\r\n"); | |
exit(1); | |
} | |
+ if (mkdir("polls", 644) == -1) { | |
+ fprintf(stderr, "mkdir polls/ failed: %s\n", strerror(errno)); | |
+ OUT("Status: 500 Internal Server Error\r\n\r\n"); | |
+ exit(0); | |
+ } | |
+ | |
if (!(query = getenv("QUERY_STRING"))) | |
query = ""; | |