]> SAFE projects GIT repository - jmp/mailleur/commitdiff
improving log_openlog (to use "execname")
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 27 Jun 2025 10:52:10 +0000 (06:52 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 27 Jun 2025 10:52:10 +0000 (06:52 -0400)
lib/devlog.c
lib/devlog.h
lib/lvleml.c
lib/subrou.c
lib/subrou.h
lib/unipar.c

index a85378fdcae19a7ba88bd8b8abb9d4f3118a91f2..cfd5e0bea43351926e0d9fc01e9b847dd6cd0bc4 100644 (file)
@@ -4,6 +4,7 @@
 /*     Log management implementation module            */
 /*                                                     */
 /********************************************************/
+#include        <linux/limits.h>
 #include        <sys/file.h>
 #include        <errno.h>
 #include        <malloc.h>
@@ -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) {
index 60c4524926778498312a66e634fdf686a2e71682..8230e302cc01b0bb6d9a6bdfc90e831253e9267e 100644 (file)
@@ -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);
index 3eb8366515002708042e2b7a85319976ac5bf781..86e25250829aedc73afcc62760e9b9f785764795 100644 (file)
@@ -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
index dd19f28abc1838e531dde0f404b83f1f2079857c..8e10678bff2c3b7c225efc440437661e40e7bccc 100644 (file)
@@ -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;
+}
+/*
 \f
 */
 /********************************************************/
index 89597981e9090443052448c4396aa88f42dffe18..6c6718b447cf59addd2c2fe8b5c365e570540edd 100644 (file)
@@ -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);
 
index 30e298ae71c1f46e5cb95398b71b6c900f53a5b7..6e7f14c8491a3ea790b4e03177640b36c9bdb090 100644 (file)
@@ -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) {