diff --git a/main.c b/main.c index e4af583..c7db77e 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,7 @@ #include #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"; diff --git a/petidomo.h b/petidomo.h index 1bf8a78..4aecb50 100644 --- a/petidomo.h +++ b/petidomo.h @@ -51,6 +51,7 @@ /********** main.c **********/ extern char g_is_approved; +extern const char* who_am_i; /********** config.c **********/ diff --git a/queue_command.c b/queue_command.c index 9b6d6ea..03ed624 100644 --- a/queue_command.c +++ b/queue_command.c @@ -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) diff --git a/queue_posting.c b/queue_posting.c index 5380988..5587d76 100644 --- a/queue_posting.c +++ b/queue_posting.c @@ -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");