common/utils: add system_fd_set_cloexec()
authorAlexander Couzens <[email protected]>
Mon, 23 Oct 2023 14:54:28 +0000 (16:54 +0200)
committerDavid Bauer <[email protected]>
Sat, 31 May 2025 20:41:00 +0000 (22:41 +0200)
Will be used by uqmid/ubus interface.
Taken from netifd/ubus interface.

Signed-off-by: Alexander Couzens <[email protected]>
common/utils.c
common/utils.h

index 3a2681d88e6884d3f9acea1895bb9f6fbc82b7c7..bd4cb4f03459db18ee209700eb5e615273d8804f 100644 (file)
  * Boston, MA 02110-1301 USA.
  */
 
+#include <fcntl.h>
+#include <libubox/utils.h>
+
 #include "utils.h"
 #include "qmi-errors.h"
 #include <qmi-errors.c>
 
-#include <libubox/utils.h>
 
 const char *qmi_get_error_str(int code)
 {
@@ -36,3 +38,10 @@ const char *qmi_get_error_str(int code)
 
        return "Unknown error";
 }
+
+void system_fd_set_cloexec(int fd)
+{
+#ifdef FD_CLOEXEC
+       fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+#endif
+}
index d7b7947e4178117c6ec659e911e227c5d92840a3..aeed5ec5cc1f1679b791c0611530c9d3e0d43f5e 100644 (file)
@@ -24,5 +24,6 @@
 #define __UTILS_H
 
 const char *qmi_get_error_str(int code);
+void system_fd_set_cloexec(int fd);
 
 #endif /* __UTILS_H */