This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] arm: ioperm use /proc/sys not sysctl


sysctl is essentially unmaintained bloat in the linux kernel
and is scheduled for removal in a year or so, meanwhile the
/proc/sys interface will remain and has always existed.

So use /proc/sys instead of sysctl in the implementation
of ioperm so it continues to work even when sysctl is not
present in the kernel.

I don't have an arm build system setup so I can not easily
verify I haven't made a stupid typo.  get_sysctl_int does
with other sysctl files on my x86 test machine.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 sysdeps/unix/sysv/linux/arm/ioperm.c |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/arm/ioperm.c b/sysdeps/unix/sysv/linux/arm/ioperm.c
index 8af1ea3..dccd8cf 100644
--- a/sysdeps/unix/sysv/linux/arm/ioperm.c
+++ b/sysdeps/unix/sysv/linux/arm/ioperm.c
@@ -80,7 +80,7 @@ static struct platform {
  * Initialize I/O system.  There are several ways to get the information
  * we need.  Each is tried in turn until one succeeds.
  *
- * 1. Sysctl (CTL_BUS, CTL_BUS_ISA, ISA_*).  This is the preferred method
+ * 1. Sysctl /proc/sys/bus/isa/*.  This is the preferred method
  *    but not all kernels support it.
  *
  * 2. Read the value (not the contents) of symlink PATH_ARM_SYSTYPE.
@@ -95,23 +95,36 @@ static struct platform {
  *    values.
  */
 
-/* The Linux kernel headers renamed this constant between 2.5.26 and
-   2.5.27.  It was backported to 2.4 between 2.4.22 and 2.4.23.  */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,23)
-# define BUS_ISA CTL_BUS_ISA
-#endif
+static int get_sysctl_int(const char *name, int *result)
+{
+  char buf[20];
+  ssize_t ret;
+  int fd;
+  fd = __open(name, O_RDONLY);
+  if (fd < 0)
+    return -1;
+
+  memset(buf, 0, sizeof(buf));
+  ret = __read(fd, buf, sizeof(buf) - 1);
+  __close(fd);
+  if (ret < 0)
+    return -1;
+  
+  *result = strtoul(buf, NULL, 10);
+  return 0;
+}
 
 static int
 init_iosys (void)
 {
   char systype[256];
   int i, n;
-  static int iobase_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_BASE };
-  static int ioshift_name[] = { CTL_BUS, BUS_ISA, BUS_ISA_PORT_SHIFT };
+  static const char iobase_name[] = "/proc/sys/bus/isa/portbase";
+  static const char ioshift_name[] = "/proc/sys/bus/isa/portshift";
   size_t len = sizeof(io.base);
 
-  if (! __sysctl (iobase_name, 3, &io.io_base, &len, NULL, 0)
-      && ! __sysctl (ioshift_name, 3, &io.shift, &len, NULL, 0))
+  if (! get_sysctl_int(iobase_name, &io.io_base)
+      && ! get_sysctl_int(ioshift_name, &io.io))
     {
       io.initdone = 1;
       return 0;
-- 
1.6.5.2.143.g8cc62


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]