From ab8b57ff54a160bf61a0bcfa008c956804e651c4 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 3 Feb 2019 20:46:23 +0000 Subject: [PATCH] Allow broker to always restart on Windows when using `log_dest file`. Closes #1080. Thanks to lcouz. --- ChangeLog.txt | 2 ++ lib/util_mosq.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f17e68a0..e72b9211 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -30,6 +30,8 @@ Broker: - Handle mismatched handshakes (e.g. QoS1 PUBLISH with QoS2 reply) properly. - Fix spaces not being allowed in the bridge remote_username option. Closes #1131. +- Allow broker to always restart on Windows when using `log_dest file`. Closes + #1080. Library: - Fix TLS connections not working over SOCKS. diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 72666872..350d1ccc 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -404,6 +404,21 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) char username[UNLEN + 1]; int ulen = UNLEN; SECURITY_DESCRIPTOR sd; + DWORD dwCreationDisposition; + + switch(mode[0]){ + case 'a': + dwCreationDisposition = OPEN_ALWAYS; + break; + case 'r': + dwCreationDisposition = OPEN_EXISTING; + break; + case 'w': + dwCreationDisposition = CREATE_ALWAYS; + break; + default: + return NULL; + } GetUserName(username, &ulen); if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) { @@ -424,7 +439,7 @@ FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read) hfile = CreateFile(buf, GENERIC_READ | GENERIC_WRITE, 0, &sec, - CREATE_NEW, + dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);