Petidomo needs to know the path to the executable in order to write

the ack-spool file, which starts Petidomo again to process the
acknowledged command or posting. I used BINDIR for that, but realized
that this sucks when somebody manually moves the binary. Hence, I am
using the contents of argv[0] now, normalized to an absolute path.
This value is stored in the global variable who_am_i, which the
queue_*() routines now use.
This commit is contained in:
Peter Simons 2001-01-19 12:49:44 +00:00
parent 60a0658b81
commit 1440285340
4 changed files with 24 additions and 2 deletions

21
main.c
View File

@ -24,6 +24,7 @@
#include <string.h>
#include "libargv/argv.h"
#include "libtext/text.h"
#include "petidomo.h"
#ifndef LOG_PERROR
@ -34,6 +35,7 @@ static char* listname = NULL;
static char* mode = NULL;
static char* masterconfig_path = SYSCONFDIR "/petidomo.conf";
char g_is_approved = ARGV_FALSE;
const char* who_am_i;
int
main(int argc, char * argv[])
@ -54,6 +56,25 @@ main(int argc, char * argv[])
openlog("petidomo", LOG_CONS | LOG_PID | LOG_PERROR, LOG_MAIL);
/* Store our full path and program name in who_am_I, so that
queue_posting() and queue_command() know where to find the
Petidomo binary. */
if (argv[0][0] == '/')
{
who_am_i = argv[0];
}
else
{
char buf[4096];
if (getcwd(buf, sizeof(buf)) == NULL)
{
syslog(LOG_CRIT, "Failed to get the path to my current working directory.");
exit(1);
}
who_am_i = text_easy_sprintf("%s/%s", buf, argv[0]);
}
/* Parse the command line. */
argv_help_string = "Petidomo Mailing List Server";

View File

@ -51,6 +51,7 @@
/********** main.c **********/
extern char g_is_approved;
extern const char* who_am_i;
/********** config.c **********/

View File

@ -39,7 +39,7 @@ char* queue_command(const struct Mail* mail, const char* command)
}
fprintf(fh, "#! /bin/sh\n");
fprintf(fh, "\n");
fprintf(fh, BINDIR "/petidomo --mode=listserv --approved <<[end-of-mail-marker]\n");
fprintf(fh, "%s --mode=listserv --approved <<[end-of-mail-marker]\n", who_am_i);
fprintf(fh, "Sender: %s\n", mail->Envelope);
fprintf(fh, "From: %s\n", mail->From);
if (mail->Reply_To)

View File

@ -39,7 +39,7 @@ char* queue_posting(const struct Mail* mail, const char* listname)
}
fprintf(fh, "#! /bin/sh\n");
fprintf(fh, "\n");
fprintf(fh, BINDIR "/petidomo --mode=deliver --listname=%s --approved <<[end-of-mail-marker]\n", listname);
fprintf(fh, "%s --mode=deliver --listname=%s --approved <<[end-of-mail-marker]\n", who_am_i, listname);
fprintf(fh, "%s\n", mail->Header);
fprintf(fh, "%s", mail->Body);
fprintf(fh, "[end-of-mail-marker]\n");