[Bug 259265] PERIODIC DAILY script errors (under certain circumstances)

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 19 Oct 2021 10:55:26 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=259265

            Bug ID: 259265
           Summary: PERIODIC DAILY script errors (under certain
                    circumstances)
           Product: Base System
           Version: 13.0-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: iandstanley@gmail.com

Created attachment 228831
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=228831&action=edit
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

-- 
You are receiving this mail because:
You are the assignee for the bug.