diff mbox series

[v2] Fix bsd build

Message ID 20210407231356.3422559-1-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series [v2] Fix bsd build | expand

Commit Message

Dominique Martinet April 7, 2021, 11:13 p.m. UTC
raw_handler/readback_handler use BLKGETSIZE64 which is linux-specific,
FreeBSD has DIOCGMEDIASIZE instead.

swupdate-sysrestart was including linux/if_link.h but does not appear
to actually need it

core/notifier isn't a build failure but a segfault on freebsd: the
string needs to be available and freeable from atexit handler, so use
strndup instead of strndupa...!

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
v2: add sob

 core/notifier.c             | 2 +-
 handlers/raw_handler.c      | 6 ++++++
 handlers/readback_handler.c | 6 ++++++
 tools/swupdate-sysrestart.c | 2 --
 4 files changed, 13 insertions(+), 3 deletions(-)

Comments

Stefano Babic April 17, 2021, 9:43 a.m. UTC | #1
On 08.04.21 01:13, Dominique Martinet wrote:
> raw_handler/readback_handler use BLKGETSIZE64 which is linux-specific,
> FreeBSD has DIOCGMEDIASIZE instead.
> 
> swupdate-sysrestart was including linux/if_link.h but does not appear
> to actually need it
> 
> core/notifier isn't a build failure but a segfault on freebsd: the
> string needs to be available and freeable from atexit handler, so use
> strndup instead of strndupa...!
> 
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
> v2: add sob
> 
>   core/notifier.c             | 2 +-
>   handlers/raw_handler.c      | 6 ++++++
>   handlers/readback_handler.c | 6 ++++++
>   tools/swupdate-sysrestart.c | 2 --
>   4 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/core/notifier.c b/core/notifier.c
> index 68447f2cc6cb..dc742c19f9d4 100644
> --- a/core/notifier.c
> +++ b/core/notifier.c
> @@ -368,7 +368,7 @@ static void unlink_socket(void)
>   
>   static void setup_socket_cleanup(struct sockaddr_un *addr)
>   {
> -	socket_path = strndupa(addr->sun_path, sizeof(addr->sun_path));
> +	socket_path = strndup(addr->sun_path, sizeof(addr->sun_path));
>   	if (atexit(unlink_socket) != 0) {
>   		TRACE("Cannot setup socket cleanup on exit, %s won't be unlinked.", socket_path);
>   	}
> diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
> index 1007e8baf4f5..e8e66eb73339 100644
> --- a/handlers/raw_handler.c
> +++ b/handlers/raw_handler.c
> @@ -10,7 +10,13 @@
>   #include <sys/stat.h>
>   #include <sys/types.h>
>   #include <sys/ioctl.h>
> +#ifdef __FreeBSD__
> +#include <sys/disk.h>
> +// the ioctls are almost identical except for the name, just alias it
> +#define BLKGETSIZE64 DIOCGMEDIASIZE
> +#else
>   #include <linux/fs.h>
> +#endif
>   
>   
>   #include <unistd.h>
> diff --git a/handlers/readback_handler.c b/handlers/readback_handler.c
> index 9dc99fce4855..aaab436122ae 100644
> --- a/handlers/readback_handler.c
> +++ b/handlers/readback_handler.c
> @@ -10,7 +10,13 @@
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <sys/ioctl.h>
> +#ifdef __FreeBSD__
> +#include <sys/disk.h>
> +// the ioctls are almost identical except for the name, just alias it
> +#define BLKGETSIZE64 DIOCGMEDIASIZE
> +#else
>   #include <linux/fs.h>
> +#endif
>   
>   #include "swupdate.h"
>   #include "handler.h"
> diff --git a/tools/swupdate-sysrestart.c b/tools/swupdate-sysrestart.c
> index 9a9a4ffca06f..152ed01ddb18 100644
> --- a/tools/swupdate-sysrestart.c
> +++ b/tools/swupdate-sysrestart.c
> @@ -24,7 +24,6 @@
>   #include <getopt.h>
>   #include <ifaddrs.h>
>   #include <netdb.h>
> -#include <linux/if_link.h>
>   
>   #if defined(CONFIG_CURL)
>   #include <curl/curl.h>
> @@ -270,4 +269,3 @@ int main(int __attribute__((__unused__)) argc, char __attribute__((__unused__))
>   	exit(1);
>   }
>   #endif
> -	
> 


Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/notifier.c b/core/notifier.c
index 68447f2cc6cb..dc742c19f9d4 100644
--- a/core/notifier.c
+++ b/core/notifier.c
@@ -368,7 +368,7 @@  static void unlink_socket(void)
 
 static void setup_socket_cleanup(struct sockaddr_un *addr)
 {
-	socket_path = strndupa(addr->sun_path, sizeof(addr->sun_path));
+	socket_path = strndup(addr->sun_path, sizeof(addr->sun_path));
 	if (atexit(unlink_socket) != 0) {
 		TRACE("Cannot setup socket cleanup on exit, %s won't be unlinked.", socket_path);
 	}
diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
index 1007e8baf4f5..e8e66eb73339 100644
--- a/handlers/raw_handler.c
+++ b/handlers/raw_handler.c
@@ -10,7 +10,13 @@ 
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#ifdef __FreeBSD__
+#include <sys/disk.h>
+// the ioctls are almost identical except for the name, just alias it
+#define BLKGETSIZE64 DIOCGMEDIASIZE
+#else
 #include <linux/fs.h>
+#endif
 
 
 #include <unistd.h>
diff --git a/handlers/readback_handler.c b/handlers/readback_handler.c
index 9dc99fce4855..aaab436122ae 100644
--- a/handlers/readback_handler.c
+++ b/handlers/readback_handler.c
@@ -10,7 +10,13 @@ 
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#ifdef __FreeBSD__
+#include <sys/disk.h>
+// the ioctls are almost identical except for the name, just alias it
+#define BLKGETSIZE64 DIOCGMEDIASIZE
+#else
 #include <linux/fs.h>
+#endif
 
 #include "swupdate.h"
 #include "handler.h"
diff --git a/tools/swupdate-sysrestart.c b/tools/swupdate-sysrestart.c
index 9a9a4ffca06f..152ed01ddb18 100644
--- a/tools/swupdate-sysrestart.c
+++ b/tools/swupdate-sysrestart.c
@@ -24,7 +24,6 @@ 
 #include <getopt.h>
 #include <ifaddrs.h>
 #include <netdb.h>
-#include <linux/if_link.h>
 
 #if defined(CONFIG_CURL)
 #include <curl/curl.h>
@@ -270,4 +269,3 @@  int main(int __attribute__((__unused__)) argc, char __attribute__((__unused__))
 	exit(1);
 }
 #endif
-