1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-01-19 12:02:52 +00:00

Rename Log_[{Init|Exit}_]Resolver to Log_[{Init|Exit}_]Subprocess

Rename Log_Init_Resolver, Log_Exit_Resolver, and Log_Resolver to
Log_Init_Subprocess, Log_Exit_Subprocess, and Log_Subprocess and
make it more generic thereby.
This commit is contained in:
Alexander Barton 2010-07-01 00:34:56 +02:00
parent 5462c6c50f
commit 0db9a31e50
3 changed files with 51 additions and 44 deletions

View File

@ -264,64 +264,65 @@ va_dcl
GLOBAL void GLOBAL void
Log_Init_Resolver( void ) Log_Init_Subprocess(char *Name)
{ {
#ifdef SYSLOG #ifdef SYSLOG
openlog( PACKAGE_NAME, LOG_CONS|LOG_PID, LOG_LOCAL5 ); openlog( PACKAGE_NAME, LOG_CONS|LOG_PID, LOG_LOCAL5 );
#endif #endif
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Resolver sub-process starting, PID %ld.", (long)getpid()); Log_Subprocess(LOG_DEBUG, "%s sub-process starting, PID %ld.",
Name, (long)getpid());
#endif #endif
} /* Log_Init_Resolver */ }
GLOBAL void GLOBAL void
Log_Exit_Resolver( void ) Log_Exit_Subprocess(char *Name)
{ {
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Resolver sub-process %ld done.", (long)getpid()); Log_Subprocess(LOG_DEBUG, "%s sub-process %ld done.",
Name, (long)getpid());
#endif #endif
#ifdef SYSLOG #ifdef SYSLOG
closelog( ); closelog( );
#endif #endif
} /* Log_Exit_Resolver */ }
#ifdef PROTOTYPES #ifdef PROTOTYPES
GLOBAL void GLOBAL void
Log_Resolver( const int Level, const char *Format, ... ) Log_Subprocess(const int Level, const char *Format, ...)
#else #else
GLOBAL void GLOBAL void
Log_Resolver( Level, Format, va_alist ) Log_Subprocess(Level, Format, va_alist)
const int Level; const int Level;
const char *Format; const char *Format;
va_dcl va_dcl
#endif #endif
{ {
/* Eintrag des Resolver in Logfile(s) schreiben */
char msg[MAX_LOG_MSG_LEN]; char msg[MAX_LOG_MSG_LEN];
va_list ap; va_list ap;
assert( Format != NULL ); assert(Format != NULL);
#ifdef DEBUG #ifdef DEBUG
if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return; if ((Level == LOG_DEBUG) && (!NGIRCd_Debug))
return;
#else #else
if( Level == LOG_DEBUG ) return; if (Level == LOG_DEBUG)
return;
#endif #endif
/* String mit variablen Argumenten zusammenbauen ... */
#ifdef PROTOTYPES #ifdef PROTOTYPES
va_start( ap, Format ); va_start(ap, Format);
#else #else
va_start( ap ); va_start(ap);
#endif #endif
vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap ); vsnprintf(msg, MAX_LOG_MSG_LEN, Format, ap);
va_end( ap ); va_end(ap);
Log_Message(Level, msg); Log_Message(Level, msg);
} /* Log_Resolver */ }
/** /**

View File

@ -46,10 +46,10 @@ GLOBAL void LogDebug PARAMS(( const char *Format, ... ));
static inline void LogDebug PARAMS(( UNUSED const char *Format, ... )){/* Do nothing. The compiler should optimize this out, please ;-) */} static inline void LogDebug PARAMS(( UNUSED const char *Format, ... )){/* Do nothing. The compiler should optimize this out, please ;-) */}
#endif #endif
GLOBAL void Log_Init_Resolver PARAMS(( void )); GLOBAL void Log_Init_Subprocess PARAMS((char *Name));
GLOBAL void Log_Exit_Resolver PARAMS(( void )); GLOBAL void Log_Exit_Subprocess PARAMS((char *Name));
GLOBAL void Log_Resolver PARAMS(( const int Level, const char *Format, ... )); GLOBAL void Log_Subprocess PARAMS((const int Level, const char *Format, ...));
#ifdef DEBUG #ifdef DEBUG
GLOBAL void Log_InitErrorfile PARAMS(( void )); GLOBAL void Log_InitErrorfile PARAMS(( void ));

View File

@ -72,7 +72,7 @@ Resolve_Addr(PROC_STAT * s, const ng_ipaddr_t *Addr, int identsock,
/* Sub process */ /* Sub process */
Init_Subprocess(); Init_Subprocess();
Do_ResolveAddr( Addr, identsock, pipefd[1]); Do_ResolveAddr( Addr, identsock, pipefd[1]);
Log_Exit_Resolver( ); Log_Exit_Subprocess("Resolver");
exit(0); exit(0);
} }
return false; return false;
@ -101,7 +101,7 @@ Resolve_Name( PROC_STAT *s, const char *Host, void (*cbfunc)(int, short))
/* Sub process */ /* Sub process */
Init_Subprocess(); Init_Subprocess();
Do_ResolveName(Host, pipefd[1]); Do_ResolveName(Host, pipefd[1]);
Log_Exit_Resolver( ); Log_Exit_Subprocess("Resolver");
exit(0); exit(0);
} }
return false; return false;
@ -117,7 +117,7 @@ Signal_Handler(int Signal)
switch(Signal) { switch(Signal) {
case SIGTERM: case SIGTERM:
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Resolver: Got TERM signal, exiting."); Log_Subprocess(LOG_DEBUG, "Resolver: Got TERM signal, exiting.");
#endif #endif
exit(1); exit(1);
} }
@ -131,7 +131,7 @@ static void
Init_Subprocess(void) Init_Subprocess(void)
{ {
signal(SIGTERM, Signal_Handler); signal(SIGTERM, Signal_Handler);
Log_Init_Resolver(); Log_Init_Subprocess("Resolver");
} }
@ -168,17 +168,20 @@ Do_IdentQuery(int identsock, array *resolved_addr)
return; return;
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Doing IDENT lookup on socket %d ...", identsock); Log_Subprocess(LOG_DEBUG, "Doing IDENT lookup on socket %d ...",
identsock);
#endif #endif
res = ident_id( identsock, 10 ); res = ident_id( identsock, 10 );
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Ok, IDENT lookup on socket %d done: \"%s\"", Log_Subprocess(LOG_DEBUG, "Ok, IDENT lookup on socket %d done: \"%s\"",
identsock, res ? res : "(NULL)" ); identsock, res ? res : "(NULL)");
#endif #endif
if (!res) /* no result */ if (!res) /* no result */
return; return;
if (!array_cats(resolved_addr, res)) if (!array_cats(resolved_addr, res))
Log_Resolver(LOG_WARNING, "Resolver: Cannot copy IDENT result: %s!", strerror(errno)); Log_Subprocess(LOG_WARNING,
"Resolver: Cannot copy IDENT result: %s!",
strerror(errno));
free(res); free(res);
#else #else
@ -240,7 +243,7 @@ ReverseLookup(const ng_ipaddr_t *IpAddr, char *resbuf, size_t reslen)
assert(reslen >= NG_INET_ADDRSTRLEN); assert(reslen >= NG_INET_ADDRSTRLEN);
ng_ipaddr_tostr_r(IpAddr, tmp_ip_str); ng_ipaddr_tostr_r(IpAddr, tmp_ip_str);
Log_Resolver(LOG_WARNING, "%s: Can't resolve address \"%s\": %s", Log_Subprocess(LOG_WARNING, "%s: Can't resolve address \"%s\": %s",
funcname, tmp_ip_str, errmsg); funcname, tmp_ip_str, errmsg);
strlcpy(resbuf, tmp_ip_str, reslen); strlcpy(resbuf, tmp_ip_str, reslen);
return false; return false;
@ -288,10 +291,10 @@ ForwardLookup(const char *hostname, array *IpAddr)
switch (res) { switch (res) {
case 0: break; case 0: break;
case EAI_SYSTEM: case EAI_SYSTEM:
Log_Resolver(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, strerror(errno)); Log_Subprocess(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, strerror(errno));
return false; return false;
default: default:
Log_Resolver(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, gai_strerror(res)); Log_Subprocess(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, gai_strerror(res));
return false; return false;
} }
@ -314,9 +317,10 @@ ForwardLookup(const char *hostname, array *IpAddr)
if (!h) { if (!h) {
#ifdef h_errno #ifdef h_errno
Log_Resolver(LOG_WARNING, "Can't resolve \"%s\": %s", hostname, Get_Error(h_errno)); Log_Subprocess(LOG_WARNING, "Can't resolve \"%s\": %s",
hostname, Get_Error(h_errno));
#else #else
Log_Resolver(LOG_WARNING, "Can't resolve \"%s\"", hostname); Log_Subprocess(LOG_WARNING, "Can't resolve \"%s\"", hostname);
#endif #endif
return false; return false;
} }
@ -352,7 +356,7 @@ Addr_in_list(const array *resolved_addr, const ng_ipaddr_t *Addr)
tmpAddrs = array_start(resolved_addr); tmpAddrs = array_start(resolved_addr);
while (len > 0) { while (len > 0) {
Log_Resolver(LOG_WARNING, "Address mismatch: %s != %s", Log_Subprocess(LOG_WARNING, "Address mismatch: %s != %s",
tmp_ip_str, ng_ipaddr_tostr(tmpAddrs)); tmp_ip_str, ng_ipaddr_tostr(tmpAddrs));
tmpAddrs++; tmpAddrs++;
len--; len--;
@ -365,14 +369,14 @@ Addr_in_list(const array *resolved_addr, const ng_ipaddr_t *Addr)
static void static void
Log_Forgery_NoIP(const char *ip, const char *host) Log_Forgery_NoIP(const char *ip, const char *host)
{ {
Log_Resolver(LOG_WARNING, "Possible forgery: %s resolved to %s " Log_Subprocess(LOG_WARNING, "Possible forgery: %s resolved to %s "
"(which has no ip address)", ip, host); "(which has no ip address)", ip, host);
} }
static void static void
Log_Forgery_WrongIP(const char *ip, const char *host) Log_Forgery_WrongIP(const char *ip, const char *host)
{ {
Log_Resolver(LOG_WARNING,"Possible forgery: %s resolved to %s " Log_Subprocess(LOG_WARNING,"Possible forgery: %s resolved to %s "
"(which points to different address)", ip, host); "(which points to different address)", ip, host);
} }
@ -386,7 +390,7 @@ ArrayWrite(int fd, const array *a)
assert(data); assert(data);
if( (size_t)write(fd, data, len) != len ) if( (size_t)write(fd, data, len) != len )
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", Log_Subprocess( LOG_CRIT, "Resolver: Can't write to parent: %s!",
strerror(errno)); strerror(errno));
} }
@ -404,7 +408,7 @@ Do_ResolveAddr(const ng_ipaddr_t *Addr, int identsock, int w_fd)
array_init(&resolved_addr); array_init(&resolved_addr);
ng_ipaddr_tostr_r(Addr, tmp_ip_str); ng_ipaddr_tostr_r(Addr, tmp_ip_str);
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Now resolving %s ...", tmp_ip_str); Log_Subprocess(LOG_DEBUG, "Now resolving %s ...", tmp_ip_str);
#endif #endif
if (!ReverseLookup(Addr, hostname, sizeof(hostname))) if (!ReverseLookup(Addr, hostname, sizeof(hostname)))
goto dns_done; goto dns_done;
@ -419,13 +423,15 @@ Do_ResolveAddr(const ng_ipaddr_t *Addr, int identsock, int w_fd)
strlcpy(hostname, tmp_ip_str, sizeof(hostname)); strlcpy(hostname, tmp_ip_str, sizeof(hostname));
} }
#ifdef DEBUG #ifdef DEBUG
Log_Resolver(LOG_DEBUG, "Ok, translated %s to \"%s\".", tmp_ip_str, hostname); Log_Subprocess(LOG_DEBUG, "Ok, translated %s to \"%s\".", tmp_ip_str, hostname);
#endif #endif
dns_done: dns_done:
len = strlen(hostname); len = strlen(hostname);
hostname[len] = '\n'; hostname[len] = '\n';
if (!array_copyb(&resolved_addr, hostname, ++len)) { if (!array_copyb(&resolved_addr, hostname, ++len)) {
Log_Resolver(LOG_CRIT, "Resolver: Can't copy resolved name: %s!", strerror(errno)); Log_Subprocess(LOG_CRIT,
"Resolver: Can't copy resolved name: %s!",
strerror(errno));
array_free(&resolved_addr); array_free(&resolved_addr);
return; return;
} }
@ -448,7 +454,7 @@ Do_ResolveName( const char *Host, int w_fd )
ng_ipaddr_t *addr; ng_ipaddr_t *addr;
size_t len; size_t len;
#endif #endif
Log_Resolver(LOG_DEBUG, "Now resolving \"%s\" ...", Host); Log_Subprocess(LOG_DEBUG, "Now resolving \"%s\" ...", Host);
array_init(&IpAddrs); array_init(&IpAddrs);
/* Resolve hostname */ /* Resolve hostname */
@ -462,7 +468,7 @@ Do_ResolveName( const char *Host, int w_fd )
addr = array_start(&IpAddrs); addr = array_start(&IpAddrs);
assert(addr); assert(addr);
for (; len > 0; --len,addr++) { for (; len > 0; --len,addr++) {
Log_Resolver(LOG_DEBUG, "translated \"%s\" to %s.", Log_Subprocess(LOG_DEBUG, "translated \"%s\" to %s.",
Host, ng_ipaddr_tostr(addr)); Host, ng_ipaddr_tostr(addr));
} }
#endif #endif