if (DEBUG_GTE(EXIT, 2)) {
rprintf(FINFO,
"[%s] _exit_cleanup(code=%d, file=%s, line=%d): entered\n",
- who_am_i(), code, file, line);
+ who_am_i(), code, src_file(file), line);
}
#include "case_N.h"
static int flist_count_offset; /* for --delete --progress */
static int show_filelist_progress;
+static struct file_list *flist_new(int flags, const char *msg);
static void flist_sort_and_clean(struct file_list *flist, int strip_root);
static void output_flist(struct file_list *flist);
}
/* Allocate a new file list. */
-struct file_list *flist_new(int flags, char *msg)
+static struct file_list *flist_new(int flags, const char *msg)
{
struct file_list *flist;
flist = new0(struct file_list);
if (flags & FLIST_TEMP) {
- if (!(flist->file_pool = pool_create(SMALL_EXTENT, 0,
- out_of_memory,
- POOL_INTERN)))
+ if (!(flist->file_pool = pool_create(SMALL_EXTENT, 0, _out_of_memory, POOL_INTERN)))
out_of_memory(msg);
} else {
/* This is a doubly linked list with prev looping back to
* the end of the list, but the last next pointer is NULL. */
if (!first_flist) {
- flist->file_pool = pool_create(NORMAL_EXTENT, 0,
- out_of_memory,
- POOL_INTERN);
- if (!flist->file_pool)
+ if (!(flist->file_pool = pool_create(NORMAL_EXTENT, 0, _out_of_memory, POOL_INTERN)))
out_of_memory(msg);
flist->ndx_start = flist->flist_num = inc_recurse ? 1 : 0;
.SH SYNOPSIS
.B #include "pool_alloc.h"
-\fBstruct alloc_pool *pool_create(size_t \fIsize\fB, size_t \fIquantum\fB, void (*\fIbomb\fB)(char *), int \fIflags\fB);
+\fBstruct alloc_pool *pool_create(size_t \fIsize\fB, size_t \fIquantum\fB, void (*\fIbomb\fB)(char*,char*,int), int \fIflags\fB);
\fBvoid pool_destroy(struct alloc_pool *\fIpool\fB);
#define PTR_ADD(b,o) ( (void*) ((char*)(b) + (o)) )
alloc_pool_t
-pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags)
+pool_create(size_t size, size_t quantum, void (*bomb)(const char*, const char*, int), int flags)
{
struct alloc_pool *pool;
if ((MINALIGN & (MINALIGN - 1)) != 0) {
if (bomb)
- (*bomb)("Compiler error: MINALIGN is not a power of 2\n");
+ (*bomb)("Compiler error: MINALIGN is not a power of 2", __FILE__, __LINE__);
return NULL;
}
bomb_out:
if (pool->bomb)
- (*pool->bomb)(bomb_msg);
+ (*pool->bomb)(bomb_msg, __FILE__, __LINE__);
return NULL;
}
typedef void *alloc_pool_t;
-alloc_pool_t pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags);
+alloc_pool_t pool_create(size_t size, size_t quantum, void (*bomb)(const char*, const char*, int), int flags);
void pool_destroy(alloc_pool_t pool);
void *pool_alloc(alloc_pool_t pool, size_t size, const char *bomb_msg);
void pool_free(alloc_pool_t pool, size_t size, void *addr);
/* VANISHED is not an error, only a warning */
if (code == RERR_VANISHED) {
rprintf(FWARNING, "rsync warning: %s (code %d) at %s(%d) [%s=%s]\n",
- name, code, file, line, who_am_i(), RSYNC_VERSION);
+ name, code, src_file(file), line, who_am_i(), RSYNC_VERSION);
} else {
rprintf(FERROR, "rsync error: %s (code %d) at %s(%d) [%s=%s]\n",
- name, code, file, line, who_am_i(), RSYNC_VERSION);
+ name, code, src_file(file), line, who_am_i(), RSYNC_VERSION);
}
}
}
#undef strdup
#define strdup(s) my_strdup(s, __FILE__, __LINE__)
+#define out_of_memory(msg) _out_of_memory(msg, __FILE__, __LINE__)
+#define overflow_exit(msg) _overflow_exit(msg, __FILE__, __LINE__)
+
/* use magic gcc attributes to catch format errors */
void rprintf(enum logcode , const char *, ...)
__attribute__((format (printf, 2, 3)))
if (!file)
return NULL;
rprintf(FERROR, "[%s] exceeded --max-alloc=%s setting (file=%s, line=%d)\n",
- who_am_i(), do_big_num(max_alloc, 0, NULL), file, line);
+ who_am_i(), do_big_num(max_alloc, 0, NULL), src_file(file), line);
exit_cleanup(RERR_MALLOC);
}
if (!ptr)
ptr = malloc(num * size);
else
ptr = realloc(ptr, num * size);
- if (!ptr && file) {
- rprintf(FERROR, "[%s] out of memory (file=%s, line=%d)\n", who_am_i(), file, line);
- exit_cleanup(RERR_MALLOC);
- }
+ if (!ptr && file)
+ _out_of_memory("my_alloc caller", file, line);
return ptr;
}
return buf;
}
-NORETURN void out_of_memory(const char *str)
+NORETURN void _out_of_memory(const char *msg, const char *file, int line)
{
- rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
+ rprintf(FERROR, "[%s] out of memory: %s (file=%s, line=%d)\n", who_am_i(), msg, src_file(file), line);
exit_cleanup(RERR_MALLOC);
}
-NORETURN void overflow_exit(const char *str)
+NORETURN void _overflow_exit(const char *msg, const char *file, int line)
{
- rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
+ rprintf(FERROR, "[%s] buffer overflow: %s (file=%s, line=%d)\n", who_am_i(), msg, src_file(file), line);
exit_cleanup(RERR_MALLOC);
}
+
+const char *src_file(const char *file)
+{
+ static const char *util2 = __FILE__;
+ static int prefix = -1;
+
+ if (prefix < 0) {
+ const char *cp;
+ for (cp = util2, prefix = 0; *cp; cp++) {
+ if (*cp == '/')
+ prefix = cp - util2 + 1;
+ }
+ }
+
+ if (prefix && strncmp(file, util2, prefix) == 0)
+ return file + prefix;
+ return file;
+}