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

Collapse All | Expand All

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

Return to bug 236815