From 0f7b8812e0569cc69c377959c26300788e061451 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 3 Jun 2025 08:27:22 -0400 Subject: [PATCH] Able to start sender using execl --- app/sender.c | 2 -- lib/geseml.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/geseml.h | 5 +++- lib/subrou.c | 11 +++++-- lib/subrou.h | 3 -- lib/unieml.h | 3 ++ 6 files changed, 96 insertions(+), 11 deletions(-) diff --git a/app/sender.c b/app/sender.c index df72896..5f567e3 100644 --- a/app/sender.c +++ b/app/sender.c @@ -22,8 +22,6 @@ #include "unisig.h" #include "geseml.h" -#define SENDER "sender" //application name - /* */ diff --git a/lib/geseml.c b/lib/geseml.c index e30b1b6..29f4a26 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -6,11 +6,14 @@ /* */ /********************************************************/ #include +#include #include +#include #include #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; } /* @@ -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 +} diff --git a/lib/geseml.h b/lib/geseml.h index bb59902..ba68bf1 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -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 diff --git a/lib/subrou.c b/lib/subrou.c index 99b2c91..d97d181 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -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 diff --git a/lib/subrou.h b/lib/subrou.h index 9bf33fb..bba6e83 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -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); diff --git a/lib/unieml.h b/lib/unieml.h index 99bdd76..0794773 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -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 -- 2.47.3