|
| 1 | +<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 | +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
| 3 | + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
| 4 | + |
| 5 | +<!-- |
| 6 | + This file is part of systemd. |
| 7 | +
|
| 8 | + Copyright 2016 Lennart Poettering |
| 9 | +
|
| 10 | + systemd is free software; you can redistribute it and/or modify it |
| 11 | + under the terms of the GNU Lesser General Public License as published by |
| 12 | + the Free Software Foundation; either version 2.1 of the License, or |
| 13 | + (at your option) any later version. |
| 14 | +
|
| 15 | + systemd is distributed in the hope that it will be useful, but |
| 16 | + WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | + Lesser General Public License for more details. |
| 19 | +
|
| 20 | + You should have received a copy of the GNU Lesser General Public License |
| 21 | + along with systemd; If not, see <http://www.gnu.org/licenses/>. |
| 22 | +--> |
| 23 | + |
| 24 | +<refentry id="sd_journal_enumerate_fields"> |
| 25 | + |
| 26 | + <refentryinfo> |
| 27 | + <title>sd_journal_enumerate_fields</title> |
| 28 | + <productname>systemd</productname> |
| 29 | + |
| 30 | + <authorgroup> |
| 31 | + <author> |
| 32 | + <contrib>Developer</contrib> |
| 33 | + <firstname>Lennart</firstname> |
| 34 | + <surname>Poettering</surname> |
| 35 | + <email>lennart@poettering.net</email> |
| 36 | + </author> |
| 37 | + </authorgroup> |
| 38 | + </refentryinfo> |
| 39 | + |
| 40 | + <refmeta> |
| 41 | + <refentrytitle>sd_journal_enumerate_fields</refentrytitle> |
| 42 | + <manvolnum>3</manvolnum> |
| 43 | + </refmeta> |
| 44 | + |
| 45 | + <refnamediv> |
| 46 | + <refname>sd_journal_enumerate_fields</refname> |
| 47 | + <refname>sd_journal_restart_fields</refname> |
| 48 | + <refname>SD_JOURNAL_FOREACH_FIELD</refname> |
| 49 | + <refpurpose>Read used field names from the journal</refpurpose> |
| 50 | + </refnamediv> |
| 51 | + |
| 52 | + <refsynopsisdiv> |
| 53 | + <funcsynopsis> |
| 54 | + <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> |
| 55 | + |
| 56 | + <funcprototype> |
| 57 | + <funcdef>int <function>sd_journal_enumerate_fields</function></funcdef> |
| 58 | + <paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 59 | + <paramdef>const char **<parameter>field</parameter></paramdef> |
| 60 | + </funcprototype> |
| 61 | + |
| 62 | + <funcprototype> |
| 63 | + <funcdef>void <function>sd_journal_restart_fields</function></funcdef> |
| 64 | + <paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 65 | + </funcprototype> |
| 66 | + |
| 67 | + <funcprototype> |
| 68 | + <funcdef><function>SD_JOURNAL_FOREACH_FIELD</function></funcdef> |
| 69 | + <paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 70 | + <paramdef>const char *<parameter>field</parameter></paramdef> |
| 71 | + </funcprototype> |
| 72 | + |
| 73 | + </funcsynopsis> |
| 74 | + </refsynopsisdiv> |
| 75 | + |
| 76 | + <refsect1> |
| 77 | + <title>Description</title> |
| 78 | + |
| 79 | + <para><function>sd_journal_enumerate_fields()</function> may be used to iterate through all field names used in the |
| 80 | + opened journal files. On each invocation the next field name is returned. The order of the returned field names is |
| 81 | + not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where |
| 82 | + the field name is stored in. The returned data is in a read-only memory map and is only valid until the next |
| 83 | + invocation of <function>sd_journal_enumerate_fields()</function>. Note that this call is subject to the data field |
| 84 | + size threshold as controlled by <function>sd_journal_set_data_threshold()</function>.</para> |
| 85 | + |
| 86 | + <para><function>sd_journal_restart_fields()</function> resets the field name enumeration index to the beginning of |
| 87 | + the list. The next invocation of <function>sd_journal_enumerate_fields()</function> will return the first field |
| 88 | + name again.</para> |
| 89 | + |
| 90 | + <para>The <function>SD_JOURNAL_FOREACH_FIELD()</function> macro may be used as a handy wrapper around |
| 91 | + <function>sd_journal_restart_fields()</function> and <function>sd_journal_enumerate_fields()</function>.</para> |
| 92 | + |
| 93 | + <para>These functions currently are not influenced by matches set with <function>sd_journal_add_match()</function> |
| 94 | + but this might change in a later version of this software.</para> |
| 95 | + |
| 96 | + <para>To retrieve the possible values a specific field can take use |
| 97 | + <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> |
| 98 | + </refsect1> |
| 99 | + |
| 100 | + <refsect1> |
| 101 | + <title>Return Value</title> |
| 102 | + |
| 103 | + <para><function>sd_journal_enumerate_fields()</function> returns a |
| 104 | + positive integer if the next field name has been read, 0 when no |
| 105 | + more field names are known, or a negative errno-style error code. |
| 106 | + <function>sd_journal_restart_fields()</function> returns |
| 107 | + nothing.</para> |
| 108 | + </refsect1> |
| 109 | + |
| 110 | + <refsect1> |
| 111 | + <title>Notes</title> |
| 112 | + |
| 113 | + <para>The <function>sd_journal_enumerate_fields()</function> and <function>sd_journal_restart_fields()</function> |
| 114 | + interfaces are available as a shared library, which can be compiled and linked to with the |
| 115 | + <constant>libsystemd</constant> <citerefentry |
| 116 | + project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para> |
| 117 | + </refsect1> |
| 118 | + |
| 119 | + <refsect1> |
| 120 | + <title>Examples</title> |
| 121 | + |
| 122 | + <para>Use the <function>SD_JOURNAL_FOREACH_FIELD</function> macro to iterate through all field names in use in the |
| 123 | + current journal.</para> |
| 124 | + |
| 125 | + <programlisting>#include <stdio.h> |
| 126 | +#include <string.h> |
| 127 | +#include <systemd/sd-journal.h> |
| 128 | + |
| 129 | +int main(int argc, char *argv[]) { |
| 130 | + sd_journal *j; |
| 131 | + const char *field; |
| 132 | + int r; |
| 133 | + |
| 134 | + r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
| 135 | + if (r < 0) { |
| 136 | + fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); |
| 137 | + return 1; |
| 138 | + } |
| 139 | + SD_JOURNAL_FOREACH_FIELD(j, field) |
| 140 | + printf("%s\n", field); |
| 141 | + sd_journal_close(j); |
| 142 | + return 0; |
| 143 | +}</programlisting> |
| 144 | + |
| 145 | + </refsect1> |
| 146 | + |
| 147 | + <refsect1> |
| 148 | + <title>See Also</title> |
| 149 | + |
| 150 | + <para> |
| 151 | + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, |
| 152 | + <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>, |
| 153 | + <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 154 | + <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 155 | + <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 156 | + <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 157 | + <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 158 | + </para> |
| 159 | + </refsect1> |
| 160 | + |
| 161 | +</refentry> |
0 commit comments