-
Notifications
You must be signed in to change notification settings - Fork 13
/
systemd.c
65 lines (55 loc) · 1.4 KB
/
systemd.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_systemd.h"
#include <systemd/sd-journal.h>
zend_function_entry systemd_functions[] = {
PHP_FE(sd_journal_send, NULL)
{NULL, NULL, NULL} // Sentinel
};
zend_module_entry systemd_module_entry = {
STANDARD_MODULE_HEADER,
PHP_SYSTEMD_EXTNAME,
systemd_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
PHP_SYSTEMD_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_SYSTEMD
ZEND_GET_MODULE(systemd)
#endif
PHP_FUNCTION(sd_journal_send)
{
struct iovec *iov = NULL;
zval *args;
int argc, len, i;
char *val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) != SUCCESS) {
return;
}
// Allocate sufficient iovector space for the arguments.
iov = safe_emalloc(argc, sizeof(struct iovec), 0);
if (!iov) {
// Should probably raise a more clear error.
RETURN_FALSE;
}
// Iterate through the PHP arguments and fill the iovector.
for (i = 0; i < argc; ++i) {
convert_to_string_ex(&args[i]);
val = Z_STRVAL(args[i]);
len = Z_STRLEN(args[i]);
iov[i].iov_base = val;
iov[i].iov_len = len;
}
// Send the iovector to journald.
sd_journal_sendv(iov, argc);
// Free the iovector. The actual strings
// are already managed by PHP.
efree(iov);
RETURN_TRUE;
}