You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/12/29 10:28:31 UTC
svn commit: r894331 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.in Makefile.msc.in configure include/acr_port.h
include/arch/unix/acr_arch.h port/fdwalk.c
Author: mturk
Date: Tue Dec 29 09:28:30 2009
New Revision: 894331
URL: http://svn.apache.org/viewvc?rev=894331&view=rev
Log:
Add fdwalk port
Added:
commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/configure
commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=894331&r1=894330&r2=894331&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Tue Dec 29 09:28:30 2009
@@ -288,6 +288,7 @@
$(SRCDIR)/port/arc4random.$(OBJ) \
$(SRCDIR)/port/basename.$(OBJ) \
$(SRCDIR)/port/dirname.$(OBJ) \
+ $(SRCDIR)/port/fdwalk.$(OBJ) \
$(SRCDIR)/port/fnmatch.$(OBJ) \
$(SRCDIR)/port/rijndael.$(OBJ) \
$(SRCDIR)/port/pmatch.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=894331&r1=894330&r2=894331&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Tue Dec 29 09:28:30 2009
@@ -167,6 +167,7 @@
$(SRCDIR)/port/arc4random.$(OBJ) \
$(SRCDIR)/port/basename.$(OBJ) \
$(SRCDIR)/port/dirname.$(OBJ) \
+ $(SRCDIR)/port/fdwalk.$(OBJ) \
$(SRCDIR)/port/fnmatch.$(OBJ) \
$(SRCDIR)/port/rijndael.$(OBJ) \
$(SRCDIR)/port/pmatch.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=894331&r1=894330&r2=894331&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Tue Dec 29 09:28:30 2009
@@ -1170,6 +1170,7 @@
#define HAVE_SYS_EPOLL_H `have_include 0 sys/epoll`
#define HAVE_SYS_EVENT_H `have_include 0 sys/event`
#define HAVE_SYS_EVENTFD_H `have_include 0 sys/eventfd`
+#define HAVE_SYS_SIGNALFD_H `have_include 0 sys/signalfd`
#define HAVE_SYS_INOTIFY_H `have_include 0 sys/inotify`
#define HAVE_LIMITS_H `have_include 1 limits`
#define HAVE_NETDB_H `have_include 0 netdb`
@@ -1195,6 +1196,9 @@
#define HAVE_SIGSETJMP `have_function 0 sigsetjmp`
#define HAVE_SIGACTION `have_function 0 sigaction`
#define HAVE_EVENTFD `have_function 0 eventfd`
+#define HAVE_EVENTFD2 `have_function 0 eventfd2`
+#define HAVE_SIGNALFD `have_function 0 signalfd`
+#define HAVE_FDWALK `have_function 0 fdwalk`
#define HAVE_SOCK_CLOEXEC `have_defined SOCK_CLOEXEC`
#define HAVE_FILE_CLOEXEC `have_defined O_CLOEXEC`
#define HAVE_OFF64_T $have_off64t
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h?rev=894331&r1=894330&r2=894331&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h Tue Dec 29 09:28:30 2009
@@ -126,4 +126,9 @@
size_t strquote(const char *, char *, size_t);
size_t wcsquote(const wchar_t *, wchar_t *, size_t);
+#if defined(ACR_WANT_FDWALK)
+int fdwalk(int (*func)(void *, int), void *);
+#endif
+
#endif /* _ACR_PORT_H */
+
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=894331&r1=894330&r2=894331&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Tue Dec 29 09:28:30 2009
@@ -93,6 +93,10 @@
#endif
#endif
+#if HAVE_FDWALK == 0
+#define ACR_WANT_FDWALK 1
+#endif
+
#define ACR_IOH_CLEAR 0x8000000
typedef struct acr_ioh acr_ioh;
typedef int (acr_ioh_cleanup_fn_t)(void *, int, unsigned int);
Added: commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c?rev=894331&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c Tue Dec 29 09:28:30 2009
@@ -0,0 +1,106 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_port.h"
+#include "acr_error.h"
+
+#if defined(ACR_WANT_FDWALK)
+
+#if defined(LINUX)
+#include <dirent.h>
+#define PROCFS_SELF_FD "/proc/self/fd"
+
+int fdwalk(int (*func)(void *data , int fd), void *cd)
+{
+ DIR *pd;
+ struct dirent *pe;
+ int rc = 0;
+ int se;
+ if (!(pd = opendir(PROCFS_SELF_FD)))
+ return -1;
+
+ while ((pe = readdir(pd))) {
+ int fd;
+ long fv;
+ char *ep;
+ if (*pe->d_name == '.')
+ continue;
+ /* To distinguish success/failure after strtol call
+ */
+ errno = 0;
+ fv = strtol(pe->d_name, &ep, 10);
+ /* Check for various possible errors */
+ if ((errno == ERANGE && (fv == LONG_MAX || fv == LONG_MIN)) ||
+ (errno != 0 && fv == 0) ||
+ (errno != 0 || !ep || *ep)) {
+ /* Not an numbered entry.
+ */
+ continue;
+ }
+ if (fv < 0 || fv > INT_MAX)
+ continue;
+ else
+ fd = (int)fv;
+ if (fd == dirfd(pd))
+ continue;
+ if ((rc = (*func)(cd, fd)))
+ break;
+ }
+ if (rc)
+ se = errno;
+ closedir(pd);
+ if (rc)
+ errno = se;
+ return rc;
+}
+
+#else
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+int fdwalk(int (*func)(void *, int), void *cd)
+{
+ int rc = 0;
+ int fd;
+ int fm = 1024;
+#if HAVE_SYS_RESOURCE_H
+ struct rlimit rl;
+
+ if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
+ fm = (int)rl.rlim_max;
+ else
+#else
+ fm = sysconf(_SC_OPEN_MAX);
+#endif
+
+ for (fd = 0; fd < fm; fd++) {
+ errno = 0;
+ rc = (*func)(cd, fd);
+ if (rc && errno != ENOENT)
+ break;
+ }
+ return rc;
+}
+#endif
+#else
+
+UNUSED_SOURCE_FILE(fdwalk);
+
+#endif /* ACR_WANT_FDWALK */
+
Propchange: commons/sandbox/runtime/trunk/src/main/native/port/fdwalk.c
------------------------------------------------------------------------------
svn:eol-style = native