anacron: read SENDMAIL variable from anacrontab#135
anacron: read SENDMAIL variable from anacrontab#135corvus1 wants to merge 4 commits intocronie-crond:masterfrom
Conversation
Use alternative mailer command
But has all sorts of issues. execl() is acting weird when "" is passed as parameters. And I think I reached the extent of my C programming capabilities. For some bizarre reason I can't even if (string == NULL) anymore. Please help!
|
See the latest commit message. This thing is taking a toll on me. It's getting bad. Like really bad. I'd greatly appreciate if somebody, who knows C at least a little bit, could take a look at this mess I am about to make. |
|
This isn't just ugly, this is desperate. Please send help. :'-( |
| 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.
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. SENDMAILARG1 SENDMAILARG2 SENDMAILARG3....
There was a problem hiding this comment.
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.
SENDMAILARG1SENDMAILARG2SENDMAILARG3....
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.
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 ", ' as quotes and then you also need to somehow support escaping these quote characters, etc.
There was a problem hiding this comment.
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
",'as quotes and then you also need to somehow support escaping these quote characters, etc.
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 "/usr/bin/logger -t anacronmai" by a single character, everything breaks and I get some other string there. As if something overlapped in memory.
| mailer_full = getenv("SENDMAIL"); | ||
|
|
||
| if (mailer_full == NULL) { | ||
| /* Here, I basically mirrored the way /usr/sbin/sendmail is called |
There was a problem hiding this comment.
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.
Here I wouldn't duplicate the execl call but instead assign SENDMAIL to mailer_full if it is NULL.
I don't know how to do it, without making it into a special case. We need to pass these arguments to sendmail.
Use alternative mailer command.
As briefly discussed in #133 the change looks for SENDMAIL environment variable, and if it is set, uses it as an alternative mailer. It strips the command line arguments from the execl() call, and lets the mailer sort out the standard input. Perhaps it's not ideal, but I'd like to hear some comments.
For my personal use-case,
loggervery easily takes the standard input and sends it into syslog, eliminating any need for local mail setup. Which was my goal to begin with. :-) Full disclosure.Another possible issue is that you can't specify command line parameters for the alternative mailer, it has to be just a path to the binary.