mirror of
https://github.com/systemd/systemd.git
synced 2025-01-03 05:18:09 +03:00
man: move more examples to stand-alone files and use 2-space indentation consistenty
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.)
This commit is contained in:
parent
2c47fff6d2
commit
787f78b6a1
11
man/id128-app-specific.c
Normal file
11
man/id128-app-specific.c
Normal file
@ -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;
|
||||
}
|
25
man/journal-iterate-unique.c
Normal file
25
man/journal-iterate-unique.c
Normal file
@ -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;
|
||||
}
|
@ -96,13 +96,13 @@
|
||||
block is left:</para>
|
||||
|
||||
<programlisting>{
|
||||
__attribute__((cleanup(sd_bus_unrefp)) sd_bus *bus = NULL;
|
||||
int r;
|
||||
…
|
||||
r = sd_bus_default(&bus);
|
||||
if (r < 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(&bus);
|
||||
if (r < 0)
|
||||
fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r));
|
||||
…
|
||||
}</programlisting>
|
||||
|
||||
<para><function>sd_bus_ref()</function> and <function>sd_bus_unref()</function>
|
||||
|
@ -120,17 +120,7 @@
|
||||
|
||||
<para>Here's a simple example for an application specific machine ID:</para>
|
||||
|
||||
<programlisting>#include <systemd/sd-id128.h>
|
||||
#include <stdio.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;
|
||||
}</programlisting>
|
||||
<programlisting><xi:include href="id128-app-specific.c" parse="text" /></programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
|
@ -140,32 +140,7 @@
|
||||
following example lists all unit names referenced in the
|
||||
journal:</para>
|
||||
|
||||
<programlisting>#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;
|
||||
}</programlisting>
|
||||
|
||||
<programlisting><xi:include href="journal-iterate-unique.c" parse="text" /></programlisting>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -115,13 +115,13 @@
|
||||
code block is left:</para>
|
||||
|
||||
<programlisting>{
|
||||
__attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL;
|
||||
int r;
|
||||
…
|
||||
r = sd_login_monitor_default(&m);
|
||||
if (r < 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(&m);
|
||||
if (r < 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
|
||||
@ -176,13 +176,13 @@
|
||||
int msec;
|
||||
sd_login_monitor_get_timeout(m, &t);
|
||||
if (t == (uint64_t) -1)
|
||||
msec = -1;
|
||||
msec = -1;
|
||||
else {
|
||||
struct timespec ts;
|
||||
uint64_t n;
|
||||
clock_gettime(CLOCK_MONOTONIC, &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, &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
|
||||
|
Loading…
Reference in New Issue
Block a user