svn commit: r566632 - in head/devel/glib20: . files

John Baldwin jhb at FreeBSD.org
Fri Feb 26 19:31:05 UTC 2021


Author: jhb (src,doc committer)
Date: Fri Feb 26 19:31:04 2021
New Revision: 566632
URL: https://svnweb.freebsd.org/changeset/ports/566632

Log:
  Use kinfo_getfile() to implement fdwalk().
  
  Previously, the kern.file sysctl (which queries the global file table)
  was queried and the results saved in an on-stack buffer.  With a
  sufficiently active system the sysctl's output could overflow the
  stack's available space.  Instead, switch to kinfo_getfile() from
  libutil.  This uses a sysctl which queries only the open files for the
  current process, and it uses heap space instead of the stack to store
  the sysctl output.
  
  PR:		253602
  Submitted by:	ps (build glue patches)
  Reported by:	ps
  Reviewed by:	bapt
  MFH:		2021Q1
  Differential Revision:	https://reviews.freebsd.org/D28904

Added:
  head/devel/glib20/files/patch-glib_meson.build   (contents, props changed)
  head/devel/glib20/files/patch-meson.build   (contents, props changed)
Modified:
  head/devel/glib20/Makefile
  head/devel/glib20/files/patch-glib_gspawn.c

Modified: head/devel/glib20/Makefile
==============================================================================
--- head/devel/glib20/Makefile	Fri Feb 26 19:29:50 2021	(r566631)
+++ head/devel/glib20/Makefile	Fri Feb 26 19:31:04 2021	(r566632)
@@ -3,6 +3,7 @@
 
 PORTNAME=	glib
 DISTVERSION=	2.66.7
+PORTREVISION=	1
 PORTEPOCH=	1
 CATEGORIES=	devel
 MASTER_SITES=	GNOME

Modified: head/devel/glib20/files/patch-glib_gspawn.c
==============================================================================
--- head/devel/glib20/files/patch-glib_gspawn.c	Fri Feb 26 19:29:50 2021	(r566631)
+++ head/devel/glib20/files/patch-glib_gspawn.c	Fri Feb 26 19:31:04 2021	(r566632)
@@ -1,64 +1,45 @@
---- glib/gspawn.c	2018-09-21 12:29:23.000000000 +0300
-+++ glib/gspawn.c	2019-07-20 18:05:15.486558000 +0300
-@@ -51,6 +51,13 @@
+--- glib/gspawn.c.orig	2020-12-17 03:47:11.474608400 -0800
++++ glib/gspawn.c	2021-02-17 13:58:15.271434000 -0800
+@@ -51,6 +51,12 @@
  #include <sys/syscall.h>  /* for syscall and SYS_getdents64 */
  #endif
  
 +#ifdef __FreeBSD__
-+#include <sys/param.h>
-+#include <sys/sysctl.h>
++#include <sys/types.h>
 +#include <sys/user.h>
-+#include <sys/file.h>
++#include <libutil.h>
 +#endif
 +
  #include "gspawn.h"
  #include "gspawn-private.h"
  #include "gthread.h"
-@@ -1204,6 +1211,51 @@
+@@ -1204,6 +1210,33 @@ filename_to_fd (const char *p)
  }
  #endif
  
 +#ifdef __FreeBSD__
 +static int
-+fdwalk2(int (*func)(void *, int), void *udata, int *ret) {
-+  size_t i, bufsz = 0;
-+  struct xfile *xfbuf, *xf;
-+  int uret = 0, pid_found = 0;
-+  int mib[2] = { CTL_KERN, KERN_FILE };
-+  pid_t pid;
++fdwalk2(int (*func)(void *, int), void *udata, gint *ret)
++{
++  struct kinfo_file *kf;
++  int i, cnt;
 +
 +  if (NULL == func)
 +    return EINVAL;
 +
-+  if (sysctl (mib, nitems(mib), NULL, &bufsz, NULL, 0) == -1)
-+    return (errno);
-+  bufsz += 65536;
-+  xfbuf = alloca (bufsz);
-+  if (xfbuf == NULL)
-+    return errno;
-+  if (sysctl (mib, 2, xfbuf, &bufsz, NULL, 0) == -1)
-+    return errno;
-+  bufsz /= sizeof(struct xfile);
++  kf = kinfo_getfile(getpid(), &cnt);
++  if (kf == NULL)
++    return ENOMEM;
 +
-+  pid = getpid();
-+  for (i = 0; i < bufsz; i++) {
-+    xf = &xfbuf[i];
-+    if (pid != xf->xf_pid) {
-+      if (pid_found) {
-+        return 0;
-+      } else {
-+        continue;
-+      }
-+    }
-+    pid_found = 1;
-+    if (0 > xf->xf_fd)
++  for (i = 0; i < cnt; i++) {
++    if (0 > kf[i].kf_fd)
 +      continue;
-+    uret = func (udata, xf->xf_fd);
-+    if (uret != 0)
++    *ret = func (udata, kf[i].kf_fd);
++    if (*ret != 0)
 +      break;
-+
 +  }
 +
++  free(kf);
 +  return 0;
 +}
 +#endif
@@ -66,7 +47,7 @@
  /* This function is called between fork() and exec() and hence must be
   * async-signal-safe (see signal-safety(7)). */
  static int
-@@ -1228,6 +1280,12 @@
+@@ -1228,6 +1261,12 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data
    
  #if 0 && defined(HAVE_SYS_RESOURCE_H)
    struct rlimit rl;

Added: head/devel/glib20/files/patch-glib_meson.build
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/glib20/files/patch-glib_meson.build	Fri Feb 26 19:31:04 2021	(r566632)
@@ -0,0 +1,11 @@
+--- glib/meson.build.orig	2021-02-18 15:31:48.638470000 -0800
++++ glib/meson.build	2021-02-18 15:32:08.983695000 -0800
+@@ -376,7 +376,7 @@
+   # intl.lib is not compatible with SAFESEH
+   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
+   include_directories : configinc,
+-  dependencies : pcre_deps + [thread_dep, librt] + libintl_deps + libiconv + platform_deps + gnulib_libm_dependency + [libsysprof_capture_dep],
++  dependencies : pcre_deps + [thread_dep, librt] + libintl_deps + libiconv + platform_deps + gnulib_libm_dependency + [libsysprof_capture_dep] + libutil,
+   c_args : glib_c_args,
+   objc_args : glib_c_args,
+ )

Added: head/devel/glib20/files/patch-meson.build
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/glib20/files/patch-meson.build	Fri Feb 26 19:31:04 2021	(r566632)
@@ -0,0 +1,11 @@
+--- meson.build.orig	2021-02-11 04:24:55.280943200 -0800
++++ meson.build	2021-02-18 15:34:48.476370000 -0800
+@@ -2287,6 +2287,8 @@
+ test_timeout = 60
+ test_timeout_slow = 180
+ 
++libutil = [cc.find_library('util', required : true)]
++
+ pkg = import('pkgconfig')
+ windows = import('windows')
+ subdir('glib')


More information about the svn-ports-all mailing list