forked from github/server
Debug: move errno testing closer to the report-writing, so we know which report caused the error.
Fix: wrptr gets the result from _snprintf, which is int, not size_t.
This commit is contained in:
parent
df5eaa6ef2
commit
dcececf4fa
|
@ -1783,6 +1783,7 @@ int write_reports(faction * f, time_t ltime)
|
|||
bool gotit = false;
|
||||
struct report_context ctx;
|
||||
const char *encoding = "UTF-8";
|
||||
report_type *rtype;
|
||||
|
||||
if (noreports) {
|
||||
return false;
|
||||
|
@ -1798,36 +1799,42 @@ int write_reports(faction * f, time_t ltime)
|
|||
get_seen_interval(&ctx);
|
||||
}
|
||||
get_addresses(&ctx);
|
||||
if (_access(reportpath(), 0) < 0) {
|
||||
_mkdir(reportpath());
|
||||
do {
|
||||
report_type *rtype = report_types;
|
||||
|
||||
}
|
||||
if (errno) {
|
||||
log_warning("errno was %d before writing reports", errno);
|
||||
errno = 0;
|
||||
}
|
||||
if (verbosity >= 2) {
|
||||
log_printf(stdout, "Reports for %s:", factionname(f));
|
||||
}
|
||||
for (; rtype != NULL; rtype = rtype->next) {
|
||||
for (rtype = report_types; rtype != NULL; rtype = rtype->next) {
|
||||
if (f->options & rtype->flag) {
|
||||
int error;
|
||||
do {
|
||||
char filename[MAX_PATH];
|
||||
sprintf(filename, "%s/%d-%s.%s", reportpath(), turn, factionid(f),
|
||||
rtype->extension);
|
||||
error = 0;
|
||||
if (rtype->write(filename, &ctx, encoding) == 0) {
|
||||
gotit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errno) {
|
||||
char zText[64];
|
||||
log_warning("retrying, error %d during reports for faction %s", errno, factionname(f));
|
||||
log_warning("retrying, error %d during %s report for faction %s", error, rtype->extension, factionname(f));
|
||||
sprintf(zText, "waiting %u seconds before we retry", backup / 1000);
|
||||
perror(zText);
|
||||
_sleep(backup);
|
||||
if (backup < maxbackup) {
|
||||
backup *= 2;
|
||||
}
|
||||
error = errno;
|
||||
errno = 0;
|
||||
}
|
||||
} while (error);
|
||||
}
|
||||
}
|
||||
} while (errno);
|
||||
if (!gotit) {
|
||||
log_warning("No report for faction %s!", factionid(f));
|
||||
}
|
||||
|
|
|
@ -7,8 +7,18 @@
|
|||
|
||||
#include "bsdstring.h"
|
||||
|
||||
int wrptr(char **ptr, size_t * size, size_t bytes)
|
||||
int wrptr(char **ptr, size_t * size, int result)
|
||||
{
|
||||
size_t bytes = (size_t)result;
|
||||
if (result < 0) {
|
||||
// _snprintf buffer was too small
|
||||
if (*size > 0) {
|
||||
**ptr = 0;
|
||||
*size = 0;
|
||||
}
|
||||
errno = 0;
|
||||
return ERANGE;
|
||||
}
|
||||
if (bytes == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define UTIL_BSDSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
extern int wrptr(char **ptr, size_t * size, size_t bytes);
|
||||
extern int wrptr(char **ptr, size_t * size, int bytes);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
|
@ -16,6 +16,7 @@ extern size_t strlcat(char *dst, const char *src, size_t siz);
|
|||
extern size_t slprintf(char * dst, size_t size, const char * format, ...);
|
||||
#endif
|
||||
|
||||
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __FILE__, __LINE__)
|
||||
#define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
||||
#define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue