[v2,4/4] image-postproc-extension: extract systemd's version using rootfs_cmd

Message ID 20250618135040.8252-5-cedric.hombourger@siemens.com
State Superseded, archived
Headers show
Series non-privileged commands in chroot | expand

Commit Message

Cedric Hombourger June 18, 2025, 1:50 p.m. UTC
Elevated privileges are not required to query the rootfs for the version
of systemd: replace "sudo chroot" with "rootfs_cmd"

Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
---
 meta/classes/image-postproc-extension.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Quirin Gylstorff June 20, 2025, 9:16 a.m. UTC | #1
On 6/18/25 15:50, 'Cedric Hombourger' via isar-users wrote:
> Elevated privileges are not required to query the rootfs for the version
> of systemd: replace "sudo chroot" with "rootfs_cmd"
> 
> Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
> ---
>   meta/classes/image-postproc-extension.bbclass | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
> index 0af588d8..21dcfccc 100644
> --- a/meta/classes/image-postproc-extension.bbclass
> +++ b/meta/classes/image-postproc-extension.bbclass
> @@ -55,7 +55,7 @@ image_postprocess_mark() {
>   
>   # Use dpkg to find out which version of systemd is installed into the image or reports "0"
>   image_systemd_version() {
> -    sudo chroot ${IMAGE_ROOTFS} dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0"
> +    rootfs_cmd ${IMAGE_ROOTFS} -- dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0"
>   }
Why are we not using the root parameter of dpkg-query for this?

Quirin
>   
>   ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_machine_id"
Jan Kiszka June 25, 2025, 7:46 p.m. UTC | #2
On 20.06.25 11:16, 'Quirin Gylstorff' via isar-users wrote:
> 
> 
> On 6/18/25 15:50, 'Cedric Hombourger' via isar-users wrote:
>> Elevated privileges are not required to query the rootfs for the version
>> of systemd: replace "sudo chroot" with "rootfs_cmd"
>>
>> Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
>> ---
>>   meta/classes/image-postproc-extension.bbclass | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/
>> classes/image-postproc-extension.bbclass
>> index 0af588d8..21dcfccc 100644
>> --- a/meta/classes/image-postproc-extension.bbclass
>> +++ b/meta/classes/image-postproc-extension.bbclass
>> @@ -55,7 +55,7 @@ image_postprocess_mark() {
>>     # Use dpkg to find out which version of systemd is installed into
>> the image or reports "0"
>>   image_systemd_version() {
>> -    sudo chroot ${IMAGE_ROOTFS} dpkg-query --
>> showformat='${source:Upstream-Version}' --show systemd || echo "0"
>> +    rootfs_cmd ${IMAGE_ROOTFS} -- dpkg-query --
>> showformat='${source:Upstream-Version}' --show systemd || echo "0"
>>   }
> Why are we not using the root parameter of dpkg-query for this?
> 

Pro: even faster than any wrapper
Con: brings some dependency between dpkg and data base versions

But this option should still be considered in the discussion, maybe also
depending on the type of access (read as above vs. write as in other cases).

Cedric, did you think about it?

Jan

Patch

diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
index 0af588d8..21dcfccc 100644
--- a/meta/classes/image-postproc-extension.bbclass
+++ b/meta/classes/image-postproc-extension.bbclass
@@ -55,7 +55,7 @@  image_postprocess_mark() {
 
 # Use dpkg to find out which version of systemd is installed into the image or reports "0"
 image_systemd_version() {
-    sudo chroot ${IMAGE_ROOTFS} dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0"
+    rootfs_cmd ${IMAGE_ROOTFS} -- dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0"
 }
 
 ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_machine_id"