[systemd-commits] 2 commits - configure.ac src/journal

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Thu Apr 25 20:09:40 PDT 2013


 configure.ac           |   30 ++++++++++++++++--------------
 src/journal/coredump.c |   37 ++++++++++++++++++++++++++-----------
 2 files changed, 42 insertions(+), 25 deletions(-)

New commits:
commit 910003d022ed299b50ab36228732bb74a23d46ba
Author: Colin Walters <walters at verbum.org>
Date:   Wed Apr 24 18:19:04 2013 -0400

    coredump: use realloc() loop instead of malloc(768M)
    
    I typically run VMs with 1024MiB allocated; systemd is unable to write
    coredumps in this scenario at all because the default kernel
    configuration will only overcommit 50% of available RAM.
    
    Avoid this failure by using a realloc() loop.
    
    See: http://lists.freedesktop.org/archives/systemd-devel/2013-April/010709.html

diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 2be6d94..fd03e38 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -37,6 +37,8 @@
 #include "special.h"
 #include "cgroup-util.h"
 
+/* Few programs have less than 3MiB resident */
+#define COREDUMP_MIN_START (3*1024*1024)
 /* Make sure to not make this larger than the maximum journal entry
  * size. See ENTRY_SIZE_MAX in journald-native.c. */
 #define COREDUMP_MAX (768*1024*1024)
@@ -103,9 +105,10 @@ int main(int argc, char* argv[]) {
         uid_t uid;
         gid_t gid;
         struct iovec iovec[14];
+        size_t coredump_bufsize, coredump_size;
         _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, *p = NULL;
+                *core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL;
 
         prctl(PR_SET_DUMPABLE, 0);
 
@@ -234,23 +237,35 @@ int main(int argc, char* argv[]) {
                 goto finish;
         }
 
-        p = malloc(9 + COREDUMP_MAX);
-        if (!p) {
+        coredump_bufsize = COREDUMP_MIN_START;
+        coredump_data = malloc(coredump_bufsize);
+        if (!coredump_data) {
                 r = log_oom();
                 goto finish;
         }
 
-        memcpy(p, "COREDUMP=", 9);
+        memcpy(coredump_data, "COREDUMP=", 9);
+        coredump_size = 9;
 
-        n = loop_read(STDIN_FILENO, p + 9, COREDUMP_MAX, false);
-        if (n < 0) {
-                log_error("Failed to read core dump data: %s", strerror(-n));
-                r = (int) n;
-                goto finish;
+        for (;;) {
+                n = loop_read(STDIN_FILENO, coredump_data + coredump_size,
+                              coredump_bufsize - coredump_size, false);
+                if (n < 0) {
+                        log_error("Failed to read core dump data: %s", strerror(-n));
+                        r = (int) n;
+                        goto finish;
+                } else if (n == 0)
+                        break;
+
+                coredump_size += n;
+                if (!GREEDY_REALLOC(coredump_data, coredump_bufsize, coredump_size + 1)) {
+                        r = log_oom();
+                        goto finish;
+                }
         }
 
-        iovec[j].iov_base = p;
-        iovec[j].iov_len = 9 + n;
+        iovec[j].iov_base = coredump_data;
+        iovec[j].iov_len = coredump_size;
         j++;
 
         r = sd_journal_sendv(iovec, j);

commit 45df1f2c9a7fee67b37f64ddd00adad5982844fa
Author: Cristian Rodríguez <crrodriguez at opensuse.org>
Date:   Wed Apr 24 21:51:23 2013 -0300

    build-sys: add --with-debug-shell=PATH
    
    Distributions may have selinux but not sushell or might
    need to set a custom debug shell.
    
    Defaults to /sbin/sushell if selinux is enabled, /bin/sh if not.
    
    [zj: Renamed --with-debugshelltty to --with-debug-tty, and
         added a line in output showing DEBUGSHELL and DEBUGTTY.
         I figure that debug shell is pretty useful, and I hope
         the extra line in configure status will draw attention
         to it.]

diff --git a/configure.ac b/configure.ac
index ce02ff6..285fc44 100644
--- a/configure.ac
+++ b/configure.ac
@@ -275,13 +275,23 @@ if test "x$enable_selinux" != "xno"; then
         fi
 fi
 AM_CONDITIONAL(HAVE_SELINUX, [test "$have_selinux" = "yes"])
-if test "x${have_selinux}" != xno ; then
-        SUSHELL=/sbin/sushell
-else
-        SUSHELL=/bin/sh
-fi
+
+AC_ARG_WITH(debug-shell,
+        AS_HELP_STRING([--with-debug-shell=PATH],
+                [Path to debug shell binary]),
+        [SUSHELL="$withval"],[
+        AS_IF([test "x${have_selinux}" != "xno"], [SUSHELL="/sbin/sushell"] , [SUSHELL="/bin/sh"])])
+
 AC_SUBST(SUSHELL)
 
+AC_ARG_WITH([debug-tty],
+        AS_HELP_STRING([--with-debug-tty=PATH],
+                [Specify the tty device for debug shell]),
+        [DEBUGTTY="$withval"],
+        [DEBUGTTY=/dev/tty9])
+
+AC_SUBST(DEBUGTTY)
+
 # ------------------------------------------------------------------------------
 have_xz=no
 AC_ARG_ENABLE(xz, AS_HELP_STRING([--disable-xz], [Disable optional XZ support]))
@@ -758,15 +768,6 @@ AS_IF([test "x$enable_keymap" = "xyes"], [
 AM_CONDITIONAL([ENABLE_KEYMAP], [test "x$enable_keymap" = "xyes"])
 
 # ------------------------------------------------------------------------------
-DEBUGTTY=/dev/tty9
-AC_ARG_WITH([debugshelltty],
-        [AS_HELP_STRING([--with-debugshelltty=PATH],
-                [Specify the tty device for debug shell])],
-        [DEBUGTTY="$withval"],
-        [])
-AC_SUBST(DEBUGTTY)
-
-# ------------------------------------------------------------------------------
 have_manpages=no
 AC_ARG_ENABLE(manpages, AS_HELP_STRING([--disable-manpages], [disable manpages]))
 AS_IF([test "x$enable_manpages" != xno], [
@@ -967,6 +968,7 @@ AC_MSG_RESULT([
         Bash completions dir:    ${with_bashcompletiondir}
         Extra start script:      ${RC_LOCAL_SCRIPT_PATH_START}
         Extra stop script:       ${RC_LOCAL_SCRIPT_PATH_STOP}
+        Debug shell:             ${SUSHELL} @ ${DEBUGTTY}
 
         CFLAGS:                  ${OUR_CFLAGS} ${CFLAGS}
         CPPFLAGS:                ${OUR_CPPFLAGS} ${CPPFLAGS}



More information about the systemd-commits mailing list