Lines 39-44
Link Here
|
39 |
#include <sys/resource.h> |
39 |
#include <sys/resource.h> |
40 |
#endif /* HAVE_SYS_RESOURCE_H */ |
40 |
#endif /* HAVE_SYS_RESOURCE_H */ |
41 |
|
41 |
|
|
|
42 |
#ifdef __FreeBSD__ |
43 |
#include <sys/param.h> |
44 |
#include <sys/sysctl.h> |
45 |
#include <sys/types.h> |
46 |
#include <sys/user.h> |
47 |
#include <pthread.h> |
48 |
#endif |
49 |
|
42 |
#include "gspawn.h" |
50 |
#include "gspawn.h" |
43 |
#include "gthread.h" |
51 |
#include "gthread.h" |
44 |
#include "glib/gstdio.h" |
52 |
#include "glib/gstdio.h" |
Lines 1077-1082
set_cloexec (void *data, gint fd)
Link Here
|
1077 |
} |
1085 |
} |
1078 |
|
1086 |
|
1079 |
#ifndef HAVE_FDWALK |
1087 |
#ifndef HAVE_FDWALK |
|
|
1088 |
|
1089 |
#ifdef __FreeBSD__ |
1090 |
static pthread_mutex_t fdwalk_mutex = PTHREAD_MUTEX_INITIALIZER; |
1091 |
|
1092 |
#define THREAD_LOCK() \ |
1093 |
do { \ |
1094 |
if (__isthreaded) pthread_mutex_lock(&fdwalk_mutex); \ |
1095 |
} while(0) |
1096 |
#define THREAD_UNLOCK() \ |
1097 |
do { \ |
1098 |
if (__isthreaded) pthread_mutex_unlock(&fdwalk_mutex); \ |
1099 |
} while(0) |
1100 |
|
1101 |
static int |
1102 |
fdwalk_s(int (*cb)(void *data, int fd), void *data, gint *resp) |
1103 |
{ |
1104 |
char *bp, *ep; |
1105 |
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC, 0}; |
1106 |
size_t len = 0; |
1107 |
struct kinfo_file kif; |
1108 |
|
1109 |
mib[3] = (int)getpid(); |
1110 |
|
1111 |
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) != 0) |
1112 |
return FALSE; |
1113 |
|
1114 |
if ((bp = (char*) malloc(len)) == NULL) |
1115 |
return FALSE; |
1116 |
|
1117 |
if (sysctl(mib, nitems(mib), bp, &len, NULL, 0) != 0) { |
1118 |
free(bp); |
1119 |
return FALSE; |
1120 |
} |
1121 |
|
1122 |
ep = bp; |
1123 |
while (ep < bp + len) { |
1124 |
kif = *(struct kinfo_file*)ep; |
1125 |
ep += kif.kf_structsize; |
1126 |
if (kif.kf_fd < 0) |
1127 |
continue; |
1128 |
|
1129 |
if ((*resp = cb (data, kif.kf_fd)) != 0) |
1130 |
break; |
1131 |
} |
1132 |
|
1133 |
free(bp); |
1134 |
return TRUE; |
1135 |
} |
1136 |
#endif |
1137 |
|
1080 |
static int |
1138 |
static int |
1081 |
fdwalk (int (*cb)(void *data, int fd), void *data) |
1139 |
fdwalk (int (*cb)(void *data, int fd), void *data) |
1082 |
{ |
1140 |
{ |
Lines 1088-1093
fdwalk (int (*cb)(void *data, int fd), v
Link Here
|
1088 |
struct rlimit rl; |
1146 |
struct rlimit rl; |
1089 |
#endif |
1147 |
#endif |
1090 |
|
1148 |
|
|
|
1149 |
#ifdef __FreeBSD__ |
1150 |
THREAD_LOCK(); |
1151 |
if (fdwalk_s(cb, data, &res) == TRUE) { |
1152 |
THREAD_UNLOCK(); |
1153 |
return res; |
1154 |
} |
1155 |
THREAD_UNLOCK(); |
1156 |
/* If any sysctl/malloc call fails continue with the fall back method */ |
1157 |
#endif |
1158 |
|
1091 |
#ifdef __linux__ |
1159 |
#ifdef __linux__ |
1092 |
DIR *d; |
1160 |
DIR *d; |
1093 |
|
1161 |
|