]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Able to start sender using execl
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 3 Jun 2025 12:27:22 +0000 (08:27 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 3 Jun 2025 12:27:22 +0000 (08:27 -0400)
app/sender.c
lib/geseml.c
lib/geseml.h
lib/subrou.c
lib/subrou.h
lib/unieml.h

index df72896a0b74e5eb87cd6214797f53552b5ee85b..5f567e314d2ead2351f54b6e6debf020181e0dd4 100644 (file)
@@ -22,8 +22,6 @@
 #include       "unisig.h"
 #include       "geseml.h"
 
-#define SENDER  "sender"        //application name
-
 /*
 \f
 */
index e30b1b6d29fac37e9d6a60594f1e76fe1be9f1e1..29f4a260de98b074d0791ffef7215e1167b2e1bc 100644 (file)
@@ -6,11 +6,14 @@
 /*                                                     */
 /********************************************************/
 #include        <dirent.h>
+#include        <errno.h>
 #include        <string.h>
+#include        <unistd.h>
 #include        <uuid/uuid.h>
 
 #include       "subrou.h"
 #include       "unieml.h"
+#include       "unipar.h"
 #include       "geseml.h"
 
 //dovecot local storage directory
@@ -120,10 +123,16 @@ return reflist;
 /*      Procedure to display/debug TRATYP record content*/
 /*                                                      */
 /********************************************************/
-PUBLIC void eml_dumptra(FILE *qfile,TRATYP **tra)
+PUBLIC _Bool eml_dumptra(FILE *qfile,TRATYP **tra)
 
 {
+_Bool action;
+
+action=false;
 if (tra!=(TRATYP **)0) {
+  time_t isnow;
+
+  isnow=time((time_t *)0);
   if (qfile!=(FILE *)0) {
     (void) fprintf(qfile,"#'C', completed email task\n");
     (void) fprintf(qfile,"#'L', Local email\n");
@@ -145,6 +154,8 @@ if (tra!=(TRATYP **)0) {
                                       (*tra)->mailfrom,
                                       (*tra)->rcptto
                                       );
+    if (((*tra)->date+(*tra)->delay)<=isnow)
+      action=true;
     if (qfile==(FILE *)0)  {
       (void) rou_alert(0,"TRA=<%s>",line);
       }
@@ -155,6 +166,7 @@ if (tra!=(TRATYP **)0) {
     tra++;
     }
   }
+return action;
 }
 /*
 \f
@@ -305,11 +317,15 @@ if (domlist!=(REFTYP **)0) {
   ptr=domlist;
   while (*ptr!=(REFTYP *)0) {
     FILE *qfile;
+    _Bool action;
+    const char *ext;
     char qname[150];
     int phase;
     _Bool proceed;
    
     qfile=(FILE *)0;
+    action=false;
+    ext=EXTRANS;
     (void) snprintf(qname,sizeof(qname),"%s-%s-%04d",(*ptr)->domain,buffer,iter);
     phase=0;
     proceed=true;
@@ -320,13 +336,19 @@ if (domlist!=(REFTYP **)0) {
             phase=999;  //Trouble trouble
           break;
         case 1  :       //dumping TRANS data to file
-          (void) eml_dumptra(qfile,(*ptr)->todo);
+          if ((action=eml_dumptra(qfile,(*ptr)->todo))==true)
+            ext=EXTODO;
           break;
         case 2  :       //Closing file
           (void) eml_closeqfile(qfile);
           break;
         case 3  :       //file ready, renaming file, 
-          (void) eml_renameqfile(qname,EXTOBE,EXTODO);
+          (void) eml_renameqfile(qname,EXTOBE,ext);          
+          break;
+        case 4  :       //do we need to start sender
+          if (action==true) {
+            (void) eml_start_sender(qname);
+            }
           break;
         default :       //SAFE Guard
           proceed=false;
@@ -536,3 +558,58 @@ if (tra!=(TRATYP *)0) {
   }
 return status;
 }
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to fork process and execute the       */
+/*      "sender" component.                             */
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool eml_start_sender(char *todo)
+
+{
+#define OPEP    "unieml.c:eml_start_sender,"
+
+_Bool status;
+
+status=false;
+switch (fork()) {
+  case -1       :       //trouble trouble
+    (void) rou_alert(0,"%s Unable to fork process (error=<%s> Bug?)",
+                        OPEP,strerror(errno));
+    break;
+  case 0        :       //the forked process
+    int exitval;
+    char *xx;
+    char *rootpath;
+    char *execpath;
+    char buffer[300];
+
+    exitval=0;
+    rootpath=(char *)0;
+    xx=(char *)0;
+    if (rootdir!=(char *)0) {
+      xx="-r";
+      rootpath=rootdir;
+      }
+    (void) snprintf(buffer,sizeof(buffer),"%s%s",SBINDIR,SENDER);        
+    execpath=rou_apppath(buffer);
+    (void) snprintf(buffer,sizeof(buffer),"%s.%s",todo,EXTODO);
+    (void) rou_alert(0,"%s JMPDBG starting sender=<%s> testing=<%s> todo= <%s>",OPEP,execpath,rootpath,buffer);
+    if (execl(execpath,"Bigre","-c",config,buffer,xx,rootpath,(char *)0)<0) {
+      (void) rou_alert(0,"%s Unable to exec process=<%s> (error=<%s> Bug?)",
+                        OPEP,execpath,strerror(errno));
+      exitval=-1;
+      }
+    (void) exit(exitval);
+    break;
+  default       :       //the forking process itself
+    (void) usleep(10000);       //relax delay
+    status=true;
+    break;
+  }
+return status;
+#undef   OPEP
+}
index bb599028630aaaf6b6f78f74a65bb0c54a168951..ba68bf1b3519f1721312db6bbe1dbc73274ab627 100644 (file)
@@ -24,7 +24,7 @@ typedef struct  {
         }TRATYP;
 
 //procedure to dump a transfert record (debug purpose)
-extern void eml_dumptra(FILE *out,TRATYP **tra);
+extern _Bool eml_dumptra(FILE *out,TRATYP **tra);
 
 //procedure to fee memory used by a TRATYP structure
 extern TRATYP *eml_freetra(TRATYP *tra);
@@ -47,4 +47,7 @@ extern _Bool eml_store_email(TRATYP *tra);
 //procedure to add execution delay to an email sending
 extern _Bool eml_add_delay(TRATYP *tra);
 
+//procedure to fork a process and start the "sender" process
+extern _Bool eml_start_sender(char *todo);
+
 #endif
index 99b2c9181a4addf41c787c614d7e2a11c571b3e9..d97d181f23f1f0c1b11b9d82fea4034d9e236b27 100644 (file)
@@ -600,6 +600,8 @@ if (doabort==true)
 PUBLIC void rou_loadconfig(char *conffile,_Bool load)
 
 {
+#define OPEP    "subrou.c:rou_loadconfig,"
+
 FILE *fichier;
 char line[200];
 char *name;
@@ -619,8 +621,12 @@ while (proceed==true) {
   switch (phase) {
     case 0      :       //Opening the config file
       if ((fichier=fopen(conffile,"r"))==(FILE *)0) {
-        (void) fprintf(stdout,"exiting!, Unable to open file <%s> (error=<%s>)\n",
-                              conffile,strerror(errno));
+        char cwd[PATH_MAX];
+
+        (void) getcwd(cwd, sizeof(cwd));
+        (void) fprintf(stdout,"%s exiting!, Unable to open file <%s> "
+                              "within <%s> (error=<%s>)\n",
+                              OPEP,conffile,cwd,strerror(errno));
         (void) exit(-1);//Big Trouble
         }
       break;
@@ -674,6 +680,7 @@ while (proceed==true) {
     }
   phase++;
   }
+#undef  OPEP
 }
 /*
 ^L
index 9bf33fb2127c707e583c415da9b953d3e7ade296..bba6e83ddaa15228dc0e72867d91137f6b79d7c8 100644 (file)
@@ -77,9 +77,6 @@ extern char *rou_setappname(const char *newname);
 //to compute an application path with the root directory
 extern char *rou_apppath(const char *path);
 
-//to compute an application path with the root directory
-extern char *rou_apppath(const char *path);
-
 //to display message on console (verbose mode) or
 //via syslog (LOG_INFO) using variable argument list macros
 void rou_valert(const int dlevel,const char *fmt,va_list ap);
index 99bdd76b61d09fe4ac89bb88ecaa1748e171987d..07947735db0802bb3ff3198b4115169c1b973ab5 100644 (file)
@@ -28,6 +28,9 @@
 #define EXDOING "doing"         //todo file in sending mode
 #define EXTRANS "trans"         //trans qfile extension
 
+#define SBINDIR "/usr/sbin/"    //appliaction installation directory
+#define SENDER  "sender"        //application email sender
+
 //list of keyword
 typedef enum    {               //list of SMTP protocol keyword
                 c_data,         //DATA email contents transfer request