-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anacron: read SENDMAIL variable from anacrontab #135
base: master
Are you sure you want to change the base?
Changes from all commits
02fbcf2
dff6a11
e72488b
c06a13d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
|
||
#include <langinfo.h> | ||
|
||
#include "matchrx.h" | ||
|
||
static int | ||
temp_file(job_rec *jr) | ||
/* Open a temporary file and return its file descriptor */ | ||
|
@@ -207,6 +209,11 @@ xwait(pid_t pid , int *status) | |
static void | ||
launch_mailer(job_rec *jr) | ||
{ | ||
int r; | ||
char *mailer; | ||
char *mailer_args; | ||
char *mailer_full; | ||
|
||
pid_t pid; | ||
struct stat buf; | ||
|
||
|
@@ -247,13 +254,38 @@ launch_mailer(job_rec *jr) | |
/* fdflags = fcntl(0, F_GETFL); fdflags &= ~O_APPEND; */ | ||
/* fcntl(0, F_SETFL, fdflags ); */ | ||
|
||
/* Here, I basically mirrored the way /usr/sbin/sendmail is called | ||
* by cron on a Debian system, except for the "-oem" and "-or0s" | ||
* options, which don't seem to be appropriate here. | ||
* Hopefully, this will keep all the MTAs happy. */ | ||
execl(SENDMAIL, SENDMAIL, "-FAnacron", "-odi", | ||
jr->mailto, (char *)NULL); | ||
die_e("Can't exec " SENDMAIL); | ||
/* Get SENDMAIL variable from the environment if set. | ||
/* If not, will use the predefined SENDMAIL from global.h */ | ||
mailer_full = getenv("SENDMAIL"); | ||
|
||
if (mailer_full == NULL) { | ||
/* Here, I basically mirrored the way /usr/sbin/sendmail is called | ||
* by cron on a Debian system, except for the "-oem" and "-or0s" | ||
* options, which don't seem to be appropriate here. | ||
* Hopefully, this will keep all the MTAs happy. */ | ||
execl(SENDMAIL, SENDMAIL, "-FAnacron", "-odi", | ||
jr->mailto, (char *)NULL); | ||
die_e("Can't exec " SENDMAIL); | ||
} else { | ||
|
||
/* Splitting into binary path and command line parameters*/ | ||
|
||
complain("mailer_full - `%s`", mailer_full); | ||
|
||
strcat(mailer_full," "); | ||
r = match_rx("(^[^ ]*) (.*)", mailer_full, 2, &mailer, &mailer_args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this is more complicated as for executing the mailer via execl the arguments would have to be split. Or perhaps better would be to just allow a few mailer arguments in separate environment variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is that... even acceptable to shift the task of separating arguments to the user? I mean... that's kinda rude even for me. Is that okay? I mean... it turns out, it's incredibly hard to separate arguments in C. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a problem to properly separate the arguments in C because you'd basically have to re-implement the shell argument separator parser to make it really useful. I.e. you'd have to support at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought I'd just go for something simple, rudimentary even. Look for " -" and split on that. Maybe even with a regex in a loop. There is something going on there, though. If SENDMAIL variable is longer than |
||
|
||
complain("mailer - `%s` ", mailer); | ||
complain("mailer_args - `%s`", mailer_args); | ||
|
||
if ( strchr(mailer_args, '-') != NULL ) { | ||
execl(mailer, mailer, mailer_args, (char *)NULL); | ||
} else { | ||
execl(mailer, mailer, (char *)NULL); | ||
} | ||
|
||
die_e("Can't exec the mailer %s", mailer); | ||
} | ||
} | ||
/* parent */ | ||
/* record mailer pid */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I wouldn't duplicate the execl call but instead assign SENDMAIL to mailer_full if it is NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to do it, without making it into a special case. We need to pass these arguments to sendmail.