2 suPHP - (c)2002-2004 Sebastian Marsching <sebastian@marsching.com>
4 This file is part of suPHP.
6 suPHP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 suPHP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sys/types.h>
33 int log_initialized = 0;
35 void suphp_log_error(char *err_msg, ...)
41 // Build error message
42 va_start(vargs, err_msg);
43 vsnprintf(msg, 4095, err_msg, vargs);
46 // Write message to logfile
47 suphp_log(msg, "error");
50 void suphp_log_info(char *info_msg, ...)
56 // Build error message
57 va_start(vargs, info_msg);
58 vsnprintf(msg, 4095, info_msg, vargs);
61 // Write message to logfile
62 suphp_log(msg, "info");
67 if ((log_fd = open(OPT_LOGFILE, O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY, S_IRUSR | S_IWUSR)) == -1)
68 error_sysmsg_exit(ERRCODE_NO_LOG, "Could not open logfile", __FILE__, __LINE__);
69 if (fcntl(log_fd, F_SETFD, FD_CLOEXEC))
70 error_sysmsg_exit(ERRCODE_UNKNOWN, "Could not set close-on-exec attribute for logfile", __FILE__, __LINE__);
74 void suphp_log(char *msg, char *category)
85 strftime(str_time, 1023, "[%a %b %d %H:%M:%S %Y]", now);
87 // Build entry for logfile
88 snprintf(row, 8191, "%s [%s] %s\n", str_time, category, msg);
91 write(log_fd, row, strlen(row));