-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathsyslog.c
112 lines (94 loc) · 2.57 KB
/
syslog.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Stig Sæther Bakken <ssb@php.net> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#ifdef HAVE_SYSLOG_H
#include "php_ini.h"
#include "zend_globals.h"
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "basic_functions.h"
#include "php_ext_syslog.h"
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(syslog)
{
BG(syslog_device)=NULL;
return SUCCESS;
}
/* }}} */
PHP_RSHUTDOWN_FUNCTION(syslog)
{
php_closelog();
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
}
return SUCCESS;
}
/* {{{ Open connection to system logger */
/*
** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
** Syslog($LOG_EMERG, "help me!")
** CloseLog();
*/
PHP_FUNCTION(openlog)
{
char *ident;
zend_long option, facility;
size_t ident_len;
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_STRING(ident, ident_len)
Z_PARAM_LONG(option)
Z_PARAM_LONG(facility)
ZEND_PARSE_PARAMETERS_END();
if (BG(syslog_device)) {
free(BG(syslog_device));
}
BG(syslog_device) = zend_strndup(ident, ident_len);
php_openlog(BG(syslog_device), option, facility);
RETURN_TRUE;
}
/* }}} */
/* {{{ Close connection to system logger */
PHP_FUNCTION(closelog)
{
ZEND_PARSE_PARAMETERS_NONE();
php_closelog();
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device)=NULL;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ Generate a system log message */
PHP_FUNCTION(syslog)
{
zend_long priority;
zend_string *message;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_LONG(priority)
Z_PARAM_STR(message)
ZEND_PARSE_PARAMETERS_END();
php_syslog_str(priority, message);
RETURN_TRUE;
}
/* }}} */
#endif