dhcpv6-ia: Check lockf return value
authorFlorian Fainelli <f.fainelli@gmail.com>
Wed, 1 Mar 2017 05:48:29 +0000 (21:48 -0800)
committerHans Dedecker <dedeckeh@gmail.com>
Sat, 4 Mar 2017 20:27:01 +0000 (21:27 +0100)
Check the lockf return value to fix the following warning/error:

/home/fainelli/dev/openwrt/trunk/build_dir/target-mipsel-linux-gnu_glibc/odhcpd-2017-02-21-1b630f8b/src/dhcpv6-ia.c: In function 'dhcpv6_write_statefile':
/home/fainelli/dev/openwrt/trunk/build_dir/target-mipsel-linux-gnu_glibc/odhcpd-2017-02-21-1b630f8b/src/dhcpv6-ia.c:246:8: error: ignoring return value of 'lockf', declared with attribute warn_unused_result [-Werror=unused-result]
   lockf(fd, F_LOCK, 0);
        ^
cc1: all warnings being treated as errors

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
src/dhcpv6-ia.c

index 888634fe1f29482930afd78685d8f125ae94149d..fb50448844417311d40278a174bec0fc5115c200 100644 (file)
@@ -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");