Coverage Report

Created: 2026-10-28 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/standard/syslog.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Author: Stig Sæther Bakken <ssb@php.net>                             |
12
   +----------------------------------------------------------------------+
13
 */
14
15
#include "php.h"
16
17
#ifdef HAVE_SYSLOG_H
18
#include "php_ini.h"
19
#include "zend_globals.h"
20
21
#include <stdlib.h>
22
#ifdef HAVE_UNISTD_H
23
#include <unistd.h>
24
#endif
25
26
#include <string.h>
27
#include <errno.h>
28
29
#include <stdio.h>
30
#include "basic_functions.h"
31
#include "php_ext_syslog.h"
32
33
/* {{{ PHP_MINIT_FUNCTION */
34
PHP_MINIT_FUNCTION(syslog)
35
16
{
36
16
  return SUCCESS;
37
16
}
38
/* }}} */
39
40
PHP_RSHUTDOWN_FUNCTION(syslog)
41
306k
{
42
306k
  if (PG(have_called_openlog)) {
43
0
    php_closelog();
44
0
  }
45
306k
  if (BG(syslog_device)) {
46
0
    free(BG(syslog_device));
47
0
    BG(syslog_device) = NULL;
48
0
  }
49
306k
  return SUCCESS;
50
306k
}
51
52
53
/* {{{ Open connection to system logger */
54
/*
55
   ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
56
   ** Syslog($LOG_EMERG, "help me!")
57
   ** CloseLog();
58
 */
59
PHP_FUNCTION(openlog)
60
0
{
61
0
  char *ident;
62
0
  zend_long option, facility;
63
0
  size_t ident_len;
64
65
0
  ZEND_PARSE_PARAMETERS_START(3, 3)
66
0
    Z_PARAM_PATH(ident, ident_len)
67
0
    Z_PARAM_LONG(option)
68
0
    Z_PARAM_LONG(facility)
69
0
  ZEND_PARSE_PARAMETERS_END();
70
71
0
  if (BG(syslog_device)) {
72
0
    free(BG(syslog_device));
73
0
  }
74
0
  BG(syslog_device) = zend_strndup(ident, ident_len);
75
0
  php_openlog(BG(syslog_device), option, facility);
76
0
  RETURN_TRUE;
77
0
}
78
/* }}} */
79
80
/* {{{ Close connection to system logger */
81
PHP_FUNCTION(closelog)
82
0
{
83
0
  ZEND_PARSE_PARAMETERS_NONE();
84
85
0
  php_closelog();
86
0
  if (BG(syslog_device)) {
87
0
    free(BG(syslog_device));
88
0
    BG(syslog_device)=NULL;
89
0
  }
90
0
  RETURN_TRUE;
91
0
}
92
/* }}} */
93
94
/* {{{ Generate a system log message */
95
PHP_FUNCTION(syslog)
96
0
{
97
0
  zend_long priority;
98
0
  zend_string *message;
99
100
0
  ZEND_PARSE_PARAMETERS_START(2, 2)
101
0
    Z_PARAM_LONG(priority)
102
0
    Z_PARAM_STR(message)
103
0
  ZEND_PARSE_PARAMETERS_END();
104
105
0
  if (!PG(have_called_openlog)) {
106
0
    php_openlog(PG(syslog_ident), 0, PG(syslog_facility));
107
0
  }
108
0
  php_syslog_str(priority, message);
109
0
  RETURN_TRUE;
110
0
}
111
/* }}} */
112
113
#endif