File: Write.xs

package info (click to toggle)
liblinux-systemd-perl 1.201600-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 640; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#define SD_JOURNAL_SUPPRESS_LOCATION
#include <systemd/sd-journal.h>

MODULE = Linux::Systemd::Journal::Write	PACKAGE = Linux::Systemd::Journal::Write

PROTOTYPES: DISABLE

NO_OUTPUT int
__sd_journal_print(int pri, const char *msg, ...)
    CODE:
        RETVAL = sd_journal_print( pri, "%s", msg );
    POSTCALL:
        if (RETVAL < 0)
             croak("Error %d while sending message", RETVAL);

NO_OUTPUT int
__sd_journal_perror(const char *msg)
    CODE:
        RETVAL = sd_journal_perror(msg );
    POSTCALL:
        if (RETVAL < 0)
             croak("Error %d while sending message", RETVAL);

NO_OUTPUT int
__sd_journal_send(AV *data)
    CODE:
        int array_size = av_len(data) + 1;
        struct iovec iov[array_size];

        for (int i = 0; i < array_size; i++) {
            SV *s = av_shift(data);
            char *str = SvPV(s, SvLEN(s));
            iov[i].iov_base = str;
            iov[i].iov_len = strlen(str);
        }

        RETVAL = sd_journal_sendv(iov, array_size);
    POSTCALL:
        if (RETVAL < 0)
             croak("Error sending message: %s", strerror(RETVAL));