[systemd-commits] 2 commits - man/journalctl.xml src/journal src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Fri Sep 21 13:50:57 PDT 2012


 man/journalctl.xml       |   13 ++++++++-----
 src/journal/journalctl.c |   22 +++++++++++++---------
 src/journal/journald.c   |   24 ++++++++++++++++++------
 src/systemd/sd-id128.h   |    2 ++
 4 files changed, 41 insertions(+), 20 deletions(-)

New commits:
commit c2893c4b346b3fe33a3f983a83818e91affa9631
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 21 22:50:26 2012 +0200

    journald: log how big the journal files may grow

diff --git a/src/journal/journald.c b/src/journal/journald.c
index 164e108..3267fff 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -714,9 +714,11 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
         char_array_0(buffer);
         IOVEC_SET_STRING(iovec[n++], buffer);
 
-        snprintf(mid, sizeof(mid), "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(message_id));
-        char_array_0(mid);
-        IOVEC_SET_STRING(iovec[n++], mid);
+        if (!sd_id128_equal(message_id, SD_ID128_NULL)) {
+                snprintf(mid, sizeof(mid), "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(message_id));
+                char_array_0(mid);
+                IOVEC_SET_STRING(iovec[n++], mid);
+        }
 
         zero(ucred);
         ucred.pid = getpid();
@@ -827,9 +829,14 @@ static int system_journal_open(Server *s) {
                 r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, s->seal, &s->system_metrics, s->mmap, NULL, &s->system_journal);
                 free(fn);
 
-                if (r >= 0)
+                if (r >= 0) {
+                        char fb[FORMAT_BYTES_MAX];
+
                         server_fix_perms(s, s->system_journal, 0);
-                else if (r < 0) {
+                        server_driver_message(s, SD_ID128_NULL, "Allowing system journal files to grow to %s.",
+                                              format_bytes(fb, sizeof(fb), s->system_metrics.max_use));
+
+                } else if (r < 0) {
 
                         if (r != -ENOENT && r != -EROFS)
                                 log_warning("Failed to open system journal: %s", strerror(-r));
@@ -876,8 +883,13 @@ static int system_journal_open(Server *s) {
                         }
                 }
 
-                if (s->runtime_journal)
+                if (s->runtime_journal) {
+                        char fb[FORMAT_BYTES_MAX];
+
                         server_fix_perms(s, s->runtime_journal, 0);
+                        server_driver_message(s, SD_ID128_NULL, "Allowing runtime journal files to grow to %s.",
+                                              format_bytes(fb, sizeof(fb), s->runtime_metrics.max_use));
+                }
         }
 
         return r;
diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 126d83c..05521ae 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -64,6 +64,8 @@ static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
         return memcmp(&a, &b, 16) == 0;
 }
 
+#define SD_ID128_NULL ((sd_id128_t) { .qwords = { 0, 0 }})
+
 #ifdef __cplusplus
 }
 #endif

commit 1705594f597ed12f38bee309b3fdb3f691e2021b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 21 22:33:02 2012 +0200

    journalctl: make the argument to -n optional

diff --git a/man/journalctl.xml b/man/journalctl.xml
index 83ddf5c..50c915d 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -161,11 +161,14 @@
 
                                 <listitem><para>Controls the number of
                                 journal lines to show, counting from
-                                the most recent ones. Takes a positive
-                                integer argument. In follow mode
-                                defaults to 10, otherwise is unset
-                                thus not limiting how many lines are
-                                shown.</para></listitem>
+                                the most recent ones. The argument is
+                                optional, and if specified is a
+                                positive integer. If not specified and
+                                in follow mode defaults to 10. If this
+                                option is not passed and follow mode
+                                is not enabled, how many lines are
+                                shown is not
+                                limited.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 8e52dd5..6b580d4 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -87,7 +87,7 @@ static int help(void) {
                "     --no-pager          Do not pipe output into a pager\n"
                "  -a --all               Show all fields, including long and unprintable\n"
                "  -f --follow            Follow journal\n"
-               "  -n --lines=INTEGER     Journal entries to show\n"
+               "  -n --lines[=INTEGER]   Number of journal entries to show\n"
                "     --no-tail           Show all lines, even in follow mode\n"
                "  -o --output=STRING     Change journal output mode (short, short-monotonic,\n"
                "                         verbose, export, json, json-pretty, cat)\n"
@@ -133,7 +133,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "follow",       no_argument,       NULL, 'f'              },
                 { "output",       required_argument, NULL, 'o'              },
                 { "all",          no_argument,       NULL, 'a'              },
-                { "lines",        required_argument, NULL, 'n'              },
+                { "lines",        optional_argument, NULL, 'n'              },
                 { "no-tail",      no_argument,       NULL, ARG_NO_TAIL      },
                 { "new-id128",    no_argument,       NULL, ARG_NEW_ID128    },
                 { "quiet",        no_argument,       NULL, 'q'              },
@@ -155,7 +155,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hfo:an:qmbD:p:", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:", options, NULL)) >= 0) {
 
                 switch (c) {
 
@@ -178,7 +178,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'o':
-                        arg_output =  output_mode_from_string(optarg);
+                        arg_output = output_mode_from_string(optarg);
                         if (arg_output < 0) {
                                 log_error("Unknown output '%s'.", optarg);
                                 return -EINVAL;
@@ -191,11 +191,15 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'n':
-                        r = safe_atoi(optarg, &arg_lines);
-                        if (r < 0 || arg_lines < 0) {
-                                log_error("Failed to parse lines '%s'", optarg);
-                                return -EINVAL;
-                        }
+                        if (optarg) {
+                                r = safe_atoi(optarg, &arg_lines);
+                                if (r < 0 || arg_lines < 0) {
+                                        log_error("Failed to parse lines '%s'", optarg);
+                                        return -EINVAL;
+                                }
+                        } else
+                                arg_lines = 10;
+
                         break;
 
                 case ARG_NO_TAIL:



More information about the systemd-commits mailing list