Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 544440 - =sys-apps/portage-2.2.14 etc-update problem
Summary: =sys-apps/portage-2.2.14 etc-update problem
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Tools (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 611328
  Show dependency tree
 
Reported: 2015-03-25 10:09 UTC by Christian Roessner
Modified: 2017-05-20 17:55 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/usr/sbin/etc-update (etc-update_fix_merge.patch,416 bytes, patch)
2017-01-30 07:25 UTC, Christian Roessner
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Roessner 2015-03-25 10:09:15 UTC
Hi,

I use Gentoo for many, many years and I never reported the following bug, but today I have time :-)

If you use etc-update and have configured it to use an editor:

diff_command="vim -d %file1 %file2"
using_editor=1

etc-update will fail with option 5 (example config), if a previously created foo.dis_0000 exists.

The problem is the diff_command. I have extracted code fragments from etc-update to show the problem:

==========================================================
#!/bin/bash

diff_command="vim -d %file1 %file2"

diff_command() {
        local cmd=${diff_command//%file1/$1}
        ${cmd//%file2/$2}
}

do_distconf() {
        # search for any previously saved distribution config
        # files and number the current one accordingly

        local file=$1 ofile=$2
        local -i count
        local suffix
        local efile

        for (( count = 0; count <= 9999; ++count )) ; do
                suffix=$(printf ".dist_%04i" ${count})
                efile="${ofile}${suffix}"
                if [[ ! -f ${efile} ]] ; then
                        mv ${mv_opts} "${file}" "${efile}"
                        break
                elif diff_command "${file}" "${efile}" &> /dev/null; then
                        # replace identical copy
                        mv "${file}" "${efile}"
                        break
                fi
        done
}

do_distconf src dst

exit 0
==========================================================

So if you create a file named src like echo "123" > src and run the script twice, you will see the same problem that etc-update has with option 5.

The main bug is that the diff_command function does not honer "using_editor" and so it will deadlock. You need to background etc-update after this and kill it.

It would be nice to have a fix for this.

Reproducible: Always

Steps to Reproduce:
1. Install update of some package. For example postfix
2. Run etc-update
3. Choose option 5

This will create for example /etc/postfix/main.cf.dist_0000

Next time you do the same, etc-update will deadlock, if main.cf.dis_0000 exists.
Actual Results:  
Deadlock

Expected Results:  
Using command "diff" when using "using_editor" would fix the problem
Comment 1 Christian Roessner 2017-01-19 09:19:55 UTC
@Marc: Who could fix that?
Comment 2 Christian Roessner 2017-01-19 09:35:08 UTC
A fix should be easy (I guess), by replacing:

elif diff_command "${file}" "${efile}" &> /dev/null; then

with:

elif diff -uN "${file}" "${efile}" &> /dev/null; then
Comment 3 Christian Roessner 2017-01-30 07:25:04 UTC
Created attachment 461874 [details, diff]
/usr/sbin/etc-update

Could PLEASE someone commit this patch and respond to my very old bug report. It is really annoying now
Comment 4 Fabian Groffen gentoo-dev 2017-01-30 08:01:03 UTC
Indeed it seems like using diff_command here is wrong because it may be interactive.  Since options/flags can be passed to diff, it may be a bit tricky if the user specified -b or something, so I guess it should respect editor indeed.

Perhaps something like this?

--- /usr/sbin/etc-update        2015-10-07 23:49:58.000000000 +0200
+++ /var/tmp/etc-update 2017-01-30 09:00:16.386340335 +0100
@@ -649,10 +649,21 @@
                elif [[ -L ${efile} || -L ${file} ]] ; then
                        # not the same file types
                        continue
-               elif diff_command "${file}" "${efile}" &> /dev/null; then
-                       # replace identical copy
-                       mv "${file}" "${efile}"
-                       break
+               else
+                       local ret=
+                       if [[ ${using_editor} == 0 ]] ; then
+                               diff_command "${file}" "${efile}" &> /dev/null
+                               ret=$?
+                       else
+                               # fall back to plain diff
+                               diff -q "${file}" "${efile}" &> /dev/null
+                               ret=$?
+                       fi
+                       if [[ ${ret} == 0 ]] ; then
+                               # replace identical copy
+                               mv "${file}" "${efile}"
+                               break
+                       fi
                fi
        done
 }
Comment 5 Christian Roessner 2017-02-02 07:21:34 UTC
It is ok to just use "diff -uN" like in my patch, as it doesn't matter what the user specified in his configuration file. It is not interactive or something else :-) It only tries to figure out, if to *.dist_xxxx files are the same or not. And diff is always there, so the patch perfectly works.

Can you please accept it and use it :-)
Comment 6 Fabian Groffen gentoo-dev 2017-02-02 08:19:48 UTC
Why tell diff to produce unified diffs and treat non-existing files as empty ones if we just ensured both files exist?  It just results in more output that we're going to ignore, hence my switch to -q.
Comment 8 Christian Roessner 2017-03-03 08:27:19 UTC
(In reply to Zac Medico from comment #7)
> This is in the master branch:
> 
> https://gitweb.gentoo.org/proj/portage.git/commit/
> ?id=246373bbe52c55e912381d8555cceb70db0ec41b

Thanks :) Looking forward to see it in stable package :) Please leave me a note when it is available
Comment 9 Zac Medico gentoo-dev 2017-05-20 17:55:35 UTC
Fixed in portage-2.3.5.