Non-existent log files cannot be chown'ed

Bug #290127 reported by clearblueskies
6
Affects Status Importance Assigned to Milestone
sysklogd (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: sysklogd

Ubuntu Hardy Heron
sysklogd 1.5-1ubuntu1

Use case: I am using a laptop on which I do not want to save the logs from the last session, so I delete them every time powering down. However, when booting the next time the console is cluttered with error messages because of line 74 of /etc/init.d/sysklogd which reads:
"chown ${USER}:adm $l"

Perhaps this could be surrounded with a file existence test?
if [ -e $l ]; then
    chown ${USER}:adm $l
fi

This check would eliminate error messages from cluttering the console on boot.

Thank you.

Revision history for this message
clearblueskies (temporary130) wrote :

Or maybe the intention of the script is to set the user:group, in which case a new empty file should be created if it doesn't exist already.

touch $l
chown ${USER}:adm $l

Revision history for this message
Russell Phillips (ignissport) wrote :

I have a similar setup, except I have an SSD so I've got /var/log mounted on tmpfs. The directory needs to start afresh on each boot. This is a common trick for people who need to reduce the write count on their EeePC or Aspire One.

Here's a method which will touch the required logfiles (including the 'news' directory), and also create the directory for the logfile if it does not already exist. This allows the entire log directory to be rebuilt on boot, regardless of what paths are specified in /etc/syslog.conf:

fix_log_ownership()
{
        for l in `syslogd-listfiles -a --news`
        do
                # Create directory for logfile if required
                ldir=$(echo ${l} | sed 's/[^\/]*$//g')
                if [ ! -e $ldir ] ; then
                        mkdir -p $ldir
                fi
                # Touch logfile and chown
                touch $l && chown ${USER}:adm $l
        done
}

Revision history for this message
clearblueskies (temporary130) wrote :

Hi Russell, thanks for this info, it is immediately helpful as a work-around. I stumbled across this problem because I'm using an SSD as well. A related bug for sysvinit is at https://bugs.launchpad.net/ubuntu/+source/sysvinit/+bug/290429

I hope these changes can make it into the standard distribution since they wouldn't negatively effect anyone else and would be a plus for SSD users.

Revision history for this message
clearblueskies (temporary130) wrote :

Also affects Intrepid Ibex.

Revision history for this message
Tormod Volden (tormodvolden) wrote :

The easy way to silence it would be to use chmod --quiet (or -f).

As I commented in bug #285530, better yet would be to make sure this "repair" chmod is not needed by creating the files correct from the start. Also, syslogd could create missing directories itself when it creates the files. Or ignore files for which there is no existing directory. This would need write permissions for the syslogd process in /var/log though.

Revision history for this message
Tormod Volden (tormodvolden) wrote :

I meant "chown --quiet" of course.

Now, for permissions, AFAICS syslogd starts up and creates the files as root, so that should not be a problem. According to the man page, it only needs write access as "syslog" user if it is HUP restarted, in which case it runs the same code but under another uid. Nice.

The "syslog" user is not in the "adm" group, and at the moment I am not sure why those files must be "syslog:adm". Furthermore, the files are created root:adm in the postinst.

I would suggest:
1) Create /var/log/news in the init file and not in the postinst. This is the only subdir sysklog uses itself.
2) Fix syslogd to set file owner on file creation.
3) Remove file creation and chown from init file and postinst.

Regarding (2) the current code just opens the file for append, so it does not change the owner of an existing file. If we want to preserve this behaviour, we'll need know if the file is newly created before chown'ing it. If not, this debdiff is one simple way of doing it. This is just a first take for the discussion, it adds -U and -G options that will chown all files opened to the uid/gid of the process.

Revision history for this message
Tormod Volden (tormodvolden) wrote :

sysklogd has been replaced by rsyslog in Karmic, so I guess this bug will be a wontfix.

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.