[Qemu-devel] [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp

Lin Ma posted 1 patch 7 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170213095148.25500-1-lma@suse.com
Test checkpatch passed
Test docker passed
Test s390x passed
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp
Posted by Lin Ma 7 years, 2 months ago
By commit 67a1de0d, When we perform 'git pull && make && sudo make install',
In 'make' stage a qemu-version.h.tmp will be generated. If the content of
qemu-version.h.tmp and qemu-version.h aren't consistent, The qemu-version.h.tmp
will be renamed to qemu-version.h. Because of the target FORCE, The same action
will be do again in 'make install' stage.

In 'make install' stage, If there is no qemu-version.h.tmp exists and we run
'make install' with sudo, The owner and group of new qemu-version.h.tmp will be
privileged user/group. When we run 'make' next time, qemu-version.h.tmp can't
be overwritten because of permission issue.

This patch uses 'cp' instead of 'mv' to keep the qemu-version.h.tmp file, So
during the 'sudo make install' stage, new qemu-version.h.tmp's owner and group
wont be set to privileged user/group.

Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 1a8bfb2..1ca45b2 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ qemu-version.h: FORCE
 				printf '""\n'; \
 			fi; \
 		fi) > $@.tmp)
-	$(call quiet-command, cmp -s $@ $@.tmp || mv $@.tmp $@)
+	$(call quiet-command, cmp -s $@ $@.tmp || cp $@.tmp $@)
 
 config-host.h: config-host.h-timestamp
 config-host.h-timestamp: config-host.mak
-- 
2.9.2


Re: [Qemu-devel] [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp
Posted by Paolo Bonzini 7 years, 2 months ago

On 13/02/2017 10:51, Lin Ma wrote:
> By commit 67a1de0d, When we perform 'git pull && make && sudo make install',
> In 'make' stage a qemu-version.h.tmp will be generated. If the content of
> qemu-version.h.tmp and qemu-version.h aren't consistent, The qemu-version.h.tmp
> will be renamed to qemu-version.h. Because of the target FORCE, The same action
> will be do again in 'make install' stage.

But why does the content of .h and .h.tmp not match during "make install"?

Paolo

> diff --git a/Makefile b/Makefile
> index 1a8bfb2..1ca45b2 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -184,7 +184,7 @@ qemu-version.h: FORCE
>  				printf '""\n'; \
>  			fi; \
>  		fi) > $@.tmp)
> -	$(call quiet-command, cmp -s $@ $@.tmp || mv $@.tmp $@)
> +	$(call quiet-command, cmp -s $@ $@.tmp || cp $@.tmp $@)

[Qemu-devel] 答复: Re: [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp
Posted by Lin Ma 7 years, 2 months ago

>>> Paolo Bonzini <pbonzini@redhat.com> 2017/2/13 星期一 下午 6:07 >>>
>
>
>On 13/02/2017 10:51, Lin Ma wrote:
>> By commit 67a1de0d, When we perform 'git pull && make && sudo make install',
>> In 'make' stage a qemu-version.h.tmp will be generated. If the content of
>> qemu-version.h.tmp and qemu-version.h aren't consistent, The qemu-version.h.tmp
>> will be renamed to qemu-version.h. Because of the target FORCE, The same action
>> will be do again in 'make install' stage.
>
>But why does the content of .h and .h.tmp not match during "make install"?
The content of qemu-version.h recorded the git head info of last build.
After 'git pull && make ', Because the content of qemu-version.h.tmp is generated
based on the lastest git describe, Now this .h.tmp and the old .h aren't consistent,
So this .h.tmp will be renamed to qemu-version.h.
Then during 'sudo make install', because there is no .h.tmp any more, a new one will be
generated with privileged permissions.

Thanks,
Lin
Re: [Qemu-devel]答复: Re: [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp
Posted by Paolo Bonzini 7 years, 2 months ago

On 13/02/2017 12:53, Lin Ma wrote:
> 
> The content of qemu-version.h recorded the git head info of last build.
> After 'git pull && make ', Because the content of qemu-version.h.tmp is
> generated
> based on the lastest git describe, Now this .h.tmp and the old .h aren't
> consistent,
> So this .h.tmp will be renamed to qemu-version.h.
> Then during 'sudo make install', because there is no .h.tmp any more, a
> new one will be
> generated with privileged permissions.

So is the bug that the "cmp || mv" should be changed to "if cmp ...;
then mv ...; else rm ..."?

Paolo

Re: [Qemu-devel]答复: Re: [PATCH v2 RESEND] Makefile: Fix owner and group for qemu-version.h.tmp
Posted by Lin Ma 7 years, 2 months ago

>>> Paolo Bonzini <pbonzini@redhat.com> 2017/2/13 星期一 下午 7:55 >>>
>
>
>On 13/02/2017 12:53, Lin Ma wrote:
>> 
>> The content of qemu-version.h recorded the git head info of last build.
>> After 'git pull && make ', Because the content of qemu-version.h.tmp is
>> generated
>> based on the lastest git describe, Now this .h.tmp and the old .h aren't
>> consistent,
>> So this .h.tmp will be renamed to qemu-version.h.
>> Then during 'sudo make install', because there is no .h.tmp any more, a
>> new one will be
>> generated with privileged permissions.
>
>So is the bug that the "cmp || mv" should be changed to "if cmp ...;
>then mv ...; else rm ..."?
Yes, It makes sense, and this way can avoid leaving the qemu-version.h.tmp in
the folder after build. I'll send patch v3 based on it and the patch title will be
changed to 'avoid leaving the temporary QEMU_PKGVERSION header file'.
 
Thanks,
Lin