]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
man: move more examples to stand-alone files and use 2-space indentation consistenty
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Jul 2018 06:24:45 +0000 (08:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 2 Aug 2018 13:45:24 +0000 (15:45 +0200)
Moving them out makes it easier to run them through a compiler, use automatic
indentation, and opens the possibility to provide a download link in the
future. I verified that all examples compile cleanly.

(2-space indentation is used because the examples are already significantly
indented in the man page, and we need to keep them narrow so that they display
well on standard terminals.)

man/id128-app-specific.c [new file with mode: 0644]
man/journal-iterate-unique.c [new file with mode: 0644]
man/sd_bus_new.xml
man/sd_id128_get_machine.xml
man/sd_journal_query_unique.xml
man/sd_login_monitor_new.xml

diff --git a/man/id128-app-specific.c b/man/id128-app-specific.c
new file mode 100644 (file)
index 0000000..b81e50f
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <systemd/sd-id128.h>
+
+#define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
+
+int main(int argc, char *argv[]) {
+  sd_id128_t id;
+  sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &id);
+  printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
+  return 0;
+}
diff --git a/man/journal-iterate-unique.c b/man/journal-iterate-unique.c
new file mode 100644 (file)
index 0000000..fcf92e7
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <string.h>
+#include <systemd/sd-journal.h>
+
+int main(int argc, char *argv[]) {
+  sd_journal *j;
+  const void *d;
+  size_t l;
+  int r;
+
+  r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
+  if (r < 0) {
+    fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
+    return 1;
+  }
+  r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
+  if (r < 0) {
+    fprintf(stderr, "Failed to query journal: %s\n", strerror(-r));
+    return 1;
+  }
+  SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
+    printf("%.*s\n", (int) l, (const char*) d);
+  sd_journal_close(j);
+  return 0;
+}
index 5180ae78157da6cb3f443d072173c9d9cbca5a8f..59117676fde93e12cea8ed5f675d7775683594fc 100644 (file)
     block is left:</para>
 
     <programlisting>{
-        __attribute__((cleanup(sd_bus_unrefp)) sd_bus *bus = NULL;
-        int r;
-        
-        r = sd_bus_default(&amp;bus);
-        if (r &lt; 0)
-                fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r));
-        
+  __attribute__((cleanup(sd_bus_unrefp)) sd_bus *bus = NULL;
+  int r;
+  …
+  r = sd_bus_default(&amp;bus);
+  if (r &lt; 0)
+    fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r));
+  …
 }</programlisting>
 
     <para><function>sd_bus_ref()</function> and <function>sd_bus_unref()</function>
index 954fd2e6a7616f0b2be3e1bf5f42db7063b0ddd3..9587aa7d66a30edb225ee197f7457a22b70b50be 100644 (file)
 
       <para>Here's a simple example for an application specific machine ID:</para>
 
-      <programlisting>#include &lt;systemd/sd-id128.h&gt;
-#include &lt;stdio.h&gt;
-
-#define OUR_APPLICATION_ID SD_ID128_MAKE(c2,73,27,73,23,db,45,4e,a6,3b,b9,6e,79,b5,3e,97)
-
-int main(int argc, char *argv[]) {
-        sd_id128_t id;
-        sd_id128_get_machine_app_specific(OUR_APPLICATION_ID, &amp;id);
-        printf("Our application ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
-        return 0;
-}</programlisting>
+      <programlisting><xi:include href="id128-app-specific.c" parse="text" /></programlisting>
     </example>
   </refsect1>
 
index 0bbc479f22e289ce67c1c639bdccfc117c6bc683..c62f333eabb809aed1c1b8985ed888f7b15ee668 100644 (file)
     following example lists all unit names referenced in the
     journal:</para>
 
-    <programlisting>#include &lt;stdio.h&gt;
-#include &lt;string.h&gt;
-#include &lt;systemd/sd-journal.h&gt;
-
-int main(int argc, char *argv[]) {
-        sd_journal *j;
-        const void *d;
-        size_t l;
-        int r;
-
-        r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
-        if (r &lt; 0) {
-                fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
-                return 1;
-        }
-        r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
-        if (r &lt; 0) {
-                fprintf(stderr, "Failed to query journal: %s\n", strerror(-r));
-                return 1;
-        }
-        SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
-                printf("%.*s\n", (int) l, (const char*) d);
-        sd_journal_close(j);
-        return 0;
-}</programlisting>
-
+    <programlisting><xi:include href="journal-iterate-unique.c" parse="text" /></programlisting>
   </refsect1>
 
   <refsect1>
index 23f685bb3184455e3bd581fce2e7f9c1b0a572af..d914e51d0d98a780a0539d7285776d3a0303860d 100644 (file)
     code block is left:</para>
 
     <programlisting>{
-        __attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL;
-        int r;
-        
-        r = sd_login_monitor_default(&amp;m);
-        if (r &lt; 0)
-                fprintf(stderr, "Failed to allocate login monitor object: %s\n", strerror(-r));
-        
+  __attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL;
+  int r;
+  …
+  r = sd_login_monitor_default(&amp;m);
+  if (r &lt; 0)
+    fprintf(stderr, "Failed to allocate login monitor object: %s\n", strerror(-r));
+  …
 }</programlisting>
 
     <para><function>sd_login_monitor_flush()</function> may be used to
 int msec;
 sd_login_monitor_get_timeout(m, &amp;t);
 if (t == (uint64_t) -1)
-         msec = -1;
+  msec = -1;
 else {
-         struct timespec ts;
-         uint64_t n;
-         clock_gettime(CLOCK_MONOTONIC, &amp;ts);
-         n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
-         msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
+  struct timespec ts;
+  uint64_t n;
+  clock_gettime(CLOCK_MONOTONIC, &amp;ts);
+  n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+  msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
 }</programlisting>
 
     <para>The code above does not do any error checking for brevity's