Subject: at: Read MAILTO environment variable to determine recipient for standard out/err Package: at Version: 3.1.10.2-0js Severity: wishlist Tags: patch
Hi, it would be nice if one could more dynamically adjust the mail adress standard out and err are sent to. I've attached a little patch that gives the MAILTO environment variable preference to all other name sources. I don't know if I had better included an extra commandline option for that purpose, but this way it's simpler and perhaps there are some scripts which make use of this variable anyway (as in crontab, but perhaps it is overkill to use at and cron together [-; ) and it better fits in the way at receives its mailnames (LOGNAME, utmp). -- System Information: Debian Release: 5.0.5 APT prefers stable APT policy: (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 2.6.26-2-amd64 (SMP w/2 CPU cores) Locale: LANG=C, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages at depends on: ii exim4 4.69-9 metapackage to ease Exim MTA (v4) ii exim4-daemon-light [mail- 4.69-9 lightweight Exim MTA (v4) daemon ii libc6 2.7-18lenny4 GNU C Library: Shared libraries ii libpam0g 1.0.1-5+lenny1 Pluggable Authentication Modules l ii lsb-base 3.2-20 Linux Standard Base 3.2 init scrip at recommends no packages. at suggests no packages. -- no debconf information
diff -r -u ../at-3.1.12/at.c ./at.c --- ../at-3.1.12/at.c 2010-08-26 16:12:11.000000000 +0200 +++ ./at.c 2010-08-26 15:48:48.000000000 +0200 @@ -355,6 +355,12 @@ /* Get the userid to mail to, first by trying getlogin(), which reads * /var/run/utmp, then from LOGNAME, finally from getpwuid(). */ + + /* New Feature: MAILTO overrides everything */ + mailname = getenv("MAILTO"); + if (mailname != NULL) + goto dontbother; + mailname = getlogin(); if (mailname == NULL) mailname = getenv("LOGNAME"); @@ -364,6 +370,7 @@ mailname = pass_entry->pw_name; } +dontbother: if ((mailname == NULL) || (mailname[0] == '\0') || (strlen(mailname) > mailsize) ) { panic("Cannot find username to mail output to"); @@ -374,6 +381,7 @@ perr("Cannot open input file %.500s", atinput); } + fprintf(stderr, "Mail will be sent to %s\n", mailname); fprintf(fp, "#!/bin/sh\n# atrun uid=%d gid=%d\n# mail %s %d\n", real_uid, real_gid, mailname, send_mail);