From: Jean-Marc Pigeon (Delson) Date: Fri, 27 Jun 2025 10:52:10 +0000 (-0400) Subject: improving log_openlog (to use "execname") X-Git-Tag: tag-0.11~39 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=f575c15a261317eb1fb300ca898db7d7605228de;p=jmp%2Fmailleur improving log_openlog (to use "execname") --- diff --git a/lib/devlog.c b/lib/devlog.c index a85378f..cfd5e0b 100644 --- a/lib/devlog.c +++ b/lib/devlog.c @@ -4,6 +4,7 @@ /* Log management implementation module */ /* */ /********************************************************/ +#include #include #include #include @@ -17,9 +18,6 @@ #include "devlog.h" #define JRLDIR "/var/spool/"APPNAME -#define IJRLDIR JRLDIR"/receiver-logs/" -#define OJRLDIR JRLDIR"/sender-logs/" - typedef struct { char *filename; //the log filename @@ -162,20 +160,18 @@ return status; /* return a NULL file pointeur if trouble. */ /* */ /********************************************************/ -PUBLIC LOGPTR *log_openlog(char *logname,_Bool inlog,const char *cmt) +PUBLIC LOGPTR *log_openlog(char *logname,const char *cmt) { #define OPEP "devlog.c:log_openlog" LOGTYP *log; -const char *logdir; +char logdir[PATH_MAX]; int phase; int proceed; log=(LOGTYP *)0; -logdir=OJRLDIR; -if (inlog==true) - logdir=IJRLDIR; +(void) snprintf(logdir,sizeof(logdir),"%s/%s-logs/",JRLDIR,execname); phase=0; proceed=true; while (proceed==true) { diff --git a/lib/devlog.h b/lib/devlog.h index 60c4524..8230e30 100644 --- a/lib/devlog.h +++ b/lib/devlog.h @@ -13,7 +13,7 @@ typedef void LOGPTR; //procedure to open a session log -extern LOGPTR *log_openlog(char *logname,_Bool inlog,const char *cmt); +extern LOGPTR *log_openlog(char *logname,const char *cmt); //procedure to close a previously open session log extern LOGPTR *log_closelog(LOGPTR *logptr); diff --git a/lib/lvleml.c b/lib/lvleml.c index 3eb8366..86e2525 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1663,7 +1663,7 @@ while (proceed==true) { } contact->peername=soc_getaddrinfo(contact->socptr,false,true); contact->peerip=soc_getaddrinfo(contact->socptr,false,false); - contact->logptr=log_openlog(contact->mainsesid,true,(const char *)0); + contact->logptr=log_openlog(contact->mainsesid,(const char *)0); contact->localafn=afn_getipnum(contact->locip); (void) rou_alert(0,"Contact from peer <%s> to port <%s> started", contact->peerip,contact->locserv); @@ -1873,7 +1873,7 @@ while (proceed==true) { if (ptr!=(char *)0) *ptr='\000'; (void) snprintf(cmt,sizeof(cmt),"main-session-id=%s",mainsesid); - logptr=log_openlog(mainsesid,false,cmt); + logptr=log_openlog(mainsesid,cmt); mainsesid=rou_freestr(mainsesid); break; case 3 : //sending all email within transaction diff --git a/lib/subrou.c b/lib/subrou.c index dd19f28..8e10678 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -28,6 +28,9 @@ PUBLIC _Bool foreground=false; //process is always started in background mode PUBLIC char *rootdir=(char *)0;//working directory (debugging) PUBLIC char *appname; //application "official" name +//application binary name +PUBLIC char execname[20]=APPNAME; + //static variables static _Bool modopen; //boolean module open/close @@ -495,6 +498,22 @@ if (newname!=(char *)0) { return name; } /* +^L +*/ +/********************************************************/ +/* */ +/* Returne set a new exec/binary name. */ +/* logs. */ +/* */ +/********************************************************/ +PUBLIC const char *rou_setexecname(const char *newexecname) + +{ +(void) memset(execname,'\000',sizeof(execname)); +(void) strncpy(execname,newexecname,sizeof(execname)-1); +return execname; +} +/* */ /********************************************************/ diff --git a/lib/subrou.h b/lib/subrou.h index 8959798..6c6718b 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -34,6 +34,7 @@ extern _Bool foreground; //process is in foreground mode extern char *rootdir; //application root directory extern char *appname; //application "official" name +extern char execname[]; ///Application exec/binary name //--- Routines implemented within subrou.c --------- @@ -85,6 +86,9 @@ extern void **rou_freelist(void **list,genfree_t handler); //change the application name extern char *rou_setappname(const char *newname); +//change the execname name +extern const char *rou_setexecname(const char *newexecname); + //to compute an application path with the root directory extern char *rou_apppath(const char *path); diff --git a/lib/unipar.c b/lib/unipar.c index 30e298a..6e7f14c 100644 --- a/lib/unipar.c +++ b/lib/unipar.c @@ -145,6 +145,7 @@ if ((shortname=strrchr(argv[0],'/'))==(char *)0) shortname=argv[0]; else shortname++; +(void) rou_setexecname(shortname); opterr=0; //no error message from getopt library routine while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) { switch(c) {