2022-10-26 06:02:14 +00:00
|
|
|
/* SPDX-License-Identifier: MIT-0 */
|
2022-10-10 07:18:26 +00:00
|
|
|
|
2024-04-03 16:29:41 +00:00
|
|
|
#define _GNU_SOURCE 1
|
2022-10-07 14:19:21 +00:00
|
|
|
#include <errno.h>
|
2022-10-10 07:18:26 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <systemd/sd-journal.h>
|
|
|
|
#include <systemd/sd-daemon.h>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int fd;
|
|
|
|
FILE *log;
|
2024-04-02 18:40:05 +00:00
|
|
|
|
2022-10-10 07:18:26 +00:00
|
|
|
fd = sd_journal_stream_fd("test", LOG_INFO, 1);
|
|
|
|
if (fd < 0) {
|
2024-04-02 18:40:05 +00:00
|
|
|
fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
|
2022-10-10 07:18:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2024-04-02 18:40:05 +00:00
|
|
|
|
2022-10-10 07:18:26 +00:00
|
|
|
log = fdopen(fd, "w");
|
|
|
|
if (!log) {
|
2024-04-02 18:40:05 +00:00
|
|
|
fprintf(stderr, "Failed to create file object: %s\n", strerror(errno));
|
2022-10-10 07:18:26 +00:00
|
|
|
close(fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
fprintf(log, "Hello World!\n");
|
|
|
|
fprintf(log, SD_WARNING "This is a warning!\n");
|
|
|
|
fclose(log);
|
|
|
|
return 0;
|
|
|
|
}
|