diff mbox

[LEDE-DEV,odhcpd] dhcpv6-ia: Check lockf return value

Message ID 20170228055318.15460-1-f.fainelli@gmail.com
State Changes Requested
Delegated to: Mathias Kresin
Headers show

Commit Message

Florian Fainelli Feb. 28, 2017, 5:53 a.m. UTC
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 src/dhcpv6-ia.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Mathias Kresin Feb. 28, 2017, 11:48 a.m. UTC | #1
2017-02-28 6:53 GMT+01:00 Florian Fainelli <f.fainelli@gmail.com>:
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  src/dhcpv6-ia.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
> index 888634fe1f29..fb5044884441 100644
> --- a/src/dhcpv6-ia.c
> +++ b/src/dhcpv6-ia.c
> @@ -242,8 +242,12 @@ void dhcpv6_write_statefile(void)
>                 int fd = open(config.dhcp_statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
>                 if (fd < 0)
>                         return;
> -
> -               lockf(fd, F_LOCK, 0);
> +               int ret;
> +               ret = lockf(fd, F_LOCK, 0);
> +               if (ret < 0) {
> +                       close(fd);
> +                       return;
> +               }
>                 if (ftruncate(fd, 0) < 0) {}
>
>                 FILE *fp = fdopen(fd, "w");

Hey Florian,

would you please add a commit message which describes why this patch
is required, respectively what issue gets fixed with the patch.

I've added Hans to CC since he is the one working on odhcpd work at the moment.

Mathias
Florian Fainelli March 1, 2017, 5:48 a.m. UTC | #2
On 02/28/2017 03:48 AM, Mathias Kresin wrote:
> 2017-02-28 6:53 GMT+01:00 Florian Fainelli <f.fainelli@gmail.com>:
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>>  src/dhcpv6-ia.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
>> index 888634fe1f29..fb5044884441 100644
>> --- a/src/dhcpv6-ia.c
>> +++ b/src/dhcpv6-ia.c
>> @@ -242,8 +242,12 @@ void dhcpv6_write_statefile(void)
>>                 int fd = open(config.dhcp_statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
>>                 if (fd < 0)
>>                         return;
>> -
>> -               lockf(fd, F_LOCK, 0);
>> +               int ret;
>> +               ret = lockf(fd, F_LOCK, 0);
>> +               if (ret < 0) {
>> +                       close(fd);
>> +                       return;
>> +               }
>>                 if (ftruncate(fd, 0) < 0) {}
>>
>>                 FILE *fp = fdopen(fd, "w");
> 
> Hey Florian,
> 
> would you please add a commit message which describes why this patch
> is required, respectively what issue gets fixed with the patch.
> 
> I've added Hans to CC since he is the one working on odhcpd work at the moment.

Sure, I just submitted a v2, thanks!
diff mbox

Patch

diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c
index 888634fe1f29..fb5044884441 100644
--- a/src/dhcpv6-ia.c
+++ b/src/dhcpv6-ia.c
@@ -242,8 +242,12 @@  void dhcpv6_write_statefile(void)
 		int fd = open(config.dhcp_statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
 		if (fd < 0)
 			return;
-
-		lockf(fd, F_LOCK, 0);
+		int ret;
+		ret = lockf(fd, F_LOCK, 0);
+		if (ret < 0) {
+			close(fd);
+			return;
+		}
 		if (ftruncate(fd, 0) < 0) {}
 
 		FILE *fp = fdopen(fd, "w");