diff mbox series

[3/3,meta-swupdate,v1,3/3] swupdate: Set service type to exec

Message ID 20220428121033.1609620-3-muhammad_hamza@mentor.com
State Accepted
Headers show
Series [1/3,meta-swupdate,v1,1/3] swupdate-usb: update service to use mount points dynamically | expand

Commit Message

Hamza, Muhammad April 28, 2022, 12:10 p.m. UTC
swupdate service launches a shell script which is responsible for
launcing swupdate core. Default service type considers that unit
is started right after main process is forked, and dependent services
can be launched right away, however it take some time for swupdate
core to initialize. This causes swupdate-client, launched by
swupdate-usb service, to end up in a race condition if swupdate-usb
service is launched right after swupdate service as service manager
considers that swupdate unit is fully running, whereas swupdate core
has not completely initialized yet. This results in immature launcing of
swupdate-client and it fails with "swupdate_async_start returns -1"
because host socket are not initialized yet in swupdate core for
the client to connect to.
When service type is set to "exec" service manager considers that a
service unit is started after the main process binary is executed
making sure that dependent services are not launched till core is
initialized. swupdate.sh uses exec to launch swupdate core this makes
sure that swupdate.sh is considered executed only once swupdate core
is running.
This commits sets service type to "exec" and makes use of the way
swupdate.sh executes swupdate core using exec command to make sure
that swupdate-client and core do not end up in race condition.

Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
---
 recipes-support/swupdate/swupdate/swupdate.service | 1 +
 1 file changed, 1 insertion(+)

Comments

Stefano Babic June 5, 2022, 4:15 p.m. UTC | #1
On 28.04.22 14:10, Muhammad Hamza wrote:
> swupdate service launches a shell script which is responsible for
> launcing swupdate core. Default service type considers that unit
> is started right after main process is forked, and dependent services
> can be launched right away, however it take some time for swupdate
> core to initialize. This causes swupdate-client, launched by
> swupdate-usb service, to end up in a race condition if swupdate-usb
> service is launched right after swupdate service as service manager
> considers that swupdate unit is fully running, whereas swupdate core
> has not completely initialized yet. This results in immature launcing of
> swupdate-client and it fails with "swupdate_async_start returns -1"
> because host socket are not initialized yet in swupdate core for
> the client to connect to.
> When service type is set to "exec" service manager considers that a
> service unit is started after the main process binary is executed
> making sure that dependent services are not launched till core is
> initialized. swupdate.sh uses exec to launch swupdate core this makes
> sure that swupdate.sh is considered executed only once swupdate core
> is running.
> This commits sets service type to "exec" and makes use of the way
> swupdate.sh executes swupdate core using exec command to make sure
> that swupdate-client and core do not end up in race condition.
> 
> Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
> ---
>   recipes-support/swupdate/swupdate/swupdate.service | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate/swupdate.service
> index 7f36619..c0253aa 100644
> --- a/recipes-support/swupdate/swupdate/swupdate.service
> +++ b/recipes-support/swupdate/swupdate/swupdate.service
> @@ -4,6 +4,7 @@ Documentation=https://github.com/sbabic/swupdate
>   Documentation=https://sbabic.github.io/swupdate
>   
>   [Service]
> +Type=exec
>   ExecStart=@LIBDIR@/swupdate/swupdate.sh
>   KillMode=mixed
>   

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
James Hilliard June 6, 2022, 1:53 a.m. UTC | #2
On Thu, Apr 28, 2022 at 6:11 AM Muhammad Hamza
<muhammad_hamza@mentor.com> wrote:
>
> swupdate service launches a shell script which is responsible for
> launcing swupdate core. Default service type considers that unit
> is started right after main process is forked, and dependent services
> can be launched right away, however it take some time for swupdate
> core to initialize. This causes swupdate-client, launched by
> swupdate-usb service, to end up in a race condition if swupdate-usb
> service is launched right after swupdate service as service manager
> considers that swupdate unit is fully running, whereas swupdate core
> has not completely initialized yet. This results in immature launcing of
> swupdate-client and it fails with "swupdate_async_start returns -1"
> because host socket are not initialized yet in swupdate core for
> the client to connect to.
> When service type is set to "exec" service manager considers that a
> service unit is started after the main process binary is executed
> making sure that dependent services are not launched till core is
> initialized. swupdate.sh uses exec to launch swupdate core this makes
> sure that swupdate.sh is considered executed only once swupdate core
> is running.
> This commits sets service type to "exec" and makes use of the way
> swupdate.sh executes swupdate core using exec command to make sure
> that swupdate-client and core do not end up in race condition.
>
> Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
> ---
>  recipes-support/swupdate/swupdate/swupdate.service | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate/swupdate.service
> index 7f36619..c0253aa 100644
> --- a/recipes-support/swupdate/swupdate/swupdate.service
> +++ b/recipes-support/swupdate/swupdate/swupdate.service
> @@ -4,6 +4,7 @@ Documentation=https://github.com/sbabic/swupdate
>  Documentation=https://sbabic.github.io/swupdate
>
>  [Service]
> +Type=exec
Should actually be this I think:
Type=notify

Since we implement notify support here:
https://github.com/sbabic/swupdate/blob/a10214e88eba43ae0382c84d9f0d10cf5d623e2a/core/swupdate.c#L927
>  ExecStart=@LIBDIR@/swupdate/swupdate.sh
>  KillMode=mixed
>
> --
> 2.25.1
>
> --
> You received this message because you are subscribed to the Google Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to swupdate+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/swupdate/20220428121033.1609620-3-muhammad_hamza%40mentor.com.
Stefano Babic June 6, 2022, 7:25 a.m. UTC | #3
Hi James,

On 06.06.22 03:53, James Hilliard wrote:
> On Thu, Apr 28, 2022 at 6:11 AM Muhammad Hamza
> <muhammad_hamza@mentor.com> wrote:
>>
>> swupdate service launches a shell script which is responsible for
>> launcing swupdate core. Default service type considers that unit
>> is started right after main process is forked, and dependent services
>> can be launched right away, however it take some time for swupdate
>> core to initialize. This causes swupdate-client, launched by
>> swupdate-usb service, to end up in a race condition if swupdate-usb
>> service is launched right after swupdate service as service manager
>> considers that swupdate unit is fully running, whereas swupdate core
>> has not completely initialized yet. This results in immature launcing of
>> swupdate-client and it fails with "swupdate_async_start returns -1"
>> because host socket are not initialized yet in swupdate core for
>> the client to connect to.
>> When service type is set to "exec" service manager considers that a
>> service unit is started after the main process binary is executed
>> making sure that dependent services are not launched till core is
>> initialized. swupdate.sh uses exec to launch swupdate core this makes
>> sure that swupdate.sh is considered executed only once swupdate core
>> is running.
>> This commits sets service type to "exec" and makes use of the way
>> swupdate.sh executes swupdate core using exec command to make sure
>> that swupdate-client and core do not end up in race condition.
>>
>> Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
>> ---
>>   recipes-support/swupdate/swupdate/swupdate.service | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate/swupdate.service
>> index 7f36619..c0253aa 100644
>> --- a/recipes-support/swupdate/swupdate/swupdate.service
>> +++ b/recipes-support/swupdate/swupdate/swupdate.service
>> @@ -4,6 +4,7 @@ Documentation=https://github.com/sbabic/swupdate
>>   Documentation=https://sbabic.github.io/swupdate
>>
>>   [Service]
>> +Type=exec
> Should actually be this I think:
> Type=notify
> 
> Since we implement notify support here:
> https://github.com/sbabic/swupdate/blob/a10214e88eba43ae0382c84d9f0d10cf5d623e2a/core/swupdate.c#L927

You're right - notify is the right type here. @Muhammad ?

Best regards,
Stefano

>>   ExecStart=@LIBDIR@/swupdate/swupdate.sh
>>   KillMode=mixed
>>
>> --
>> 2.25.1
>>
>> --
>> You received this message because you are subscribed to the Google Groups "swupdate" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to swupdate+unsubscribe@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/swupdate/20220428121033.1609620-3-muhammad_hamza%40mentor.com.
>
Hamza, Muhammad June 13, 2022, 7:31 a.m. UTC | #4
Hello,

Yes, you're right, I have been away for few days, will send updated patch soon.

Regards,
Hamza

-----Original Message-----
From: Stefano Babic <sbabic@denx.de> 
Sent: Monday, June 6, 2022 12:25 PM
To: James Hilliard <james.hilliard1@gmail.com>; Hamza, Muhammad <Muhammad_Hamza@mentor.com>
Cc: swupdate <swupdate@googlegroups.com>
Subject: Re: [swupdate] [PATCH 3/3] [meta-swupdate] [v1,3/3] swupdate: Set service type to exec

Hi James,

On 06.06.22 03:53, James Hilliard wrote:
> On Thu, Apr 28, 2022 at 6:11 AM Muhammad Hamza 
> <muhammad_hamza@mentor.com> wrote:
>>
>> swupdate service launches a shell script which is responsible for 
>> launcing swupdate core. Default service type considers that unit is 
>> started right after main process is forked, and dependent services 
>> can be launched right away, however it take some time for swupdate 
>> core to initialize. This causes swupdate-client, launched by 
>> swupdate-usb service, to end up in a race condition if swupdate-usb 
>> service is launched right after swupdate service as service manager 
>> considers that swupdate unit is fully running, whereas swupdate core 
>> has not completely initialized yet. This results in immature launcing 
>> of swupdate-client and it fails with "swupdate_async_start returns -1"
>> because host socket are not initialized yet in swupdate core for the 
>> client to connect to.
>> When service type is set to "exec" service manager considers that a 
>> service unit is started after the main process binary is executed 
>> making sure that dependent services are not launched till core is 
>> initialized. swupdate.sh uses exec to launch swupdate core this makes 
>> sure that swupdate.sh is considered executed only once swupdate core 
>> is running.
>> This commits sets service type to "exec" and makes use of the way 
>> swupdate.sh executes swupdate core using exec command to make sure 
>> that swupdate-client and core do not end up in race condition.
>>
>> Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
>> ---
>>   recipes-support/swupdate/swupdate/swupdate.service | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/recipes-support/swupdate/swupdate/swupdate.service 
>> b/recipes-support/swupdate/swupdate/swupdate.service
>> index 7f36619..c0253aa 100644
>> --- a/recipes-support/swupdate/swupdate/swupdate.service
>> +++ b/recipes-support/swupdate/swupdate/swupdate.service
>> @@ -4,6 +4,7 @@ Documentation=https://github.com/sbabic/swupdate
>>   Documentation=https://sbabic.github.io/swupdate
>>
>>   [Service]
>> +Type=exec
> Should actually be this I think:
> Type=notify
> 
> Since we implement notify support here:
> https://github.com/sbabic/swupdate/blob/a10214e88eba43ae0382c84d9f0d10
> cf5d623e2a/core/swupdate.c#L927

You're right - notify is the right type here. @Muhammad ?

Best regards,
Stefano

>>   ExecStart=@LIBDIR@/swupdate/swupdate.sh
>>   KillMode=mixed
>>
>> --
>> 2.25.1
>>
>> --
>> You received this message because you are subscribed to the Google Groups "swupdate" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to swupdate+unsubscribe@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/swupdate/20220428121033.1609620-3-muhammad_hamza%40mentor.com.
>
diff mbox series

Patch

diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate/swupdate.service
index 7f36619..c0253aa 100644
--- a/recipes-support/swupdate/swupdate/swupdate.service
+++ b/recipes-support/swupdate/swupdate/swupdate.service
@@ -4,6 +4,7 @@  Documentation=https://github.com/sbabic/swupdate
 Documentation=https://sbabic.github.io/swupdate
 
 [Service]
+Type=exec
 ExecStart=@LIBDIR@/swupdate/swupdate.sh
 KillMode=mixed