tcheck if polls/ exists, create it if not - vote - simple cgi voting system for… | |
git clone git://src.adamsgaard.dk/vote | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 338931d646f13dcfa659fe1ecebefcc79abdda1b | |
parent cb2cf1d1ce9a181c872544f55ef5531725e57864 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sun, 27 Sep 2020 01:09:12 +0200 | |
check if polls/ exists, create it if not | |
Diffstat: | |
M vote.c | 15 ++++++++++----- | |
1 file changed, 10 insertions(+), 5 deletions(-) | |
--- | |
diff --git a/vote.c b/vote.c | |
t@@ -6,6 +6,7 @@ | |
#include <errno.h> | |
#define OUT(s) (fputs((s), stdout)) | |
+#define POLLS_DIR "polls" | |
void | |
print_html_head() { | |
t@@ -39,17 +40,21 @@ int | |
main() { | |
char *query; | |
char *q; | |
+ struct stat sb; | |
- if (pledge("stdio cpath", NULL) == -1) { | |
+ if (pledge("stdio cpath rpath", NULL) == -1) { | |
fprintf(stderr, "pledge: %s\n", strerror(errno)); | |
OUT("Status: 500 Internal Server Error\r\n\r\n"); | |
exit(1); | |
} | |
+ if (stat(POLLS_DIR, &sb) == -1) { | |
+ fprintf(stderr, "dir %s does not exist: %s\n", POLLS_DIR, stre… | |
- if (mkdir("polls", 0755) == -1) { | |
- fprintf(stderr, "mkdir polls/ failed: %s\n", strerror(errno)); | |
- OUT("Status: 500 Internal Server Error\r\n\r\n"); | |
- exit(0); | |
+ if (mkdir(POLLS_DIR, 0755) == -1) { | |
+ fprintf(stderr, "mkdir polls/ failed: %s\n", strerror(… | |
+ OUT("Status: 500 Internal Server Error\r\n\r\n"); | |
+ exit(0); | |
+ } | |
} | |
if (!(query = getenv("QUERY_STRING"))) |