Coverage Report

Created: 2025-06-13 06:43

/src/php-src/ext/standard/syslog.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright (c) The PHP Group                                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to version 3.01 of the PHP license,      |
6
   | that is bundled with this package in the file LICENSE, and is        |
7
   | available through the world-wide-web at the following url:           |
8
   | https://www.php.net/license/3_01.txt                                 |
9
   | If you did not receive a copy of the PHP license and are unable to   |
10
   | obtain it through the world-wide-web, please send a note to          |
11
   | license@php.net so we can mail you a copy immediately.               |
12
   +----------------------------------------------------------------------+
13
   | Author: Stig Sæther Bakken <ssb@php.net>                             |
14
   +----------------------------------------------------------------------+
15
 */
16
17
#include "php.h"
18
19
#ifdef HAVE_SYSLOG_H
20
#include "php_ini.h"
21
#include "zend_globals.h"
22
23
#include <stdlib.h>
24
#ifdef HAVE_UNISTD_H
25
#include <unistd.h>
26
#endif
27
28
#include <string.h>
29
#include <errno.h>
30
31
#include <stdio.h>
32
#include "basic_functions.h"
33
#include "php_ext_syslog.h"
34
35
/* {{{ PHP_MINIT_FUNCTION */
36
PHP_MINIT_FUNCTION(syslog)
37
16
{
38
16
  return SUCCESS;
39
16
}
40
/* }}} */
41
42
PHP_RSHUTDOWN_FUNCTION(syslog)
43
300k
{
44
300k
  php_closelog();
45
300k
  if (BG(syslog_device)) {
46
0
    free(BG(syslog_device));
47
0
    BG(syslog_device) = NULL;
48
0
  }
49
300k
  return SUCCESS;
50
300k
}
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_STRING(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
  php_syslog_str(priority, message);
106
0
  RETURN_TRUE;
107
0
}
108
/* }}} */
109
110
#endif