View | Details | Raw Unified | Return to bug 236815 | Differences between
and this patch

Collapse All | Expand All

(-)glib/gspawn.c (+52 lines)
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
#endif
48
42
#include "gspawn.h"
49
#include "gspawn.h"
43
#include "gthread.h"
50
#include "gthread.h"
44
#include "glib/gstdio.h"
51
#include "glib/gstdio.h"
Lines 1077-1082 set_cloexec (void *data, gint fd) Link Here
1077
}
1084
}
1078
1085
1079
#ifndef HAVE_FDWALK
1086
#ifndef HAVE_FDWALK
1087
1088
#ifdef __FreeBSD__
1089
static int
1090
fdwalk_s(int (*cb)(void *data, int fd), void *data, gint *resp)
1091
{
1092
  char	*bp, *ep;
1093
  int	 mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC, 0};
1094
  size_t len = 0;
1095
  struct kinfo_file kif;
1096
1097
  mib[3] = (int)getpid();
1098
1099
  if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) != 0)
1100
      return FALSE;
1101
1102
  if ((bp = (char*) malloc(len)) == NULL)
1103
      return FALSE;
1104
1105
  if (sysctl(mib, nitems(mib), bp, &len, NULL, 0) != 0) {
1106
      free(bp);
1107
      return FALSE;
1108
  }
1109
1110
  ep = bp;
1111
  while (ep < bp + len) {
1112
    kif = *(struct kinfo_file*)ep;
1113
    ep += kif.kf_structsize;
1114
    if (kif.kf_fd < 0)
1115
        continue;
1116
1117
    if ((*resp = cb (data, kif.kf_fd)) != 0)
1118
        break;
1119
  }
1120
1121
  free(bp);
1122
  return TRUE;
1123
}
1124
#endif
1125
1080
static int
1126
static int
1081
fdwalk (int (*cb)(void *data, int fd), void *data)
1127
fdwalk (int (*cb)(void *data, int fd), void *data)
1082
{
1128
{
Lines 1088-1093 fdwalk (int (*cb)(void *data, int fd), v Link Here
1088
  struct rlimit rl;
1134
  struct rlimit rl;
1089
#endif
1135
#endif
1090
1136
1137
#ifdef __FreeBSD__
1138
  if (fdwalk_s(cb, data, &res) == TRUE)
1139
      return res;
1140
  /* If any sysctl/malloc call fails continue with the fall back method */
1141
#endif
1142
1091
#ifdef __linux__  
1143
#ifdef __linux__  
1092
  DIR *d;
1144
  DIR *d;
1093
1145

Return to bug 236815