diff --git a/ChangeLog.txt b/ChangeLog.txt index f17e68a081..e72b92112b 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 72666872f3..350d1ccc36 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);