Debian Codegraph @

man/journal-stream-fd.c

raw
1 /* SPDX-License-Identifier: MIT-0 */
2
3 #define _GNU_SOURCE 1
4 #include <errno.h>
5 #include <syslog.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <systemd/sd-journal.h>
9 #include <systemd/sd-daemon.h>
10
11 int main(int argc, char *argv[]) {
12 int fd;
13 FILE *log;
14
15 fd = sd_journal_stream_fd("test", LOG_INFO, 1);
16 if (fd < 0) {
17 fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
18 return 1;
19 }
20
21 log = fdopen(fd, "w");
22 if (!log) {
23 fprintf(stderr, "Failed to create file object: %s\n", strerror(errno));
24 close(fd);
25 return 1;
26 }
27 fprintf(log, "Hello World!\n");
28 fprintf(log, SD_WARNING "This is a warning!\n");
29 fclose(log);
30 return 0;
31 }