From 5b380eec531dc8beece6288b3afc2336dde47ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:38:48 +0800 Subject: [PATCH] add funlock --- cmoe.c | 13 ++++++++++--- cmoe.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmoe.c b/cmoe.c index 142d4ad..a424152 100644 --- a/cmoe.c +++ b/cmoe.c @@ -139,7 +139,7 @@ static void return_count(FILE* fp, char* name, char* theme) { h = H_SMALL; head = (char*)svg_small; } - if(headers(get_content_len(isbig, len_type, cntstr), image/svg+xml)) { + if(headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml")) { write(1, "\0\0\0\0", 4); return; } @@ -210,6 +210,7 @@ int main(int argc, char **argv) { return -3; } return_count(fp, name, theme); + flock(fileno(fp), LOCK_UN); fclose(fp); fp = NULL; return 0; } @@ -231,10 +232,12 @@ int main(int argc, char **argv) { return -5; } if(name_exist(fp, name)) { + flock(fileno(fp), LOCK_UN); fclose(fp); fp = NULL; http_error(HTTP400, "Name Exist."); return 7; } + flock(fileno(fp), LOCK_UN); fclose(fp); fp = NULL; fp = fopen(datfile, "ab+"); if (!fp) { @@ -246,9 +249,10 @@ int main(int argc, char **argv) { return -7; } add_user(name, 0, fp); + flock(fileno(fp), LOCK_UN); fclose(fp); fp = NULL; char* msg = "
Success.\r\n"; - if(headers(strlen(msg), text/html)) { + if(headers(strlen(msg), "text/html")) { write(1, "\0\0\0\0", 4); return 8; } @@ -256,5 +260,8 @@ int main(int argc, char **argv) { } static void __attribute__((destructor)) defer_close_fp() { - if(fp) fclose(fp); + if(fp) { + flock(fileno(fp), LOCK_UN); + fclose(fp); + } } diff --git a/cmoe.h b/cmoe.h index 78983aa..c45a404 100644 --- a/cmoe.h +++ b/cmoe.h @@ -21,7 +21,7 @@ const uint8_t typel[] = {59, 111, 69}; enum errcode_enum_t {HTTP400, HTTP404, HTTP500}; typedef enum errcode_enum_t errcode_enum_t; -#define CONTENT_TYPE(x) "Content-Type: " #x "\r\n" +#define CONTENT_TYPE(x) "Content-Type: " x "\r\n" #define CONTENT_LEN "Content-Length: %d\r\n" #define CACHE_CTRL "Cache-Control: max-age=0, no-cache, no-store, must-revalidate\r\n"