summaryrefslogtreecommitdiff
path: root/src/journal/coredump.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-10 09:48:59 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-12 10:20:55 -0400
commitca2d37841476e6272c9957c3f5a0cbe869a531ca (patch)
treeab1dea346bd6342248858be26e9638437141a0d1 /src/journal/coredump.c
parent7cc832b91e8f5883b505c42f9f403e03dfc83c89 (diff)
Unify GREEDY_REALLOC and GREEDY_REALLOC_T
greedy_realloc() and greedy_realloc0() now store the allocated size as the count, not bytes. Replace GREEDY_REALLOC uses with GREEDY_REALLOC_T everywhere, and then rename GREEDY_REALLOC_T to GREEDY_REALLOC. It is just too error-prone to have two slightly different macros which do the same thing.
Diffstat (limited to 'src/journal/coredump.c')
-rw-r--r--src/journal/coredump.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 29342de681..74b1dbd013 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -39,10 +39,10 @@
#include "journald-native.h"
/* Few programs have less than 3MiB resident */
-#define COREDUMP_MIN_START (3*1024*1024)
+#define COREDUMP_MIN_START (3*1024*1024u)
/* Make sure to not make this larger than the maximum journal entry
* size. See ENTRY_SIZE_MAX in journald-native.c. */
-#define COREDUMP_MAX (767*1024*1024)
+#define COREDUMP_MAX (767*1024*1024u)
assert_cc(COREDUMP_MAX <= ENTRY_SIZE_MAX);
enum {
@@ -107,7 +107,7 @@ int main(int argc, char* argv[]) {
uid_t uid;
gid_t gid;
struct iovec iovec[14];
- size_t coredump_bufsize, coredump_size;
+ size_t coredump_bufsize = 0, coredump_size = 0;
_cleanup_free_ char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL,
*core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL,
*core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL;
@@ -239,17 +239,18 @@ int main(int argc, char* argv[]) {
goto finish;
}
- coredump_bufsize = COREDUMP_MIN_START;
- coredump_data = malloc(coredump_bufsize);
- if (!coredump_data) {
- log_warning("Failed to allocate memory for core, core will not be stored.");
- goto finalize;
- }
+ for (;;) {
+ if (!GREEDY_REALLOC(coredump_data, coredump_bufsize,
+ MAX(coredump_size + 1, COREDUMP_MIN_START/2))) {
+ log_warning("Failed to allocate memory for core, core will not be stored.");
+ goto finalize;
+ }
- memcpy(coredump_data, "COREDUMP=", 9);
- coredump_size = 9;
+ if (coredump_size == 0) {
+ memcpy(coredump_data, "COREDUMP=", 9);
+ coredump_size = 9;
+ }
- for (;;) {
n = loop_read(STDIN_FILENO, coredump_data + coredump_size,
coredump_bufsize - coredump_size, false);
if (n < 0) {
@@ -265,11 +266,6 @@ int main(int argc, char* argv[]) {
log_error("Core too large, core will not be stored.");
goto finalize;
}
-
- if (!GREEDY_REALLOC(coredump_data, coredump_bufsize, coredump_size + 1)) {
- log_warning("Failed to allocate memory for core, core will not be stored.");
- goto finalize;
- }
}
iovec[j].iov_base = coredump_data;