From 97083caf5732669e17c46af3232a5568aee75ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Moj=C5=BE=C3=AD=C5=A1?= Date: Sun, 17 Dec 2023 17:23:35 +0100 Subject: [PATCH] log: add tracing level --- tinyssh/log.c | 5 +++- tinyssh/log.h | 53 +++++++++++++++++++++++++++++++++++++---- tinyssh/main_tinysshd.c | 3 +-- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/tinyssh/log.c b/tinyssh/log.c index c49ce5f..c75cb91 100644 --- a/tinyssh/log.c +++ b/tinyssh/log.c @@ -20,7 +20,7 @@ The 'log' library also supports syslog. static const char *logtext = "x"; static char logstring[9] = "________"; -static int loglevel = 1; +int loglevel = 1; static int logflagfnln = 1; static int logflagsyslog = 0; @@ -130,6 +130,9 @@ void log_9_( case 3: m = "debug"; break; + case 4: + m = "tracing"; + break; default: m = "unknown"; break; diff --git a/tinyssh/log.h b/tinyssh/log.h index a231d34..5d7ae13 100644 --- a/tinyssh/log.h +++ b/tinyssh/log.h @@ -4,6 +4,8 @@ extern void log_init(int, const char *, int, int); extern char *log_string(void); +extern int loglevel; + extern void log_9_( int, int, @@ -20,7 +22,12 @@ extern void log_9_( const char *); /* usage */ -#define log_u9(a,b,c,d,e,f,g,h,i) log_9_(0,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_u(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 0) break; \ + log_9_(0,1,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_u9(a,b,c,d,e,f,g,h,i) log_u(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) #define log_u8(a,b,c,d,e,f,g,h) log_u9(a,b,c,d,e,f,g,h,0) #define log_u7(a,b,c,d,e,f,g) log_u8(a,b,c,d,e,f,g,0) #define log_u6(a,b,c,d,e,f) log_u7(a,b,c,d,e,f,0) @@ -31,7 +38,12 @@ extern void log_9_( #define log_u1(a) log_u2(a,0) /* fatal */ -#define log_f9(a,b,c,d,e,f,g,h,i) log_9_(1,0,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_f(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 1) break; \ + log_9_(1,0,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_f9(a,b,c,d,e,f,g,h,i) log_f(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) #define log_f8(a,b,c,d,e,f,g,h) log_f9(a,b,c,d,e,f,g,h,0) #define log_f7(a,b,c,d,e,f,g) log_f8(a,b,c,d,e,f,g,0) #define log_f6(a,b,c,d,e,f) log_f7(a,b,c,d,e,f,0) @@ -42,7 +54,12 @@ extern void log_9_( #define log_f1(a) log_f2(a,0) /* warning */ -#define log_w9(a,b,c,d,e,f,g,h,i) log_9_(2,0,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_w(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 2) break; \ + log_9_(2,0,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_w9(a,b,c,d,e,f,g,h,i) log_w(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) #define log_w8(a,b,c,d,e,f,g,h) log_w9(a,b,c,d,e,f,g,h,0) #define log_w7(a,b,c,d,e,f,g) log_w8(a,b,c,d,e,f,g,0) #define log_w6(a,b,c,d,e,f) log_w7(a,b,c,d,e,f,0) @@ -53,7 +70,12 @@ extern void log_9_( #define log_w1(a) log_w2(a,0) /* info */ -#define log_i9(a,b,c,d,e,f,g,h,i) log_9_(2,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_i(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 2) break; \ + log_9_(2,1,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_i9(a,b,c,d,e,f,g,h,i) log_i(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) #define log_i8(a,b,c,d,e,f,g,h) log_i9(a,b,c,d,e,f,g,h,0) #define log_i7(a,b,c,d,e,f,g) log_i8(a,b,c,d,e,f,g,0) #define log_i6(a,b,c,d,e,f) log_i7(a,b,c,d,e,f,0) @@ -64,7 +86,12 @@ extern void log_9_( #define log_i1(a) log_i2(a,0) /* debug */ -#define log_d9(a,b,c,d,e,f,g,h,i) log_9_(3,1,__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_d(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 3) break; \ + log_9_(3,1,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_d9(a,b,c,d,e,f,g,h,i) log_d(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) #define log_d8(a,b,c,d,e,f,g,h) log_d9(a,b,c,d,e,f,g,h,0) #define log_d7(a,b,c,d,e,f,g) log_d8(a,b,c,d,e,f,g,0) #define log_d6(a,b,c,d,e,f) log_d7(a,b,c,d,e,f,0) @@ -74,4 +101,20 @@ extern void log_9_( #define log_d2(a,b) log_d3(a,b,0) #define log_d1(a) log_d2(a,0) +/* tracing */ +#define log_t(a,b,c,d,e,f,g,h,i,j,k) \ + do { \ + if (loglevel < 4) break; \ + log_9_(4,1,a,b,c,d,e,f,g,h,i,j,k); \ + } while (0) +#define log_t9(a,b,c,d,e,f,g,h,i) log_t(__FILE__,__LINE__,a,b,c,d,e,f,g,h,i) +#define log_t8(a,b,c,d,e,f,g,h) log_t9(a,b,c,d,e,f,g,h,0) +#define log_t7(a,b,c,d,e,f,g) log_t8(a,b,c,d,e,f,g,0) +#define log_t6(a,b,c,d,e,f) log_t7(a,b,c,d,e,f,0) +#define log_t5(a,b,c,d,e) log_t6(a,b,c,d,e,0) +#define log_t4(a,b,c,d) log_t5(a,b,c,d,0) +#define log_t3(a,b,c) log_t4(a,b,c,0) +#define log_t2(a,b) log_t3(a,b,0) +#define log_t1(a) log_t2(a,0) + #endif diff --git a/tinyssh/main_tinysshd.c b/tinyssh/main_tinysshd.c index af952b5..c02150f 100644 --- a/tinyssh/main_tinysshd.c +++ b/tinyssh/main_tinysshd.c @@ -89,7 +89,7 @@ int main_tinysshd(int argc, char **argv, const char *binaryname) { while (*++x) { if (*x == 'q') { flagverbose = 0; continue; } if (*x == 'Q') { flagverbose = 1; continue; } - if (*x == 'v') { if (flagverbose >= 2) flagverbose = 3; else flagverbose = 2; continue; } + if (*x == 'v') { ++flagverbose; if (flagverbose >= 4) flagverbose = 4; continue; } if (*x == 'o') { cryptotypeselected |= sshcrypto_TYPEOLDCRYPTO; continue; } if (*x == 'O') { cryptotypeselected &= ~sshcrypto_TYPEOLDCRYPTO; continue; } if (*x == 's') { cryptotypeselected |= sshcrypto_TYPENEWCRYPTO; continue; } @@ -218,7 +218,6 @@ int main_tinysshd(int argc, char **argv, const char *binaryname) { watchtochild = watchfromchild1 = watchfromchild2 = 0; watchselfpipe = 0; } - else { if (watch0) if (!watch0->revents) watch0 = 0; if (watch1) if (!watch1->revents) watch1 = 0;