Bug 259265 - PERIODIC DAILY script errors (under certain circumstances)
Summary: PERIODIC DAILY script errors (under certain circumstances)
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: Peter Wemm
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-19 10:55 UTC by Ian
Modified: 2021-12-21 02:59 UTC (History)
1 user (show)

See Also:


Attachments
patched version of periodic with correct path (4.20 KB, application/x-shellscript)
2021-10-19 10:55 UTC, Ian
no flags Details
patch for path of mail (173 bytes, patch)
2021-10-19 10:57 UTC, Ian
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian 2021-10-19 10:55:26 UTC
Created attachment 228831 [details]
patched version of periodic with correct path

ENVIRONMENT
"""""""""""

- Running FreeBSD 13.0

uname -a 
FreeBSD frodo 13.0-RELEASE FreeBSD 13.0-RELEASE #0 releng/13.0-n244733-ea31abc261f: Fri Apr  9 04:24:09 UTC 2021     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64

- GNU mailutils installed (either explicitly or as in my case as a by-product of installing another tool).


PERIODIC DAILY SCRIPT
"""""""""""""""""""""

I am using the unmodified daily script shipped with 13.0-release


HISTORY
"""""""

Something I noticed recently that my periodic daily script wasn't running properly as I was getting mail complaining about the -s flag.

It was working after original install but now complains despite not touching the script.



REPRODUCING
"""""""""""

1. Install Freebsd 13.0-release
2. Check periodic daily can be run with 'sudo periodic daily'
3. Install emacs with 'sudo pkg install emacs-nox'
4. Check periodic daily can be run with 'sudo periodic daily'

Example test run: 

ian@frodo:/etc $ sudo periodic daily
Password:
mail: Unknown command: -s

This works without error if you pkg remove emacs-nox, change the path to use /usr/bin before /usr/local/bin or as I noticed it I switched to csh which I have a different path order in $PATH


DIAGNOSIS
"""""""""

The 'bug' [not really a bug but more of an oversight] is that GNU mail from mailutils doesn't like the -s flag in line 24

I think this is because GNU mail is interpreting the -E flag differently.

Some may argue that /usr/local/bin should come after /usr/bin but there are valid reasons for a user to place /usr/local/bin prior to /usr/bin in their path (eg deliberately overriding the internal tools). 

It is better to be explicit where there is a chance of both BSD and GNU tools being installed particularly when using switches that aren't cross compatible


SOLUTION
""""""""

give the full path to the BSD mail tool so that the user's environment doesn't override and mess up the script.

As emacs-nox installs the gnu mailtutils with GNU's own mail util it will depend on the user's environment variable as to which mail tool is run.

Using the full path (patch below) will ensure that FreeBSD uses it's own tool and prevents GNU from messing up the system.


PATCH
"""""

root@frodo:/usr/sbin # diff -u periodic periodic_fixed
--- periodic    2021-10-19 11:15:24.731207000 +0100
+++ periodic_fixed      2021-10-19 11:15:18.282797000 +0100
@@ -21,7 +21,7 @@
     case "$output" in
     /*) pipe="cat >>$output";;
     "") pipe=cat;;
-    *)  pipe="mail -E -s '$host ${2}${2:+ }${1##*/} run output' $output";;
+    *)  pipe="/usr/bin/mail -E -s '$host ${2}${2:+ }${1##*/} run output' $output";;
     esac
     eval $pipe
 }

thanks
Comment 1 Ian 2021-10-19 10:57:59 UTC
Created attachment 228832 [details]
patch for path of mail
Comment 2 commit-hook freebsd_committer freebsd_triage 2021-12-21 02:59:09 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=81a48881c63149e5fc104e158ed3d71a2ec659a7

commit 81a48881c63149e5fc104e158ed3d71a2ec659a7
Author:     Peter Wemm <peter@FreeBSD.org>
AuthorDate: 2021-12-21 01:08:04 +0000
Commit:     Peter Wemm <peter@FreeBSD.org>
CommitDate: 2021-12-21 02:54:56 +0000

    periodic: Use a deterministic $PATH for periodic.

    Various tools can have alternate versions elsewhere, eg: the GNU
    mailutils port (a dependency of emacs*) brings /usr/local/bin/mail.
    Match the preset PATH in /etc/crontab for deterministic path searches
    even when run manually with a different environment.

    PR:             259265
    Reported by:    iandstanley@gmail.com

 usr.sbin/periodic/periodic.sh | 4 ++++
 1 file changed, 4 insertions(+)