From d8ddd3b5bccdffd99ee5bf2ba3ebd09bede3f18c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 15 Jul 2017 09:40:11 +0200 Subject: [PATCH] mingw: work around mingw mkdir mingw doesn't come with a posix compliant mkdir as it only takes a single argument. --- configure.ac | 1 + src/log-filestore.c | 2 +- src/log-pcap.c | 7 ++----- src/log-tcp-data.c | 6 +----- src/log-tlsstore.c | 2 +- src/suricata-common.h | 6 ++++++ src/unix-manager.c | 2 +- src/util-logopenfile.c | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 1b94f7851a..f70275b5bd 100644 --- a/configure.ac +++ b/configure.ac @@ -229,6 +229,7 @@ LDFLAGS="${LDFLAGS} -lws2_32" WINDOWS_PATH="yes" PCAP_LIB_NAME="wpcap" + AC_DEFINE([HAVE_NON_POSIX_MKDIR], [1], [mkdir is not POSIX compliant: single arg]) ;; *-*-cygwin) LUA_PC_NAME="lua" diff --git a/src/log-filestore.c b/src/log-filestore.c index 6b2c0f55e5..f8f84616c8 100644 --- a/src/log-filestore.c +++ b/src/log-filestore.c @@ -507,7 +507,7 @@ static TmEcode LogFilestoreLogThreadInit(ThreadVars *t, const void *initdata, vo struct stat stat_buf; if (stat(g_logfile_base_dir, &stat_buf) != 0) { int ret; - ret = mkdir(g_logfile_base_dir, S_IRWXU|S_IXGRP|S_IRGRP); + ret = SCMkDir(g_logfile_base_dir, S_IRWXU|S_IXGRP|S_IRGRP); if (ret != 0) { int err = errno; if (err != EEXIST) { diff --git a/src/log-pcap.c b/src/log-pcap.c index 869c0ff3fe..0fcf5c7f59 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -1234,11 +1234,8 @@ static int PcapLogOpenFileCtx(PcapLogData *pl) } /* if mkdir fails file open will fail, so deal with errors there */ -#ifndef OS_WIN32 - (void)mkdir(dirfull, 0700); -#else - (void)mkdir(dirfull); -#endif + (void)SCMkDir(dirfull, 0700); + if ((pf->dirname = SCStrdup(dirfull)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for " "directory name"); diff --git a/src/log-tcp-data.c b/src/log-tcp-data.c index 068e738eb0..9be178a8a7 100644 --- a/src/log-tcp-data.c +++ b/src/log-tcp-data.c @@ -295,11 +295,7 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf) SCLogInfo("using directory %s", dirfull); /* if mkdir fails file open will fail, so deal with errors there */ -#ifndef OS_WIN32 - (void)mkdir(dirfull, 0700); -#else - (void)mkdir(dirfull); -#endif + (void)SCMkDir(dirfull, 0700); } OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); diff --git a/src/log-tlsstore.c b/src/log-tlsstore.c index 79f3c881f6..1e6573c93f 100644 --- a/src/log-tlsstore.c +++ b/src/log-tlsstore.c @@ -311,7 +311,7 @@ static TmEcode LogTlsStoreLogThreadInit(ThreadVars *t, const void *initdata, voi if (stat(tls_logfile_base_dir, &stat_buf) != 0) { int ret; /* coverity[toctou] */ - ret = mkdir(tls_logfile_base_dir, S_IRWXU|S_IXGRP|S_IRGRP); + ret = SCMkDir(tls_logfile_base_dir, S_IRWXU|S_IXGRP|S_IRGRP); if (ret != 0) { int err = errno; if (err != EEXIST) { diff --git a/src/suricata-common.h b/src/suricata-common.h index 50a5ade86b..4e73fe5612 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -367,6 +367,12 @@ #define WARN_UNUSED __attribute__((warn_unused_result)) +#ifndef HAVE_NON_POSIX_MKDIR + #define SCMkDir(a, b) mkdir(a, b) +#else + #define SCMkDir(a, b) mkdir(a) +#endif + typedef enum PacketProfileDetectId_ { PROF_DETECT_IPONLY, PROF_DETECT_RULES, diff --git a/src/unix-manager.c b/src/unix-manager.c index e401ec57b7..91b5937886 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -133,7 +133,7 @@ static int UnixNew(UnixCommand * this) /* coverity[toctou] */ if (stat(SOCKET_PATH, &stat_buf) != 0) { /* coverity[toctou] */ - ret = mkdir(SOCKET_PATH, S_IRWXU|S_IXGRP|S_IRGRP); + ret = SCMkDir(SOCKET_PATH, S_IRWXU|S_IXGRP|S_IRGRP); if (ret != 0) { int err = errno; if (err != EEXIST) { diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index d9b1cc4e0a..92540812b5 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -265,7 +265,7 @@ static int SCLogCreateDirectoryTree(const char *filepath) /* Truncate, while creating directory */ *p = '\0'; - if (mkdir(pathbuf, S_IRWXU | S_IRGRP | S_IXGRP) != 0) { + if (SCMkDir(pathbuf, S_IRWXU | S_IRGRP | S_IXGRP) != 0) { if (errno != EEXIST) { return -1; }