creates motd.tail on postinst, which could mean duplicate entries in /etc/motd

Bug #634387 reported by Timo Aaltonen
154
This bug affects 31 people
Affects Status Importance Assigned to Milestone
sysvinit (Debian)
Unknown
Unknown
sysvinit (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

Binary package hint: sysvinit

Did an upgrade on a server (8.04 -> 10.04), and after a reboot & login noticed that motd had duplicate headers:

Linux fermaatti 2.6.32-24-generic #42-Ubuntu SMP Fri Aug 20 14:24:04 UTC 2010 i686 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to Ubuntu!
 * Documentation: https://help.ubuntu.com/

Ubuntu 10.04.1 LTS

Welcome to Ubuntu!
 * Documentation: https://help.ubuntu.com/
--

traced it down to the postinst files of base-files and iniscripts. First, base-files moved motd.tail as motd.tail.old, and later initscripts would create a new on by running 'sed 1d /etc/motd > /etc/motd.tail' (motd would by that time have been regenerated it seems). The result after a login is above.

I can't think of a reason why initscripts creates motd.tail in the first place. In ubuntu the file should be empty, or nonexistant...

Tags: patch
Revision history for this message
Timo Aaltonen (tjaalton) wrote :

oh and it still creates it in maverick.

Revision history for this message
Joost Ringoot (joost) wrote :

the bug came back in this weeks update of 10.04 LTS

Revision history for this message
Juliano Ravasi (jravasi) wrote :

So this explains the strange MOTD I'm receiving in my servers (10.04 LTS). MOTD shows two landscape reports, one new and one outdated. The outdated version was in /etc/motd.tail.

Timo Aaltonen (tjaalton)
Changed in sysvinit (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Gabriel Thörnblad (gabriel-thornblad) wrote :

Thanks for clearing this up! In my case the motd.tail on one of our servers contained the line "*** System restart required ***" which has probably made me restart that poor thing every time I logged on - for no reason...

Revision history for this message
Richard Whitehouse (richardwhiuk) wrote :

The antidote is fairly simple:

sudo rm /etc/motd.tail

Revision history for this message
Andrew Pollock (apollock) wrote :

Richard, yes, until the initscripts package gets updated again, then we're right back where we started.

Revision history for this message
Nathan Stratton Treadway (nathanst) wrote :

For what it's worth, here's the code from initscripts.postinst:
  if [ ! -f /etc/motd.tail ]
  then
          if [ -f /etc/motd ]
          then
                  sed 1d /etc/motd > /etc/motd.tail
                  [ -s /etc/motd.tail ] || rm -f /etc/motd.tail
          fi
  fi

The "[ ! -f /etc/motd.tail ]" at the front means the code only fires if /etc/motd.tail doesn't exist... and thus if leave an empty file there (rather than deleting it completely), that should prevent the motd->motd.tail copy from being performed on the next initscript upgrade.

Still, it definitely seems like a bug for the "motd" file that has just been generated by the /etc/updated-motd.d/ scripts to get copied into the "motd.tail" file during a package upgrade....

Looking back in the revision history of that script, it seems this code was added back in version 2.86.ds1-14.1ubuntu1 as part of the switch to a tmpfs /var/run directory:
  http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/lucid/sysvinit/lucid/revision/42/debian/initscripts/postinst?remember=42

Anyway, I wonder if this logic is still needed -- or, if so, if it could at least be protected by a "if dpkg --compare-versions" statement to make sure it only happens when it should?

(Or, at least, don't perform the copy if /etc/motd is already a symlink to /var/run/motd...)

Nathan

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

Looks like the code in sysvinit-2.87dsf/debian/initscripts.postinst that tries to preserve an existing motd by turning it into a motd.tail only makes sense if /etc/motd isn't already symlink to a generated file.

#
# Set up motd stuff, putting variable file in /var/run/
#
if [ ! -f /etc/motd.tail ]
then
        if [ -f /etc/motd ]
        then
                sed 1d /etc/motd > /etc/motd.tail
                [ -s /etc/motd.tail ] || rm -f /etc/motd.tail
        fi
fi

should be

#
# Set up motd stuff, putting variable file in /var/run/
#
if [ ! -f /etc/motd.tail ]
then
        if [ -f /etc/motd -a ! -L /etc/motd ]
        then
                sed 1d /etc/motd > /etc/motd.tail
                [ -s /etc/motd.tail ] || rm -f /etc/motd.tail
        fi
fi

The additional "-a ! -L /etc/motd" part would make the /etc/motd to /etc/motd.tail only happen if /etc/motd was not a symlink.

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

This is the update which broke it:

sysvinit (2.87dsf-4ubuntu17) lucid; urgency=low

  * debian/initscripts/etc/init.d/sendsigs: additional upstart jobs may be
    /started/ on shutdown after this script has first been invoked; so don't
    assume the list of known jobs is constant, instead requery initctl before
    each killall5 -CONT to properly exclude any new jobs upstart knows about
    so that we aren't waiting an extra 10 seconds for no reason.
    LP: #537262.

 -- Steve Langasek <email address hidden> Tue, 30 Mar 2010 00:08:33 -0700

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

Congratulation! /etc/motd.tail just got the contents of /etc/motd copied into again.

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

Now all the /etc/motd.tail files have been clobbered by overwriting them with garbage for the second time thats to this:

sysvinit (2.87dsf-4ubuntu17.3) lucid-proposed; urgency=low

  * debian/sysv-rc/sbin/invoke-rc.d: replace RUNLEVEL with RUNLEVELHELPER.
    Using RUNLEVEL causes spurious failures when invoke-rc.d is invoked
    with RUNLEVEL already defined in the environment (as it is e.g. during
    bootup) since invoke-rc.d's RUNLEVEL will become an exported variable
    at that point and cause /sbin/runlevel to return bad data. (LP: #619246)

 -- James Troup <email address hidden> Tue, 24 May 2011 11:41:45 +0000

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

This is supposedly an LTS platform but in the last month they copy garbage into /etc/motd.tail break cron daemon and copy garbage into /etc/motd.tail again. What sort of QA does Canonical do?

Revision history for this message
Barry Warsaw (barry) wrote :

Just to verify, this does not affect Oneiric, right?

Revision history for this message
Barry Warsaw (barry) wrote :

Well, a naive patch to fix this didn't go so well:

https://launchpad.net/~barry/+archive/experimental/+build/2550744/+files/buildlog_ubuntu-natty-i386.sysvinit_2.87dsf-4ubuntu17.4%7Eppa0_FAILEDTOBUILD.txt.gz

If someone else wants to work out a patch that actually builds, I'd be happy to sponsor it to natty-proposed.

Revision history for this message
nutznboltz (nutznboltz-deactivatedaccount) wrote :

One thing I just notice is that the server version of 10.04.4 LTS ISO installs update-motd package by default while the desktop 10.04.4 LTS ISO does not install that for you.

But it's still a bug in the initscripts package, it just requires other packages or the

sysvinit-2.87dsf/debian/initscripts.postinst

script will not have the contents of the packages that it damages installed.

If you are a desktop ubuntu user In order to experience this bug try installing a server ISO in a VM guest.

Revision history for this message
Barry Warsaw (barry) wrote :

I figured out my build problem above (pebkac). Here's a debdiff which should fix the problem. I'll get this into my PPA for testing and if it looks good I'll upload it to lucid-proposed.

~nutznboltz, I could only give you credit via your Launchpad URL, since there's no other personal information publicly available. If you want credit to go to your real name, please contact me before I upload it.

tags: added: patch
Revision history for this message
Brian Murray (brian-murray) wrote :

Barry bug 659738 has a Lucid task regarding this same issue.

Revision history for this message
Nathan Stratton Treadway (nathanst) wrote : Re: [Bug 634387] Re: creates motd.tail on postinst, which could mean duplicate entries in /etc/motd

On Mon, Jun 06, 2011 at 18:03:28 -0000, Barry Warsaw wrote:
> Just to verify, this does not affect Oneiric, right?

I don't have Oneiric installed anywhere, but looking
in in the latest version of the sysvinit.postinst
script (currently revision 14):
  http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/oneiric/sysvinit/oneiric/view/head:/debian/initscripts/postinst
, it doesn't appear that the copy-to-motd.tail logic
(line 259) is any different that the troublesome code
in the current Lucid version....

      Nathan

Revision history for this message
Nathan Stratton Treadway (nathanst) wrote :

On Wed, Jun 08, 2011 at 04:01:44 -0000, Nathan Stratton Treadway wrote:
> I don't have Oneiric installed anywhere, but looking
> in in the latest version of the sysvinit.postinst
> script (currently revision 14):

Actually, I was looking at revsion 114...

> http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/oneiric/sysvinit/oneiric/view/head:/debian/initscripts/postinst
> , it doesn't appear that the copy-to-motd.tail logic
> (line 259) is any different that the troublesome code
> in the current Lucid version....

... but then again, I see that that revision is dated 2009-06-25, so I
guess it's not actually the source code for the version that is
included in Oneric, anyway.

So... I downloaded the tar.gz file for sysvinit-2.87dsf-4ubuntu25, and can
confirm that the initscripts.postinst no longer creates the motd.tail
file.

       Nathan

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.