[systemd-commits] 5 commits - bash-completion/systemd-bash-completion.sh man/systemd-coredumpctl.xml src/journal
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Tue Oct 30 03:30:05 PDT 2012
bash-completion/systemd-bash-completion.sh | 72 ++++++++++++++++++++----
man/systemd-coredumpctl.xml | 17 +++++
src/journal/coredumpctl.c | 84 ++++++++++++++++++++++-------
3 files changed, 142 insertions(+), 31 deletions(-)
New commits:
commit 26acfdae44e3605788420432d28a7264214d1213
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Oct 30 10:18:17 2012 +0100
bash-completion: add completion for coredumpctl
diff --git a/bash-completion/systemd-bash-completion.sh b/bash-completion/systemd-bash-completion.sh
index 8d23268..5f829b3 100644
--- a/bash-completion/systemd-bash-completion.sh
+++ b/bash-completion/systemd-bash-completion.sh
@@ -280,6 +280,17 @@ _loginctl () {
}
complete -F _loginctl loginctl
+__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
+ ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
+ _{P,U,G}ID _COMM _EXE _CMDLINE
+ _AUDIT_{SESSION,LOGINUID}
+ _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
+ _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
+ _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
+ _KERNEL_{DEVICE,SUBSYSTEM}
+ _UDEV_{SYSNAME,DEVNODE,DEVLINK}
+ __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
+
_journalctl() {
local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local -A OPTS=(
@@ -291,17 +302,6 @@ _journalctl() {
[ARGUNKNOWN]='-c --cursor --interval -n --lines -p --priority --since --until
--verify-key'
)
- local journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
- ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
- _{P,U,G}ID _COMM _EXE _CMDLINE
- _AUDIT_{SESSION,LOGINUID}
- _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
- _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
- _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
- _KERNEL_{DEVICE,SUBSYSTEM}
- _UDEV_{SYSNAME,DEVNODE,DEVLINK}
- __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
-
if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
case $prev in
@@ -313,7 +313,7 @@ _journalctl() {
comps='short short-monotonic verbose export json cat'
;;
--field|-F)
- comps=${journal_fields[*]}
+ comps=${__journal_fields[*]}
;;
--unit|-u)
comps=$(journalctl -F '_SYSTEMD_UNIT')
@@ -337,11 +337,57 @@ _journalctl() {
COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
else
compopt -o nospace
- COMPREPLY=( $(compgen -W '${journal_fields[*]}' -S= -- "$cur") )
+ COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
fi
}
complete -F _journalctl journalctl
+_coredumpctl() {
+ local i verb comps
+ local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
+ local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field'
+
+ local -A VERBS=(
+ [LIST]='list'
+ [DUMP]='dump'
+ )
+
+ if __contains_word "$prev" '--output -o'; then
+ comps=$( compgen -A file -- "$cur" )
+ compopt -o filenames
+ elif __contains_word "$prev" '--FIELD -F'; then
+ comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" )
+ elif [[ $cur = -* ]]; then
+ comps=${OPTS}
+ elif __contains_word "$prev" ${VERBS[*]} &&
+ ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then
+ compopt -o nospace
+ COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
+ return 0
+ elif [[ $cur = *=* ]]; then
+ mapfile -t field_vals < <(systemd-coredumpctl -F "${prev%=}" 2>/dev/null)
+ COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
+ return 0
+ else
+ for ((i=0; i <= COMP_CWORD; i++)); do
+ if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
+ verb=${COMP_WORDS[i]}
+ break
+ fi
+ done
+
+ if [[ -z $verb ]]; then
+ comps=${VERBS[*]}
+ elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then
+ comps=''
+ fi
+ fi
+
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+}
+complete -F _coredumpctl systemd-coredumpctl
+
_timedatectl() {
local i verb comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
commit 4f76ae1b4bfca0975373b78349928a60e94b000c
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Oct 30 10:15:24 2012 +0000
coredumpctl: add --field/-F option
Useful for completion generation.
diff --git a/man/systemd-coredumpctl.xml b/man/systemd-coredumpctl.xml
index b80aac8..4a6e83a 100644
--- a/man/systemd-coredumpctl.xml
+++ b/man/systemd-coredumpctl.xml
@@ -83,6 +83,16 @@
</varlistentry>
<varlistentry>
+ <term><option>--field=</option></term>
+ <term><option>-F</option></term>
+
+ <listitem><para>Print all possible
+ data values the specified field
+ takes in matching coredump entries of the
+ journal.</para></listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>--output=FILE</option></term>
<term><option>-o FILE</option></term>
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index e1b5a19..60bba7f 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -43,6 +43,7 @@ static enum {
static Set *matches = NULL;
static FILE* output = NULL;
+static char* field = NULL;
static int arg_no_pager = false;
static int arg_no_legend = false;
@@ -150,13 +151,14 @@ static int parse_argv(int argc, char *argv[]) {
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "output", required_argument, NULL, 'o' },
+ { "field", required_argument, NULL, 'F' },
{ NULL, 0, NULL, 0 }
};
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "ho:", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "ho:F:", options, NULL)) >= 0)
switch(c) {
case 'h':
help();
@@ -192,6 +194,15 @@ static int parse_argv(int argc, char *argv[]) {
break;
+ case 'F':
+ if (field) {
+ log_error("cannot use --field/-F more than once");
+ return -EINVAL;
+ }
+
+ field = optarg;
+ break;
+
case '?':
return -EINVAL;
@@ -214,6 +225,11 @@ static int parse_argv(int argc, char *argv[]) {
}
}
+ if (field && arg_action != ACTION_LIST) {
+ log_error("Option --field/-F only makes sense with list");
+ return -EINVAL;
+ }
+
while (optind < argc) {
r = add_match(matches, argv[optind]);
if (r != 0)
@@ -229,26 +245,39 @@ static int retrieve(const void *data,
const char *name,
const char **var) {
- size_t field;
+ size_t ident;
- field = strlen(name) + 1; /* name + "=" */
+ ident = strlen(name) + 1; /* name + "=" */
- if (len < field)
+ if (len < ident)
return 0;
- if (memcmp(data, name, field - 1) != 0)
+ if (memcmp(data, name, ident - 1) != 0)
return 0;
- if (((const char*) data)[field - 1] != '=')
+ if (((const char*) data)[ident - 1] != '=')
return 0;
- *var = strndup((const char*)data + field, len - field);
+ *var = strndup((const char*)data + ident, len - ident);
if (!var)
return log_oom();
return 0;
}
+static void print_field(FILE* file, sd_journal *j) {
+ const char _cleanup_free_ *value = NULL;
+ const void *d;
+ size_t l;
+
+ assert(field);
+
+ SD_JOURNAL_FOREACH_DATA(j, d, l)
+ retrieve(d, l, field, &value);
+ if (value)
+ fprintf(file, "%s\n", value);
+}
+
static int print_entry(FILE* file, sd_journal *j, int had_legend) {
const char _cleanup_free_
*pid = NULL, *uid = NULL, *gid = NULL,
@@ -310,10 +339,14 @@ static int dump_list(sd_journal *j) {
assert(j);
- SD_JOURNAL_FOREACH(j)
- print_entry(stdout, j, found++);
+ SD_JOURNAL_FOREACH(j) {
+ if (field)
+ print_field(stdout, j);
+ else
+ print_entry(stdout, j, found++);
+ }
- if (!found) {
+ if (!field && !found) {
log_notice("No coredumps found");
return -ESRCH;
}
commit 9a340880942c7c712bb6021e6633118d47378a32
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Oct 30 09:45:19 2012 +0100
coredumpctl: add --no-legend option
Useful for completion generation.
diff --git a/man/systemd-coredumpctl.xml b/man/systemd-coredumpctl.xml
index bbb4214..b80aac8 100644
--- a/man/systemd-coredumpctl.xml
+++ b/man/systemd-coredumpctl.xml
@@ -98,6 +98,13 @@
pager.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--no-legend</option></term>
+
+ <listitem><para>Do not print the column headers.
+ </para></listitem>
+ </varlistentry>
+
</variablelist>
<para>The following commands are understood:</para>
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 03f063f..e1b5a19 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -45,6 +45,7 @@ static Set *matches = NULL;
static FILE* output = NULL;
static int arg_no_pager = false;
+static int arg_no_legend = false;
static Set *new_matches(void) {
Set *set;
@@ -138,6 +139,7 @@ static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
ARG_NO_PAGER,
+ ARG_NO_LEGEND,
};
int r, c;
@@ -146,6 +148,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "help", no_argument, NULL, 'h' },
{ "version" , no_argument, NULL, ARG_VERSION },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
+ { "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "output", required_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 }
};
@@ -171,6 +174,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_no_pager = true;
break;
+ case ARG_NO_LEGEND:
+ arg_no_legend = true;
+ break;
+
case 'o':
if (output) {
log_error("cannot set output more than once");
@@ -242,7 +249,7 @@ static int retrieve(const void *data,
return 0;
}
-static int print_entry(FILE* file, sd_journal *j, int had_header) {
+static int print_entry(FILE* file, sd_journal *j, int had_legend) {
const char _cleanup_free_
*pid = NULL, *uid = NULL, *gid = NULL,
*sgnl = NULL, *exe = NULL;
@@ -278,7 +285,7 @@ static int print_entry(FILE* file, sd_journal *j, int had_header) {
format_timestamp(buf, sizeof(buf), t);
- if (!had_header)
+ if (!had_legend && !arg_no_legend)
fprintf(file, "%-*s %*s %*s %*s %*s %s\n",
FORMAT_TIMESTAMP_MAX-1, "TIME",
6, "PID",
commit 2fb7a5ce67fd6196416919535fa6a6065e0ea815
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Oct 30 09:44:32 2012 +0100
coredumpctl: fix program return code
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 3560534..03f063f 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -476,10 +476,13 @@ int main(int argc, char *argv[]) {
log_open();
matches = new_matches();
- if (!matches)
+ if (!matches) {
+ r = -ENOMEM;
goto end;
+ }
- if (parse_argv(argc, argv))
+ r = parse_argv(argc, argv);
+ if (r < 0)
goto end;
if (arg_action == ACTION_NONE)
commit 57ce4bd4ea3c54317490ad719fad17bc6413c3f6
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Oct 30 09:35:53 2012 +0100
coredumpctl: add guard to options table
It is not nice to segfault on unknown options :(
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 311c18b..3560534 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -143,10 +143,11 @@ static int parse_argv(int argc, char *argv[]) {
int r, c;
static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "version" , no_argument, NULL, ARG_VERSION },
- { "no-pager", no_argument, NULL, ARG_NO_PAGER },
- { "output", required_argument, NULL, 'o' },
+ { "help", no_argument, NULL, 'h' },
+ { "version" , no_argument, NULL, ARG_VERSION },
+ { "no-pager", no_argument, NULL, ARG_NO_PAGER },
+ { "output", required_argument, NULL, 'o' },
+ { NULL, 0, NULL, 0 }
};
assert(argc >= 0);
@@ -183,6 +184,10 @@ static int parse_argv(int argc, char *argv[]) {
}
break;
+
+ case '?':
+ return -EINVAL;
+
default:
log_error("Unknown option code %c", c);
return -EINVAL;
More information about the systemd-commits
mailing list