Let's just call it a database rather than persistent storage file.

Also, fix a small memory leak if the database was corrupted.
This commit is contained in:
Bram Matthys 2019-08-19 16:38:57 +02:00
parent 86f7d8c5cc
commit 142289c2de
No known key found for this signature in database
GPG key ID: BF8116B163EAAE98
2 changed files with 16 additions and 20 deletions

View file

@ -19,7 +19,7 @@
#define W_SAFE(x) \
do { \
if (!(x)) { \
config_warn("[channeldb] Write error from the persistent storage tempfile '%s': %s (DATABASE NOT SAVED)", tmpfname, strerror(errno)); \
config_warn("[channeldb] Error writing to temporary database file '%s': %s (DATABASE NOT SAVED)", tmpfname, strerror(errno)); \
fclose(fd); \
return 0; \
} \
@ -212,7 +212,7 @@ int write_channeldb(void)
fd = fopen(tmpfname, "wb");
if (!fd)
{
config_warn("[channeldb] Unable to open the persistent storage tempfile '%s' for writing: %s", tmpfname, strerror(errno));
config_warn("[channeldb] Unable to open the temporary database file '%s' for writing: %s. DATABASE NOT SAVED!", tmpfname, strerror(errno));
return 0;
}
@ -237,7 +237,7 @@ int write_channeldb(void)
// Everything seems to have gone well, attempt to close and rename the tempfile
if (fclose(fd) != 0)
{
config_warn("[channeldb] Got an error when trying to close the persistent storage file '%s' (possible corruption occurred, DATABASE NOT SAVED): %s", cfg.database, strerror(errno));
config_warn("[channeldb] Error while writing to temporary database file '%s': %s. DATABASE NOT SAVED CORRECTLY!", cfg.database, strerror(errno));
return 0;
}
@ -305,7 +305,7 @@ int write_channel_entry(FILE *fd, const char *tmpfname, aChannel *chptr)
#define R_SAFE(x) \
do { \
if (!(x)) { \
config_warn("[channeldb] Read error from the persistent storage file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
config_warn("[channeldb] Read error from database file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
if (e) \
{ \
safefree(e->banstr); \
@ -359,7 +359,7 @@ int read_listmode(FILE *fd, Ban **lst)
#define R_SAFE(x) \
do { \
if (!(x)) { \
config_warn("[channeldb] Read error from the persistent storage file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
config_warn("[channeldb] Read error from database file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
fclose(fd); \
FreeChannelEntry(); \
return 0; \
@ -399,7 +399,7 @@ int read_channeldb(void)
config_warn("[channeldb] No database present at '%s', will start a new one", cfg.database);
return 1;
} else {
config_warn("[channeldb] Unable to open the persistent storage file '%s' for reading: %s", cfg.database, strerror(errno));
config_warn("[channeldb] Unable to open the database file '%s' for reading: %s", cfg.database, strerror(errno));
return 0;
}
}
@ -408,8 +408,7 @@ int read_channeldb(void)
if (version > channeldb_version)
{
config_warn("[channeldb] Database '%s' has a wrong version: expected it to be <= %u but got %u instead", cfg.database, channeldb_version, version);
if (fclose(fd) != 0)
config_warn("[channeldb] Got an error when trying to close the persistent storage file '%s' (possible corruption occurred): %s", cfg.database, strerror(errno));
fclose(fd);
return 0;
}
@ -450,12 +449,9 @@ int read_channeldb(void)
chptr->topic_time = topic_time;
chptr->mode_lock = BadPtr(mode_lock) ? NULL : strdup(mode_lock);
set_channel_mode(chptr, modes1, modes2);
if (!read_listmode(fd, &chptr->banlist))
break;
if (!read_listmode(fd, &chptr->exlist))
break;
if (!read_listmode(fd, &chptr->invexlist))
break;
R_SAFE(read_listmode(fd, &chptr->banlist));
R_SAFE(read_listmode(fd, &chptr->exlist));
R_SAFE(read_listmode(fd, &chptr->invexlist));
R_SAFE(read_data(fd, &magic, sizeof(magic)));
FreeChannelEntry();
added++;

View file

@ -51,7 +51,7 @@
#define R_SAFE(x) \
do { \
if (!(x)) { \
config_warn("[tkldb] Read error from the persistent storage file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
config_warn("[tkldb] Read error from database file '%s' (possible corruption): %s", cfg.database, strerror(errno)); \
fclose(fd); \
FreeTKLRead(); \
return 0; \
@ -61,7 +61,7 @@
#define W_SAFE(x) \
do { \
if (!(x)) { \
config_warn("[tkldb] Write error from the persistent storage tempfile '%s': %s (DATABASE NOT SAVED)", tmpfname, strerror(errno)); \
config_warn("[tkldb] Error writing to temporary database file '%s': %s. DATABASE NOT SAVED!", tmpfname, strerror(errno)); \
fclose(fd); \
return 0; \
} \
@ -258,7 +258,7 @@ int write_tkldb(void)
fd = fopen(tmpfname, "wb");
if (!fd)
{
config_warn("[tkldb] Unable to open the persistent storage tempfile '%s' for writing: %s", tmpfname, strerror(errno));
config_warn("[tkldb] Unable to open temporary database file '%s' for writing: %s. DATABASE NOT SAVED!", tmpfname, strerror(errno));
return 0;
}
@ -321,7 +321,7 @@ int write_tkldb(void)
// Everything seems to have gone well, attempt to close and rename the tempfile
if (fclose(fd) != 0)
{
config_warn("[tkldb] Got an error when trying to close the persistent storage file '%s' (possible corruption occurred, DATABASE NOT SAVED): %s", cfg.database, strerror(errno));
config_warn("[tkldb] Got an error when trying to close database file '%s' (possible corruption occurred, DATABASE NOT SAVED): %s", cfg.database, strerror(errno));
return 0;
}
if (rename(tmpfname, cfg.database) < 0)
@ -433,7 +433,7 @@ int read_tkldb(void)
config_warn("[tkldb] No database present at '%s', will start a new one", cfg.database);
return 1;
} else {
config_warn("[tkldb] Unable to open the persistent storage file '%s' for reading: %s", cfg.database, strerror(errno));
config_warn("[tkldb] Unable to open database file '%s' for reading: %s", cfg.database, strerror(errno));
return 0;
}
}
@ -444,7 +444,7 @@ int read_tkldb(void)
// Older DBs should still work with newer versions of this module
config_warn("[tkldb] Database '%s' has a wrong version: expected it to be <= %u but got %u instead", cfg.database, tkl_db_version, version);
if (fclose(fd) != 0)
config_warn("[tkldb] Got an error when trying to close the persistent storage file '%s' (possible corruption occurred): %s", cfg.database, strerror(errno));
config_warn("[tkldb] Got an error when trying to close database file '%s' (possible corruption occurred): %s", cfg.database, strerror(errno));
return 0;
}