From 50d16b16ca4724373e02edffdfe08709dae52450 Mon Sep 17 00:00:00 2001 From: quocbao Date: Mon, 20 Feb 2023 14:39:18 +0700 Subject: [PATCH 1/6] Compile in C99 mode src/websocket.c:247:2: error: 'for' loop initial declarations are only allowed in C99 mode for(int i = 0; p < eom && i < cmd->count; i++) { ^ --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29ebef0..35a7d66 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ CFLAGS ?= -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD LDFLAGS ?= -levent -pthread # Pass preprocessor macros to the compile invocation -CFLAGS += $(CPPFLAGS) +CFLAGS += $(CPPFLAGS) -std=gnu99 # check for MessagePack MSGPACK_LIB=$(shell ls /usr/lib/libmsgpack.so 2>/dev/null) From 08f0d5d7cfdf59ecc1e67fdf2dd8a3ad39c35376 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Feb 2023 06:44:48 -0800 Subject: [PATCH 2/6] Change contributed fix from gnu99 to c99 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 35a7d66..312cf5d 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,11 @@ B64_OBJS?=src/b64/cencode.o FORMAT_OBJS?=src/formats/json.o src/formats/raw.o src/formats/common.o src/formats/custom-type.o HTTP_PARSER_OBJS?=src/http-parser/http_parser.o -CFLAGS ?= -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD +CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD LDFLAGS ?= -levent -pthread # Pass preprocessor macros to the compile invocation -CFLAGS += $(CPPFLAGS) -std=gnu99 +CFLAGS += $(CPPFLAGS) # check for MessagePack MSGPACK_LIB=$(shell ls /usr/lib/libmsgpack.so 2>/dev/null) From 7c66f69b21a15d9692951902690a4c732fb6ea14 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Feb 2023 07:04:16 -0800 Subject: [PATCH 3/6] Remove O_NOFOLLOW from src/server.c This was unnecessarily limiting, since users could legitimately want to use a symlink for the config file. It is also unsupported on some platforms; this was discovered when attempting to build Webdis on CentOS 7. --- src/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 03fa3b9..be39792 100644 --- a/src/server.c +++ b/src/server.c @@ -200,7 +200,7 @@ server_daemonize(struct server *s, const char *pidfile) { /* write pidfile */ if(pidfile) { - int pid_fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600); + int pid_fd = open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, 0600); if(pid_fd > 0) { char pid_buffer[(CHAR_BIT * sizeof(int) / 3) + 3]; /* max length for int */ int pid_sz = snprintf(pid_buffer, sizeof(pid_buffer), "%d\n", (int)getpid()); From 05f168fc512625e17e5925e174bcaf2bb65c577e Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Feb 2023 06:46:19 -0800 Subject: [PATCH 4/6] Define _POSIX_C_SOURCE=200809L This is needed to enable localtime_r(3) used in src/slog.c Also needed for strdup(3) Add #ifndef to src/hiredis/fmacros.h to avoid warnings --- Makefile | 2 +- src/hiredis/fmacros.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 312cf5d..bfa0bed 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ B64_OBJS?=src/b64/cencode.o FORMAT_OBJS?=src/formats/json.o src/formats/raw.o src/formats/common.o src/formats/custom-type.o HTTP_PARSER_OBJS?=src/http-parser/http_parser.o -CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD +CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD -D_POSIX_C_SOURCE=200809L LDFLAGS ?= -levent -pthread # Pass preprocessor macros to the compile invocation diff --git a/src/hiredis/fmacros.h b/src/hiredis/fmacros.h index 3227faa..6da4238 100644 --- a/src/hiredis/fmacros.h +++ b/src/hiredis/fmacros.h @@ -2,7 +2,9 @@ #define __HIREDIS_FMACRO_H #define _XOPEN_SOURCE 600 +#ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L +#endif #if defined(__APPLE__) && defined(__MACH__) /* Enable TCP_KEEPALIVE */ From 27359502071241363fe37f2e96a3c1717921c93a Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Feb 2023 07:19:17 -0800 Subject: [PATCH 5/6] Disable pragma warning on old versions of GCC Found with GCC 4.8.5 (released June 2015) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bfa0bed..64a0482 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ B64_OBJS?=src/b64/cencode.o FORMAT_OBJS?=src/formats/json.o src/formats/raw.o src/formats/common.o src/formats/custom-type.o HTTP_PARSER_OBJS?=src/http-parser/http_parser.o -CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD -D_POSIX_C_SOURCE=200809L +CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD -D_POSIX_C_SOURCE=200809L -Wno-pragmas LDFLAGS ?= -levent -pthread # Pass preprocessor macros to the compile invocation From 23838381f69ec0c0378b7b4cf7e5c0c578b7e3b6 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Thu, 23 Feb 2023 07:20:06 -0800 Subject: [PATCH 6/6] Add missing includes for strings.h Several string functions were used without an explicit include. This was discovered using an old version of GCC which warned about them; these warnings are not seen with more recent compilers. --- src/acl.c | 1 + src/client.c | 1 + src/cmd.c | 1 + src/conf.c | 1 + src/formats/json.c | 1 + src/formats/msgpack.c | 1 + src/http.c | 1 + 7 files changed, 7 insertions(+) diff --git a/src/acl.c b/src/acl.c index 160e6e5..61d1b5e 100644 --- a/src/acl.c +++ b/src/acl.c @@ -5,6 +5,7 @@ #include "client.h" #include +#include #include #include #include diff --git a/src/client.c b/src/client.c index 353b360..c54fab8 100644 --- a/src/client.c +++ b/src/client.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/src/cmd.c b/src/cmd.c index 937e6ca..a77e079 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/src/conf.c b/src/conf.c index 904356e..2644d89 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/src/formats/json.c b/src/formats/json.c index 0cbcb52..833e7b1 100644 --- a/src/formats/json.c +++ b/src/formats/json.c @@ -5,6 +5,7 @@ #include "client.h" #include +#include #include #include diff --git a/src/formats/msgpack.c b/src/formats/msgpack.c index a3190b7..0a6606e 100644 --- a/src/formats/msgpack.c +++ b/src/formats/msgpack.c @@ -5,6 +5,7 @@ #include "client.h" #include +#include #include #include diff --git a/src/http.c b/src/http.c index 9da29e1..89bd942 100644 --- a/src/http.c +++ b/src/http.c @@ -5,6 +5,7 @@ #include "slog.h" #include +#include #include #include #include