dash inability - cron starts binary with /bin/sh

Bug #1337576 reported by bugproxy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
Expired
Low
Unassigned

Bug Description

-- Problem Description --
CRON uses shell to start a binary executable defined in crontab, which is a waste of the resources for the extra shell process hanging in the system. It's supposed to run it directly with exec system call.

*** Here are some command outputs to see the extra process(12327) and relevant information: ***
# ps -ef | grep -e CRON -e PMLnx
root 12326 771 0 13:59 ? 00:00:00 CRON
root 12327 12326 0 13:59 ? 00:00:00 /bin/sh -c /var/perf/pm/bin/daemon_PMLnx <--- extra layer, a waste
root 12328 12327 0 13:59 ? 00:00:00 /var/perf/pm/bin/daemon_PMLnx

# crontab -l
59 * * * * /var/perf/pm/bin/daemon_PMLnx

# file /var/perf/pm/bin/daemon_PMLnx
/var/perf/pm/bin/daemon_PMLnx: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=1761d6d97eabb4e52870cb517fe6bf457e5bf89e, stripped

# uname -a
Linux ubuntu 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:09:21 UTC 2014 ppc64le ppc64le ppc64le GNU/Linux

# dpkg -l cron
    Name Version Architecture Description
+++-=====-==================-=============-=========================
ii cron 3.0pl1-124ubuntu2 ppc64el process scheduling daemon

*** Expect cron to directly execute a binary like this ***
# ps -ef | grep -e CRON -e PMLnx
root 2293 2223 0 09:59 ? 00:00:00 /usr/sbin/CRON -n
root 2294 2293 0 09:59 ? 00:00:00 /var/perf/pm/bin/daemon_PMLnx

# uname -a
Linux hulala 3.12.15-3-default #1 SMP Wed Apr 2 17:08:55 UTC 2014 (69c2ea8) ppc64le ppc64le ppc64le GNU/Linux

# cat /etc/SuSE-release
SUSE Linux Enterprise Server 12 (ppc64le)
VERSION = 12
PATCHLEVEL = 0

bugproxy (bugproxy)
tags: added: architecture-ppc64le bugnameltc-112970 severity-normal
Luciano Chavez (lnx1138)
affects: ubuntu → cron (Ubuntu)
bugproxy (bugproxy)
tags: added: severity-medium targetmilestone-inin1410
removed: severity-normal
Revision history for this message
Christian Kastner (ckk) wrote :
Changed in cron (Ubuntu):
status: New → Invalid
Revision history for this message
bugproxy (bugproxy) wrote : Comment bridged from LTC Bugzilla

------- Comment From <email address hidden> 2014-10-20 16:04 EDT-------
(In reply to comment #8)
> This is mandated by POSIX, see
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html

Further research explores the problem with shell link:
root@ucrypt:/# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Sep 16 10:54 /bin/sh -> dash

In other words, it is dash (a slim shell to provide faster boot times) that can not execute a binary command to override itself.

You may see the different behaviors of dash vs bash:
root@ucrypt:/# /bin/dash -c cat
... ...
root@ucrypt:~# ps -ef | grep cat # at another terminal
root 6611 6462 0 15:45 pts/0 00:00:00 /bin/dash -c cat
root 6612 6611 0 15:45 pts/0 00:00:00 cat

root@ucrypt:/# /bin/bash -c cat
... ...
root@ucrypt:/# ps -ef | grep cat # at another terminal
root 6615 6462 0 15:47 pts/0 00:00:00 cat

Liangchang Guo (vcd0a5)
Changed in cron (Ubuntu):
status: Invalid → New
summary: - cron starts binary with /bin/sh
+ dash inability - cron start binary with /bin/sh
Liangchang Guo (vcd0a5)
summary: - dash inability - cron start binary with /bin/sh
+ dash inability - cron starts binary with /bin/sh
Revision history for this message
Christian Kastner (ckk) wrote :

Perhaps I should have been more clearer: the POSIX standard mandates that the command field (that's everything in the sixth column of a crontab file) be passed as arguments to /bin/sh:

  | The sixth field of a line in a crontab entry is a string
  | that shall be executed by sh at the specified times.

Therefore, this cannot be changed.

Furthermore, exec'ing the command directly would severely break existing crontabs. Take the following entry for example, which utilizes output redirection:

  15 * * * * df -h > $HOME/disk.log

As you correctly identified, /bin/sh points to /bin/dash. But you can point that to any other Bourne-compatible shell, eg bash, if you want.

Changed in cron (Ubuntu):
status: New → Invalid
Revision history for this message
Liangchang Guo (vcd0a5) wrote :

(In reply to comment #3)
Perhaps I should have been more clearer: This turns out to be a dash defect.

Changed in cron (Ubuntu):
status: Invalid → New
Revision history for this message
Christian Kastner (ckk) wrote :

Re-assigning to dash then.

affects: cron (Ubuntu) → dash (Ubuntu)
bugproxy (bugproxy)
tags: added: targetmilestone-inin---
removed: targetmilestone-inin1410
Revision history for this message
bugproxy (bugproxy) wrote :

------- Comment From <email address hidden> 2015-02-02 13:30 EDT-------
Hi,

Do we have any updates on this? Do you need more information from us?

Thanks!

Revision history for this message
bugproxy (bugproxy) wrote :

------- Comment From <email address hidden> 2016-01-13 09:53 EDT-------
(In reply to comment #18)
It is a /bin/dash defect affecting all Ubuntu releases, and still remains everywhere:
root@Ubuntu1604:~# ps -ef | grep cat
root 1553 1527 0 08:45 tty1 00:00:00 /bin/dash -c cat
root 1554 1553 0 08:45 tty1 00:00:00 cat

Luciano Chavez (lnx1138)
Changed in dash (Ubuntu):
assignee: nobody → Taco Screen team (taco-screen-team)
bugproxy (bugproxy)
tags: added: targetmilestone-inin1604
removed: targetmilestone-inin---
Steve Langasek (vorlon)
Changed in dash (Ubuntu):
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Steve Langasek (vorlon) wrote :

It seems reasonable to want the shell to exec the command passed as a -c argument after evaluating it, instead of forking. However, I don't see anything in POSIX that defines that the shell must do this (http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html). For such a small optimization (the dash shell has been picked precisely because it is very lightweight compared with bash, so stray shell processes for the lifetime of a running cronjob have negligible performance impact on the system), we would not want to carry a delta in Ubuntu. Please discuss with dash upstream (namely, the Debian maintainer).

Revision history for this message
Manoj Iyer (manjo) wrote :

Based on Steve's comment #8, this issue needs to worked with the upstream dash. Marking this as incomplete and removing taco screen team as the owner.

Changed in dash (Ubuntu):
assignee: Taco Screen team (taco-screen-team) → nobody
status: Triaged → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for dash (Ubuntu) because there has been no activity for 60 days.]

Changed in dash (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.