summaryrefslogtreecommitdiff
path: root/log-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-11 17:57:39 +1100
committerDamien Miller <djm@mindrot.org>1999-11-11 17:57:39 +1100
commit5ce662a9202240a2f5fa6a9334d58186bdaba50c (patch)
tree9fe37122fa27f070abc3c9c28531877d43673b7f /log-client.c
parentab5e0d0c27e00dca463c67395c2b5941e778836e (diff)
- Merged more OpenBSD CVS changes:
- [auth-krb4.c auth-passwd.c] remove x11- and krb-cleanup from fatal() + krb-cleanup cleanup - [clientloop.c log-client.c log-server.c ] [readconf.c readconf.h servconf.c servconf.h ] [ssh.1 ssh.c ssh.h sshd.8] add LogLevel {QUIET, FATAL, ERROR, INFO, CHAT, DEBUG} to ssh/sshd, obsoletes QuietMode and FascistLogging in sshd.
Diffstat (limited to 'log-client.c')
-rw-r--r--log-client.c137
1 files changed, 31 insertions, 106 deletions
diff --git a/log-client.c b/log-client.c
index 1792ba847..63cc79445 100644
--- a/log-client.c
+++ b/log-client.c
@@ -10,129 +10,54 @@ Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10Created: Mon Mar 20 21:13:40 1995 ylo 10Created: Mon Mar 20 21:13:40 1995 ylo
11 11
12Client-side versions of debug(), log(), etc. These print to stderr. 12Client-side versions of debug(), log(), etc. These print to stderr.
13This is a stripped down version of log-server.c.
13 14
14*/ 15*/
15 16
16#include "includes.h" 17#include "includes.h"
17RCSID("$Id: log-client.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); 18RCSID("$Id: log-client.c,v 1.2 1999/11/11 06:57:39 damien Exp $");
18 19
19#include "xmalloc.h" 20#include "xmalloc.h"
20#include "ssh.h" 21#include "ssh.h"
21 22
22static int log_debug = 0; 23static LogLevel log_level = SYSLOG_LEVEL_INFO;
23static int log_quiet = 0;
24 24
25void log_init(char *av0, int on_stderr, int debug, int quiet, 25/* Initialize the log.
26 SyslogFacility facility) 26 av0 program name (should be argv[0])
27{ 27 level logging level
28 log_debug = debug; 28 */
29 log_quiet = quiet;
30}
31
32void log(const char *fmt, ...)
33{
34 va_list args;
35
36 if (log_quiet)
37 return;
38 va_start(args, fmt);
39 vfprintf(stderr, fmt, args);
40 fprintf(stderr, "\r\n");
41 va_end(args);
42}
43
44void debug(const char *fmt, ...)
45{
46 va_list args;
47 if (log_quiet || !log_debug)
48 return;
49 va_start(args, fmt);
50 fprintf(stderr, "debug: ");
51 vfprintf(stderr, fmt, args);
52 fprintf(stderr, "\r\n");
53 va_end(args);
54}
55
56void error(const char *fmt, ...)
57{
58 va_list args;
59 if (log_quiet)
60 return;
61 va_start(args, fmt);
62 vfprintf(stderr, fmt, args);
63 fprintf(stderr, "\r\n");
64 va_end(args);
65}
66
67struct fatal_cleanup
68{
69 struct fatal_cleanup *next;
70 void (*proc)(void *);
71 void *context;
72};
73
74static struct fatal_cleanup *fatal_cleanups = NULL;
75
76/* Registers a cleanup function to be called by fatal() before exiting. */
77
78void fatal_add_cleanup(void (*proc)(void *), void *context)
79{
80 struct fatal_cleanup *cu;
81 29
82 cu = xmalloc(sizeof(*cu)); 30void
83 cu->proc = proc; 31log_init(char *av0, LogLevel level, SyslogFacility ignored1, int ignored2)
84 cu->context = context;
85 cu->next = fatal_cleanups;
86 fatal_cleanups = cu;
87}
88
89/* Removes a cleanup frunction to be called at fatal(). */
90
91void fatal_remove_cleanup(void (*proc)(void *context), void *context)
92{ 32{
93 struct fatal_cleanup **cup, *cu; 33 switch (level)
94
95 for (cup = &fatal_cleanups; *cup; cup = &cu->next)
96 { 34 {
97 cu = *cup; 35 case SYSLOG_LEVEL_QUIET:
98 if (cu->proc == proc && cu->context == context) 36 case SYSLOG_LEVEL_ERROR:
99 { 37 case SYSLOG_LEVEL_FATAL:
100 *cup = cu->next; 38 case SYSLOG_LEVEL_INFO:
101 xfree(cu); 39 case SYSLOG_LEVEL_CHAT:
102 return; 40 case SYSLOG_LEVEL_DEBUG:
103 } 41 log_level = level;
42 break;
43 default:
44 /* unchanged */
45 break;
104 } 46 }
105 fatal("fatal_remove_cleanup: no such cleanup function: 0x%lx 0x%lx\n",
106 (unsigned long)proc, (unsigned long)context);
107} 47}
108 48
109/* Function to display an error message and exit. This is in this file because 49#define MSGBUFSIZE 1024
110 this needs to restore terminal modes before exiting. See log-client.c
111 for other related functions. */
112 50
113void fatal(const char *fmt, ...) 51void
52do_log(LogLevel level, const char *fmt, va_list args)
114{ 53{
115 va_list args; 54 char msgbuf[MSGBUFSIZE];
116 struct fatal_cleanup *cu, *next_cu;
117 static int fatal_called = 0;
118
119 if (!fatal_called)
120 {
121 fatal_called = 1;
122 55
123 /* Call cleanup functions. */ 56 if (level > log_level)
124 for (cu = fatal_cleanups; cu; cu = next_cu) 57 return;
125 { 58 if (level == SYSLOG_LEVEL_DEBUG)
126 next_cu = cu->next; 59 fprintf(stderr, "debug: ");
127 (*cu->proc)(cu->context); 60 vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
128 } 61 fprintf(stderr, "%s", msgbuf);
129 }
130
131 va_start(args, fmt);
132 vfprintf(stderr, fmt, args);
133 fprintf(stderr, "\r\n"); 62 fprintf(stderr, "\r\n");
134 va_end(args);
135 exit(255);
136} 63}
137
138/* fatal() is in ssh.c so that it can properly reset terminal modes. */