• R/O
  • HTTP
  • SSH
  • HTTPS

openpts: 提交

Repo for OpenPTS version 0.2.X


Commit MetaInfo

修订版a0496f4d32b4ec6d3ea4598e559b9fdfeb8ddc31 (tree)
时间2012-01-05 09:05:41
作者Seiji Munetoh <munetoh@jp.i...>
CommiterSeiji Munetoh

Log Message

set initial value (-1) to catd to avoid segmentation fault by catgets called before catopen

更改概述

差异

--- a/src/log.c
+++ b/src/log.c
@@ -26,43 +26,31 @@
2626 * \brief logging functions
2727 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
2828 * @date 2010-05-07
29- * cleanup 2011-01-22 SM
30- * cleanup 2011-12-28 SM
29+ * cleanup 2012-01-04 SM
3130 *
32- * Verbose OUTPUT VERBOSE LOGGING
33- * Level (stdout) (stderr) (console/syslog/file)
31+ * Console output
32+ *
33+ * Verbose OUTPUT ERROR/VERBOSE
34+ * Level (stdout) (stderr)
3435 * --------------------------------------------------
35- * 0 ON ERROR msg. ERROR/INFO
36- * 1 ON +verbose msg. ERROR/INFO
37- * 2 ON ERROR/INFO+DEBUG
36+ * 0 ON ERROR msg.
37+ * 1 ON +verbose(1) msg
38+ * 2 ON +verbose(2) msg
3839 * --------------------------------------------------
3940 *
40- * LOG
41- * off
42- * error
43- * on/debug
44- *
45- * Config
46- * verbose=0
47- * logging.location=console|syslog|file
48- * logging.file=./ptsc.log
49- * debug.mode=0x01
41+ * Logging (syslog/console/file)
5042 *
51- * Priority
52- * 1. Commandline option (location/file must be given by conf)
53- * 2. ENV
54- * 3. Conf file
43+ * Default logging scheme is hard coded by each command
5544 *
56- * LOG("msg",format)
45+ * ptsc -m syslog -> conf
46+ * ptsc else env -> conf
47+ * openpts default(file ~/.openpts/openpts.log) -> conf
5748 *
58- * OUTPUT console/stderr
59- * VERBOSE console/stderr
60- * ASSERT console/stderr
49+ * Controlled by config file
50+ * debug.mode=0x01
51+ * logging.location=console|syslog|file
52+ * logging.file=./ptsc.log
6153 *
62- * ERROR console|file|syslog
63- * INFO console|file|syslog
64- * TODO console|file|syslog
65- * DEBUG console|file|syslog
6654 *
6755 */
6856
@@ -107,7 +95,7 @@
10795 #include <locale.h>
10896 #ifdef HAVE_CATGETS
10997 #include <nl_types.h>
110-nl_catd catd;
98+nl_catd catd = (nl_catd) -1; /* set error until open */
11199 #endif
112100 #endif
113101
@@ -206,7 +194,7 @@ void determineLogLocationByEnv(void) {
206194
207195 /* debug mode => debugBits */
208196 if ((tempDebugMode = getenv("OPENPTS_DEBUG_MODE")) != NULL) {
209- debugBits = (int) strtol(tempDebugMode,NULL,16);
197+ debugBits = (int) strtol(tempDebugMode, NULL, 16);
210198 DEBUG("DEBUG FLAG(0x%x) set by ENV\n", debugBits);
211199 }
212200 }
@@ -222,7 +210,7 @@ void setLogLocation(int ll, char *filename) {
222210 char * oldlog;
223211 /* already open */
224212 LOG(LOG_INFO, "Logfile changed from %s to %s\n", logFileName, filename);
225- oldlog=strdup(logFileName);
213+ oldlog = strdup(logFileName);
226214 if (oldlog == NULL) {
227215 LOG(LOG_ERR, "no memory");
228216 return;
@@ -389,42 +377,11 @@ void writeLog(int priority, const char *format, ...) {
389377 fprintf(stderr, "%s", logEntry);
390378 break;
391379 }
392- // TODO default?
380+ default:
381+ LOG(LOG_ERR, "Unknown logLocation, %d", logLocation);
382+ break;
393383 }
394384
395-
396-#if 0
397- va_start(list, format);
398-
399- // if (getenv("PTSCD_DAEMON") != NULL) {
400- if (getenv("OPENPTS_SYSLOG") != NULL) {
401- /* daemon -> syslog */
402- openlog("ptsc", LOG_NDELAY|LOG_PID, LOG_LOCAL5);
403-
404- // 2011-04-11 SM shows verbose messages
405- if (priority == LOG_DEBUG) priority = LOG_INFO;
406-
407- // vsyslog is not supported by some unix
408- vsnprintf(buf, SYSLOG_BUF_SIZE, format, list);
409- syslog(priority, "%s", buf);
410-
411- closelog();
412- } else {
413- /* foregrond -> stdout */
414- if (priority == LOG_INFO) {
415- fprintf(stdout, "INFO:");
416- } else if (priority == LOG_ERR) {
417- fprintf(stdout, "ERROR:");
418- } else {
419- fprintf(stdout, "%d:", priority);
420- }
421- vfprintf(stdout, format, list);
422- fprintf(stdout, "\n");
423- }
424- va_end(list);
425-#endif
426-
427-
428385 if (format2 != NULL) free(format2);
429386 }
430387
@@ -435,7 +392,7 @@ static int openLogFile(void) {
435392 return logFileFd;
436393 }
437394
438- //logFileFd = open(logFileName, O_RDWR|O_CREAT|O_TRUNC, DEFAULT_LOG_FILE_PERM);
395+ /* append to the existing file */
439396 logFileFd = open(logFileName, O_WRONLY|O_CREAT|O_APPEND, DEFAULT_LOG_FILE_PERM);
440397 return logFileFd;
441398 }
Show on old repository browser