[systemd-commits] 4 commits - src/journal src/shared src/sysusers
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Jun 23 07:28:48 PDT 2014
src/journal/coredump.c | 18 ++++++++++++++++--
src/journal/coredumpctl.c | 39 ++++++++++++++++++++++++++++++---------
src/shared/copy.c | 25 +++++++++++++++++++++----
src/shared/copy.h | 2 +-
src/sysusers/sysusers.c | 2 +-
5 files changed, 69 insertions(+), 17 deletions(-)
New commits:
commit 93240d3aba4611dd966c5b9f7368d20612211486
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Jun 23 16:28:05 2014 +0200
coredump: never write more than the configured processing size limit to disk
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 764c5e7..1b35eb1 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -240,8 +240,14 @@ static int save_external_coredump(char **argv, uid_t uid, char **ret_filename, i
return -errno;
}
- r = copy_bytes(STDIN_FILENO, fd);
- if (r < 0) {
+ r = copy_bytes(STDIN_FILENO, fd, arg_process_size_max);
+ if (r == -E2BIG) {
+ log_error("Coredump of %s (%s) is larger than configured processing limit, refusing.", argv[ARG_PID], argv[ARG_COMM]);
+ goto fail;
+ } else if (IN_SET(r, -EDQUOT, -ENOSPC)) {
+ log_error("Not enough disk space for coredump of %s (%s), refusing.", argv[ARG_PID], argv[ARG_COMM]);
+ goto fail;
+ } else if (r < 0) {
log_error("Failed to dump coredump to file: %s", strerror(-r));
goto fail;
}
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index fefd02b..48e6341 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -659,7 +659,7 @@ static int dump_core(sd_journal* j) {
return -errno;
}
- r = copy_bytes(fd, output ? fileno(output) : STDOUT_FILENO);
+ r = copy_bytes(fd, output ? fileno(output) : STDOUT_FILENO, (off_t) -1);
if (r < 0) {
log_error("Failed to stream coredump: %s", strerror(-r));
return r;
diff --git a/src/shared/copy.c b/src/shared/copy.c
index 7c3fab6..ebd6699 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -22,15 +22,27 @@
#include "util.h"
#include "copy.h"
-int copy_bytes(int fdf, int fdt) {
+int copy_bytes(int fdf, int fdt, off_t max_bytes) {
assert(fdf >= 0);
assert(fdt >= 0);
for (;;) {
char buf[PIPE_BUF];
ssize_t n, k;
+ size_t m;
- n = read(fdf, buf, sizeof(buf));
+ m = sizeof(buf);
+
+ if (max_bytes != (off_t) -1) {
+
+ if (max_bytes <= 0)
+ return -E2BIG;
+
+ if ((off_t) m > max_bytes)
+ m = (size_t) max_bytes;
+ }
+
+ n = read(fdf, buf, m);
if (n < 0)
return -errno;
if (n == 0)
@@ -42,6 +54,11 @@ int copy_bytes(int fdf, int fdt) {
return k;
if (k != n)
return errno ? -errno : -EIO;
+
+ if (max_bytes != (off_t) -1) {
+ assert(max_bytes >= n);
+ max_bytes -= n;
+ }
}
return 0;
@@ -84,7 +101,7 @@ static int fd_copy_regular(int df, const char *from, const struct stat *st, int
if (fdt < 0)
return -errno;
- r = copy_bytes(fdf, fdt);
+ r = copy_bytes(fdf, fdt, (off_t) -1);
if (r < 0) {
unlinkat(dt, to, 0);
return r;
@@ -262,7 +279,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) {
if (fdt < 0)
return -errno;
- r = copy_bytes(fdf, fdt);
+ r = copy_bytes(fdf, fdt, (off_t) -1);
if (r < 0) {
unlink(to);
return r;
diff --git a/src/shared/copy.h b/src/shared/copy.h
index 1d5e0ad..0bf2598 100644
--- a/src/shared/copy.h
+++ b/src/shared/copy.h
@@ -23,4 +23,4 @@
int copy_file(const char *from, const char *to, int flags, mode_t mode);
int copy_tree(const char *from, const char *to, bool merge);
-int copy_bytes(int fdf, int fdt);
+int copy_bytes(int fdf, int fdt, off_t max_bytes);
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
index d549969..c192add 100644
--- a/src/sysusers/sysusers.c
+++ b/src/sysusers/sysusers.c
@@ -211,7 +211,7 @@ static int make_backup(const char *x) {
if (dst < 0)
return dst;
- r = copy_bytes(src, dst);
+ r = copy_bytes(src, dst, (off_t) -1);
if (r < 0)
goto fail;
commit 81cef14fce9c64afed600614403ecae7cd79781d
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Jun 23 15:55:24 2014 +0200
coredumpctl: show comm name next to PID
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 56b7bec..fefd02b 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -441,9 +441,14 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
if (need_space)
fputs("\n", file);
- fprintf(file,
- " PID: %s%s%s\n",
- ansi_highlight(), strna(pid), ansi_highlight_off());
+ if (comm)
+ fprintf(file,
+ " PID: %s%s%s (%s)\n",
+ ansi_highlight(), strna(pid), ansi_highlight_off(), comm);
+ else
+ fprintf(file,
+ " PID: %s%s%s\n",
+ ansi_highlight(), strna(pid), ansi_highlight_off());
if (uid) {
uid_t n;
@@ -504,12 +509,10 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
fprintf(file, " Timestamp: %s\n", timestamp);
}
- if (exe)
- fprintf(file, " Executable: %s%s%s\n", ansi_highlight(), exe, ansi_highlight_off());
- if (comm)
- fprintf(file, " Comm: %s\n", comm);
if (cmdline)
fprintf(file, " Command Line: %s\n", cmdline);
+ if (exe)
+ fprintf(file, " Executable: %s%s%s\n", ansi_highlight(), exe, ansi_highlight_off());
if (cgroup)
fprintf(file, " Control Group: %s\n", cgroup);
if (unit)
commit 6388c31525eff90aadddad448217fa92232890ca
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Jun 23 15:53:03 2014 +0200
coredump: quit early if we cannot store ay coredump to disk
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 287e0ed..764c5e7 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -39,6 +39,7 @@
#include "conf-parser.h"
#include "copy.h"
#include "stacktrace.h"
+#include "path-util.h"
#ifdef HAVE_ACL
#include <sys/acl.h>
@@ -375,6 +376,13 @@ int main(int argc, char* argv[]) {
parse_config();
log_debug("Selected storage '%s'.", coredump_storage_to_string(arg_storage));
+ /* Exit early if we cannot write the coredump to disk anyway */
+ if (path_is_read_only_fs("/var/lib") != 0) {
+ log_error("Coredump directory not mounted or not writable, skipping coredump.");
+ r = -EROFS;
+ goto finish;
+ }
+
r = parse_uid(argv[ARG_UID], &uid);
if (r < 0) {
log_error("Failed to parse UID.");
commit 4b8cbe9a71380a912b799de5f12f06a9d838b289
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Jun 23 15:51:09 2014 +0200
coredumpctl: include timestamp information in "coredumpctl info" output
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 4f50f1b..56b7bec 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -409,9 +409,10 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
*unit = NULL, *user_unit = NULL, *session = NULL,
*boot_id = NULL, *machine_id = NULL, *hostname = NULL,
*coredump = NULL, *slice = NULL, *cgroup = NULL,
- *owner_uid = NULL, *message = NULL;
+ *owner_uid = NULL, *message = NULL, *timestamp = NULL;
const void *d;
size_t l;
+ int r;
assert(file);
assert(j);
@@ -430,6 +431,7 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
retrieve(d, l, "COREDUMP_OWNER_UID", &owner_uid);
retrieve(d, l, "COREDUMP_SLICE", &slice);
retrieve(d, l, "COREDUMP_CGROUP", &cgroup);
+ retrieve(d, l, "COREDUMP_TIMESTAMP", ×tamp);
retrieve(d, l, "_BOOT_ID", &boot_id);
retrieve(d, l, "_MACHINE_ID", &machine_id);
retrieve(d, l, "_HOSTNAME", &hostname);
@@ -486,6 +488,22 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
fprintf(file, " Signal: %s\n", sgnl);
}
+ if (timestamp) {
+ usec_t u;
+
+ r = safe_atou64(timestamp, &u);
+ if (r >= 0) {
+ char absolute[FORMAT_TIMESTAMP_MAX], relative[FORMAT_TIMESPAN_MAX];
+
+ fprintf(file,
+ " Timestamp: %s (%s)\n",
+ format_timestamp(absolute, sizeof(absolute), u),
+ format_timestamp_relative(relative, sizeof(relative), u));
+
+ } else
+ fprintf(file, " Timestamp: %s\n", timestamp);
+ }
+
if (exe)
fprintf(file, " Executable: %s%s%s\n", ansi_highlight(), exe, ansi_highlight_off());
if (comm)
More information about the systemd-commits
mailing list