2014-05-07 22:27:00 +00:00
|
|
|
/*
|
2018-04-11 14:24:29 +00:00
|
|
|
Copyright (c) 2010-2018 Roger Light <roger@atchoo.org>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
|
|
|
|
|
|
|
The Eclipse Public License is available at
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
|
|
|
|
|
|
|
Contributors:
|
|
|
|
Roger Light - initial implementation and documentation.
|
|
|
|
*/
|
|
|
|
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "config.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
#ifdef WITH_PERSISTENCE
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2014-09-14 17:08:09 +00:00
|
|
|
#include <time.h>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2016-07-08 09:10:04 +00:00
|
|
|
#include "mosquitto_broker_internal.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "memory_mosq.h"
|
|
|
|
#include "persist.h"
|
|
|
|
#include "time_mosq.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
#include "util_mosq.h"
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
static int persist__client_messages_save(struct mosquitto_db *db, FILE *db_fptr, struct mosquitto *context, struct mosquitto_client_msg *queue)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2019-03-19 16:26:29 +00:00
|
|
|
struct P_client_msg chunk;
|
2014-05-07 22:27:00 +00:00
|
|
|
struct mosquitto_client_msg *cmsg;
|
2019-03-19 16:26:29 +00:00
|
|
|
int rc;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
assert(db);
|
|
|
|
assert(db_fptr);
|
|
|
|
assert(context);
|
|
|
|
|
2016-04-18 15:48:11 +00:00
|
|
|
cmsg = queue;
|
2014-05-07 22:27:00 +00:00
|
|
|
while(cmsg){
|
2017-04-13 12:40:12 +00:00
|
|
|
if(!strncmp(cmsg->store->topic, "$SYS", 4)
|
|
|
|
&& cmsg->store->ref_count <= 1
|
|
|
|
&& cmsg->store->dest_id_count == 0){
|
|
|
|
|
|
|
|
/* This $SYS message won't have been persisted, so we can't persist
|
|
|
|
* this client message. */
|
|
|
|
cmsg = cmsg->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.store_id = cmsg->store->db_id;
|
|
|
|
chunk.F.mid = cmsg->mid;
|
|
|
|
chunk.F.id_len = strlen(context->id);
|
|
|
|
chunk.F.qos = cmsg->qos;
|
|
|
|
chunk.F.retain = cmsg->retain;
|
|
|
|
chunk.F.direction = cmsg->direction;
|
|
|
|
chunk.F.state = cmsg->state;
|
|
|
|
chunk.F.dup = cmsg->dup;
|
|
|
|
chunk.client_id = context->id;
|
|
|
|
|
|
|
|
rc = persist__client_msg_chunk_write_v4(db_fptr, &chunk);
|
|
|
|
if(rc){
|
|
|
|
return rc;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
cmsg = cmsg->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
static int persist__message_store_save(struct mosquitto_db *db, FILE *db_fptr)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2019-03-19 16:26:29 +00:00
|
|
|
struct P_msg_store chunk;
|
2014-11-18 19:12:08 +00:00
|
|
|
struct mosquitto_msg_store *stored;
|
2019-03-19 16:26:29 +00:00
|
|
|
int rc;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
assert(db);
|
|
|
|
assert(db_fptr);
|
|
|
|
|
2014-11-18 19:12:08 +00:00
|
|
|
stored = db->msg_store;
|
|
|
|
while(stored){
|
2019-03-16 09:57:48 +00:00
|
|
|
if(stored->ref_count < 1){
|
|
|
|
stored = stored->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-31 21:17:27 +00:00
|
|
|
if(stored->topic && !strncmp(stored->topic, "$SYS", 4)){
|
2016-06-21 16:17:23 +00:00
|
|
|
if(stored->ref_count <= 1 && stored->dest_id_count == 0){
|
2016-05-14 20:57:09 +00:00
|
|
|
/* $SYS messages that are only retained shouldn't be persisted. */
|
|
|
|
stored = stored->next;
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
/* Don't save $SYS messages as retained otherwise they can give
|
|
|
|
* misleading information when reloaded. They should still be saved
|
|
|
|
* because a disconnected durable client may have them in their
|
|
|
|
* queue. */
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.retain = 0;
|
2019-03-19 17:02:51 +00:00
|
|
|
}else{
|
|
|
|
chunk.F.retain = (uint8_t)stored->retain;
|
2016-05-31 21:17:27 +00:00
|
|
|
}
|
2019-01-31 21:50:42 +00:00
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.store_id = stored->db_id;
|
|
|
|
chunk.F.payloadlen = stored->payloadlen;
|
|
|
|
chunk.F.mid = stored->mid;
|
|
|
|
chunk.F.source_mid = stored->source_mid;
|
2019-01-31 21:50:42 +00:00
|
|
|
if(stored->source_id){
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.source_id_len = strlen(stored->source_id);
|
|
|
|
chunk.source.id = stored->source_id;
|
|
|
|
}else{
|
|
|
|
chunk.F.source_id_len = 0;
|
|
|
|
chunk.source.id = NULL;
|
2019-01-31 21:50:42 +00:00
|
|
|
}
|
|
|
|
if(stored->source_username){
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.source_username_len = strlen(stored->source_username);
|
|
|
|
chunk.source.username = stored->source_username;
|
2019-01-31 21:50:42 +00:00
|
|
|
}else{
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.source_username_len = 0;
|
|
|
|
chunk.source.username = NULL;
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
2019-03-19 16:26:29 +00:00
|
|
|
if(stored->topic){
|
|
|
|
chunk.F.topic_len = strlen(stored->topic);
|
|
|
|
chunk.topic = stored->topic;
|
|
|
|
}else{
|
|
|
|
chunk.F.topic_len = 0;
|
|
|
|
chunk.topic = NULL;
|
2016-05-31 21:17:27 +00:00
|
|
|
}
|
2019-03-19 16:26:29 +00:00
|
|
|
if(stored->source_listener){
|
|
|
|
chunk.F.source_port = stored->source_listener->port;
|
2014-05-07 22:27:00 +00:00
|
|
|
}else{
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.source_port = 0;
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.qos = stored->qos;
|
2019-03-19 17:02:51 +00:00
|
|
|
chunk.payload = stored->payload;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
rc = persist__message_store_chunk_write_v4(db_fptr, &chunk);
|
|
|
|
if(rc){
|
|
|
|
return rc;
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
2014-11-18 19:12:08 +00:00
|
|
|
stored = stored->next;
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
static int persist__client_save(struct mosquitto_db *db, FILE *db_fptr)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2014-06-23 16:57:35 +00:00
|
|
|
struct mosquitto *context, *ctxt_tmp;
|
2019-03-19 16:26:29 +00:00
|
|
|
struct P_client chunk;
|
|
|
|
int rc;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
assert(db);
|
|
|
|
assert(db_fptr);
|
|
|
|
|
2014-06-23 16:57:35 +00:00
|
|
|
HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){
|
2018-11-27 10:02:10 +00:00
|
|
|
if(context && context->clean_start == false){
|
2019-03-19 16:26:29 +00:00
|
|
|
chunk.F.id_len = strlen(context->id);
|
|
|
|
chunk.F.last_mid = context->last_mid;
|
|
|
|
chunk.F.disconnect_t = context->disconnect_t;
|
|
|
|
chunk.client_id = context->id;
|
|
|
|
|
|
|
|
rc = persist__client_chunk_write_v4(db_fptr, &chunk);
|
|
|
|
if(rc){
|
|
|
|
return rc;
|
2014-06-13 21:34:04 +00:00
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
if(persist__client_messages_save(db, db_fptr, context, context->inflight_msgs)) return 1;
|
|
|
|
if(persist__client_messages_save(db, db_fptr, context, context->queued_msgs)) return 1;
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-01-31 21:50:42 +00:00
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
static int persist__subs_retain_save(struct mosquitto_db *db, FILE *db_fptr, struct mosquitto__subhier *node, const char *topic, int level)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2016-07-19 14:05:53 +00:00
|
|
|
struct mosquitto__subhier *subhier, *subhier_tmp;
|
2015-04-19 21:10:59 +00:00
|
|
|
struct mosquitto__subleaf *sub;
|
2019-03-19 16:26:29 +00:00
|
|
|
struct P_retain retain_chunk;
|
|
|
|
struct P_sub sub_chunk;
|
2014-05-07 22:27:00 +00:00
|
|
|
char *thistopic;
|
|
|
|
size_t slen;
|
2019-03-19 16:26:29 +00:00
|
|
|
int rc;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2015-04-04 20:15:27 +00:00
|
|
|
slen = strlen(topic) + node->topic_len + 2;
|
2015-04-19 21:10:59 +00:00
|
|
|
thistopic = mosquitto__malloc(sizeof(char)*slen);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(!thistopic) return MOSQ_ERR_NOMEM;
|
2016-05-14 21:39:14 +00:00
|
|
|
if(level > 1 || strlen(topic)){
|
2019-03-08 23:11:21 +00:00
|
|
|
snprintf(thistopic, slen, "%s/%s", topic, node->topic);
|
2014-05-07 22:27:00 +00:00
|
|
|
}else{
|
2019-03-08 23:11:21 +00:00
|
|
|
snprintf(thistopic, slen, "%s", node->topic);
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub = node->subs;
|
|
|
|
while(sub){
|
2018-12-19 14:11:11 +00:00
|
|
|
if(sub->context->clean_start == false && sub->context->id){
|
2019-03-19 16:26:29 +00:00
|
|
|
sub_chunk.F.id_len = strlen(sub->context->id);
|
|
|
|
sub_chunk.F.topic_len = strlen(thistopic);
|
|
|
|
sub_chunk.F.qos = (uint8_t)sub->qos;
|
|
|
|
sub_chunk.client_id = sub->context->id;
|
|
|
|
sub_chunk.topic = thistopic;
|
|
|
|
|
|
|
|
rc = persist__sub_chunk_write_v4(db_fptr, &sub_chunk);
|
|
|
|
if(rc){
|
|
|
|
mosquitto__free(thistopic);
|
|
|
|
return rc;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
sub = sub->next;
|
|
|
|
}
|
|
|
|
if(node->retained){
|
2015-04-11 20:17:16 +00:00
|
|
|
if(strncmp(node->retained->topic, "$SYS", 4)){
|
2014-05-07 22:27:00 +00:00
|
|
|
/* Don't save $SYS messages. */
|
2019-03-19 16:26:29 +00:00
|
|
|
retain_chunk.F.store_id = node->retained->db_id;
|
|
|
|
rc = persist__retain_chunk_write_v4(db_fptr, &retain_chunk);
|
|
|
|
if(rc){
|
|
|
|
mosquitto__free(thistopic);
|
|
|
|
return rc;
|
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 14:05:53 +00:00
|
|
|
HASH_ITER(hh, node->children, subhier, subhier_tmp){
|
2019-03-19 16:26:29 +00:00
|
|
|
persist__subs_retain_save(db, db_fptr, subhier, thistopic, level+1);
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
2015-04-19 21:10:59 +00:00
|
|
|
mosquitto__free(thistopic);
|
2014-05-07 22:27:00 +00:00
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
static int persist__subs_retain_save_all(struct mosquitto_db *db, FILE *db_fptr)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
2016-07-19 14:05:53 +00:00
|
|
|
struct mosquitto__subhier *subhier, *subhier_tmp;
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2016-07-19 14:05:53 +00:00
|
|
|
HASH_ITER(hh, db->subs, subhier, subhier_tmp){
|
2016-05-31 21:17:27 +00:00
|
|
|
if(subhier->children){
|
2019-03-19 16:26:29 +00:00
|
|
|
persist__subs_retain_save(db, db_fptr, subhier->children, "", 0);
|
2016-05-31 21:17:27 +00:00
|
|
|
}
|
2014-05-07 22:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-05-16 14:24:24 +00:00
|
|
|
int persist__backup(struct mosquitto_db *db, bool shutdown)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
FILE *db_fptr = NULL;
|
|
|
|
uint32_t db_version_w = htonl(MOSQ_DB_VERSION);
|
|
|
|
uint32_t crc = htonl(0);
|
|
|
|
dbid_t i64temp;
|
|
|
|
uint32_t i32temp;
|
|
|
|
uint16_t i16temp;
|
|
|
|
uint8_t i8temp;
|
2018-11-07 17:43:21 +00:00
|
|
|
char *err;
|
2014-05-07 22:27:00 +00:00
|
|
|
char *outfile = NULL;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if(!db || !db->config || !db->config->persistence_filepath) return MOSQ_ERR_INVAL;
|
2019-03-19 14:25:40 +00:00
|
|
|
if(db->config->persistence == false) return MOSQ_ERR_SUCCESS;
|
|
|
|
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_INFO, "Saving in-memory database to %s.", db->config->persistence_filepath);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
len = strlen(db->config->persistence_filepath)+5;
|
2015-04-19 21:10:59 +00:00
|
|
|
outfile = mosquitto__malloc(len+1);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(!outfile){
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, out of memory.");
|
2014-05-07 22:27:00 +00:00
|
|
|
return MOSQ_ERR_NOMEM;
|
|
|
|
}
|
|
|
|
snprintf(outfile, len, "%s.new", db->config->persistence_filepath);
|
2015-01-14 21:43:39 +00:00
|
|
|
outfile[len] = '\0';
|
2016-08-16 21:36:58 +00:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* If a system lost power during the rename operation at the
|
|
|
|
* end of this file the filesystem could potentially be left
|
|
|
|
* with a directory that looks like this after powerup:
|
|
|
|
*
|
|
|
|
* 24094 -rw-r--r-- 2 root root 4099 May 30 16:27 mosquitto.db
|
|
|
|
* 24094 -rw-r--r-- 2 root root 4099 May 30 16:27 mosquitto.db.new
|
|
|
|
*
|
|
|
|
* The 24094 shows that mosquitto.db.new is hard-linked to the
|
|
|
|
* same file as mosquitto.db. If fopen(outfile, "wb") is naively
|
|
|
|
* called then mosquitto.db will be truncated and the database
|
|
|
|
* potentially corrupted.
|
|
|
|
*
|
|
|
|
* Any existing mosquitto.db.new file must be removed prior to
|
|
|
|
* opening to guarantee that it is not hard-linked to
|
|
|
|
* mosquitto.db.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
rc = unlink(outfile);
|
|
|
|
if (rc != 0) {
|
2019-03-19 14:25:40 +00:00
|
|
|
rc = 0;
|
2016-08-16 21:36:58 +00:00
|
|
|
if (errno != ENOENT) {
|
2017-03-06 21:19:53 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, unable to remove %s.", outfile);
|
2016-08-16 21:36:58 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-16 21:52:01 +00:00
|
|
|
db_fptr = mosquitto__fopen(outfile, "wb", true);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(db_fptr == NULL){
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_INFO, "Error saving in-memory database, unable to open %s for writing.", outfile);
|
2014-05-07 22:27:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Header */
|
|
|
|
write_e(db_fptr, magic, 15);
|
|
|
|
write_e(db_fptr, &crc, sizeof(uint32_t));
|
|
|
|
write_e(db_fptr, &db_version_w, sizeof(uint32_t));
|
|
|
|
|
|
|
|
/* DB config */
|
|
|
|
i16temp = htons(DB_CHUNK_CFG);
|
|
|
|
write_e(db_fptr, &i16temp, sizeof(uint16_t));
|
|
|
|
/* chunk length */
|
|
|
|
i32temp = htonl(sizeof(dbid_t) + sizeof(uint8_t) + sizeof(uint8_t));
|
|
|
|
write_e(db_fptr, &i32temp, sizeof(uint32_t));
|
|
|
|
/* db written at broker shutdown or not */
|
|
|
|
i8temp = shutdown;
|
|
|
|
write_e(db_fptr, &i8temp, sizeof(uint8_t));
|
|
|
|
i8temp = sizeof(dbid_t);
|
|
|
|
write_e(db_fptr, &i8temp, sizeof(uint8_t));
|
|
|
|
/* last db mid */
|
|
|
|
i64temp = db->last_db_id;
|
|
|
|
write_e(db_fptr, &i64temp, sizeof(dbid_t));
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
if(persist__message_store_save(db, db_fptr)){
|
2014-05-07 22:27:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:26:29 +00:00
|
|
|
persist__client_save(db, db_fptr);
|
|
|
|
persist__subs_retain_save_all(db, db_fptr);
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2016-06-26 21:48:16 +00:00
|
|
|
#ifndef WIN32
|
2016-08-16 21:36:58 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Closing a file does not guarantee that the contents are
|
|
|
|
* written to disk. Need to flush to send data from app to OS
|
|
|
|
* buffers, then fsync to deliver data from OS buffers to disk
|
|
|
|
* (as well as disk hardware permits).
|
|
|
|
*
|
|
|
|
* man close (http://linux.die.net/man/2/close, 2016-06-20):
|
|
|
|
*
|
|
|
|
* "successful close does not guarantee that the data has
|
|
|
|
* been successfully saved to disk, as the kernel defers
|
|
|
|
* writes. It is not common for a filesystem to flush
|
|
|
|
* the buffers when the stream is closed. If you need
|
|
|
|
* to be sure that the data is physically stored, use
|
|
|
|
* fsync(2). (It will depend on the disk hardware at this
|
|
|
|
* point."
|
|
|
|
*
|
|
|
|
* This guarantees that the new state file will not overwrite
|
|
|
|
* the old state file before its contents are valid.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
fflush(db_fptr);
|
2016-06-26 21:48:16 +00:00
|
|
|
fsync(fileno(db_fptr));
|
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
fclose(db_fptr);
|
|
|
|
|
2014-10-08 19:51:17 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
if(remove(db->config->persistence_filepath) != 0){
|
2015-04-17 20:19:45 +00:00
|
|
|
if(errno != ENOENT){
|
|
|
|
goto error;
|
|
|
|
}
|
2014-10-08 19:51:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-05-07 22:27:00 +00:00
|
|
|
if(rename(outfile, db->config->persistence_filepath) != 0){
|
|
|
|
goto error;
|
|
|
|
}
|
2015-04-19 21:10:59 +00:00
|
|
|
mosquitto__free(outfile);
|
2014-05-07 22:27:00 +00:00
|
|
|
outfile = NULL;
|
|
|
|
return rc;
|
|
|
|
error:
|
2015-08-18 13:53:22 +00:00
|
|
|
mosquitto__free(outfile);
|
2018-11-07 17:43:21 +00:00
|
|
|
err = strerror(errno);
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err);
|
2014-05-07 22:27:00 +00:00
|
|
|
if(db_fptr) fclose(db_fptr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|