Useful for completion generation.
string and exit.</para></listitem>
</varlistentry>
string and exit.</para></listitem>
</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>
<varlistentry>
<term><option>--output=FILE</option></term>
<term><option>-o FILE</option></term>
static Set *matches = NULL;
static FILE* output = NULL;
static Set *matches = NULL;
static FILE* output = NULL;
+static char* field = NULL;
static int arg_no_pager = false;
static int arg_no_legend = false;
static int arg_no_pager = false;
static int arg_no_legend = false;
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "output", required_argument, NULL, 'o' },
{ "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);
{ 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();
switch(c) {
case 'h':
help();
+ case 'F':
+ if (field) {
+ log_error("cannot use --field/-F more than once");
+ return -EINVAL;
+ }
+
+ field = optarg;
+ break;
+
case '?':
return -EINVAL;
case '?':
return -EINVAL;
+ 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)
while (optind < argc) {
r = add_match(matches, argv[optind]);
if (r != 0)
const char *name,
const char **var) {
const char *name,
const char **var) {
- field = strlen(name) + 1; /* name + "=" */
+ ident = strlen(name) + 1; /* name + "=" */
- if (memcmp(data, name, field - 1) != 0)
+ if (memcmp(data, name, ident - 1) != 0)
- if (((const char*) data)[field - 1] != '=')
+ if (((const char*) data)[ident - 1] != '=')
- *var = strndup((const char*)data + field, len - field);
+ *var = strndup((const char*)data + ident, len - ident);
if (!var)
return log_oom();
return 0;
}
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,
static int print_entry(FILE* file, sd_journal *j, int had_legend) {
const char _cleanup_free_
*pid = NULL, *uid = NULL, *gid = NULL,
- 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 (!field && !found) {
log_notice("No coredumps found");
return -ESRCH;
}
log_notice("No coredumps found");
return -ESRCH;
}