summaryrefslogtreecommitdiff
path: root/src/xine-utils
diff options
context:
space:
mode:
authorDarren Salt <linux@youmustbejoking.demon.co.uk>2011-10-04 23:41:41 +0100
committerDarren Salt <linux@youmustbejoking.demon.co.uk>2011-10-04 23:41:41 +0100
commit5be586e3025e72c1a1cef2a3ada6238486f7ed43 (patch)
tree2a5da19b632e9296e622e47c161062caec0b9b89 /src/xine-utils
parentd7c4d2bd622b1405ff520006dbeaf739e9725a89 (diff)
parent7e335173083e1fc91f27927a2d749f5a09773b32 (diff)
downloadxine-lib-5be586e3025e72c1a1cef2a3ada6238486f7ed43.tar.gz
xine-lib-5be586e3025e72c1a1cef2a3ada6238486f7ed43.tar.bz2
Merge from 1.1.
--HG-- rename : src/xine-utils/attributes.h => include/xine/attributes.h rename : src/xine-engine/xine_internal.h => include/xine/xine_internal.h rename : src/xine-utils/xineutils.h => include/xine/xineutils.h
Diffstat (limited to 'src/xine-utils')
-rw-r--r--src/xine-utils/utils.c61
-rw-r--r--src/xine-utils/xine_check.c10
2 files changed, 68 insertions, 3 deletions
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index 75caaf09f..27c52c70d 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -35,9 +35,12 @@
#include <errno.h>
#include <pwd.h>
+#include <sys/types.h>
#include <sys/time.h>
+#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
+#include <fcntl.h>
#if HAVE_EXECINFO_H
#include <execinfo.h>
@@ -56,6 +59,10 @@
#include <windows.h>
#endif
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
typedef struct {
const char language[16]; /* name of the locale */
const char encoding[16]; /* typical encoding */
@@ -717,3 +724,57 @@ char *xine_strcat_realloc (char **dest, char *append)
strcat (*dest = newstr, append);
return newstr;
}
+
+
+int _x_set_file_close_on_exec(int fd)
+{
+#ifndef WIN32
+ return fcntl(fd, F_SETFD, FD_CLOEXEC);
+#else
+ return SetHandleInformation((HANDLE)_get_osfhandle(fd), HANDLE_FLAG_INHERIT, 0);
+#endif
+}
+
+int _x_set_socket_close_on_exec(int s)
+{
+#ifndef WIN32
+ return fcntl(s, F_SETFD, FD_CLOEXEC);
+#else
+ return SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
+#endif
+}
+
+
+int xine_open_cloexec(const char *name, int flags)
+{
+ int fd = open(name, (flags | O_CLOEXEC));
+
+ if (fd >= 0) {
+ _x_set_file_close_on_exec(fd);
+ }
+
+ return fd;
+}
+
+int xine_create_cloexec(const char *name, int flags, mode_t mode)
+{
+ int fd = open(name, (flags | O_CREAT | O_CLOEXEC), mode);
+
+ if (fd >= 0) {
+ _x_set_file_close_on_exec(fd);
+ }
+
+ return fd;
+}
+
+int xine_socket_cloexec(int domain, int type, int protocol)
+{
+ int s = socket(domain, type, protocol);
+
+ if (s >= 0) {
+ _x_set_socket_close_on_exec(s);
+ }
+
+ return s;
+}
+
diff --git a/src/xine-utils/xine_check.c b/src/xine-utils/xine_check.c
index b0a252b6f..3c860493b 100644
--- a/src/xine-utils/xine_check.c
+++ b/src/xine-utils/xine_check.c
@@ -46,6 +46,10 @@
#include <xine/xineutils.h>
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
#if defined(__linux__)
#include <dlfcn.h>
@@ -168,7 +172,7 @@ static xine_health_check_t* _x_health_check_cdrom (xine_health_check_t* hc) {
return hc;
}
- if ( (fd = open(hc->cdrom_dev, O_RDWR)) < 0) {
+ if ( (fd = open(hc->cdrom_dev, O_RDWR | O_CLOEXEC)) < 0) {
switch (errno) {
case EACCES:
set_hc_result (hc, XINE_HEALTH_CHECK_FAIL, "FAILED - %s permissions are not sufficient\n.", hc->cdrom_dev);
@@ -204,7 +208,7 @@ static xine_health_check_t* _x_health_check_dvdrom(xine_health_check_t* hc) {
return hc;
}
- if ( (fd = open(hc->dvd_dev, O_RDWR)) < 0) {
+ if ( (fd = open(hc->dvd_dev, O_RDWR | O_CLOEXEC)) < 0) {
switch (errno) {
case EACCES:
set_hc_result (hc, XINE_HEALTH_CHECK_FAIL, "FAILED - %s permissions are not sufficient\n.", hc->dvd_dev);
@@ -247,7 +251,7 @@ static xine_health_check_t* _x_health_check_dma (xine_health_check_t* hc) {
return hc;
}
- fd = open (hc->dvd_dev, O_RDONLY | O_NONBLOCK);
+ fd = open (hc->dvd_dev, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
set_hc_result(hc, XINE_HEALTH_CHECK_FAIL, "FAILED - Could not open %s.\n", hc->dvd_dev);
return hc;