diff --git a/atd.c b/atd.c index 566d50a..cb22dd7 100644 --- a/atd.c +++ b/atd.c @@ -98,6 +98,10 @@ int selinux_enabled = 0; #define BATCH_INTERVAL_DEFAULT 60 #define CHECK_INTERVAL 3600 +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + /* Global variables */ uid_t real_uid, effective_uid; @@ -115,6 +119,7 @@ static time_t last_chg; static int nothing_to_do; unsigned int batch_interval; static int run_as_daemon = 0; +static int mail_with_hostname = 0; static volatile sig_atomic_t term_signal = 0; @@ -300,6 +305,7 @@ run_file(const char *filename, uid_t uid, gid_t gid) char fmt[64]; unsigned long jobno; int rc; + char hostbuf[MAXHOSTNAMELEN]; #ifdef WITH_PAM int retcode; #endif @@ -454,6 +460,11 @@ run_file(const char *filename, uid_t uid, gid_t gid) write_string(fd_out, "Subject: Output from your job "); write_string(fd_out, jobbuf); + if (mail_with_hostname > 0) { + gethostname(hostbuf, MAXHOSTNAMELEN-1); + write_string(fd_out, " "); + write_string(fd_out, hostbuf); + } write_string(fd_out, "\nTo: "); write_string(fd_out, mailname); write_string(fd_out, "\n\n"); @@ -855,7 +866,7 @@ main(int argc, char *argv[]) run_as_daemon = 1; batch_interval = BATCH_INTERVAL_DEFAULT; - while ((c = getopt(argc, argv, "sdl:b:f")) != EOF) { + while ((c = getopt(argc, argv, "sdnl:b:f")) != EOF) { switch (c) { case 'l': if (sscanf(optarg, "%lf", &load_avg) != 1) @@ -877,6 +888,10 @@ main(int argc, char *argv[]) daemon_foreground++; break; + case 'n': + mail_with_hostname=1; + break; + case 's': run_as_daemon = 0; break;