Revert "Linux: normalize error return for emulated syscalls"
authorSimon Wilkinson <sxw@your-file-system.com>
Tue, 15 Mar 2011 00:06:19 +0000 (00:06 +0000)
committerDerrick Brashear <shadow@dementia.org>
Tue, 15 Mar 2011 02:27:09 +0000 (19:27 -0700)
This reverts commit 0bc837f68a72ba1f75d940cc5dd057774d9f36bb.

Sadly, this change fixed setpag(), but broke all of the pioctls. The
problem is actually a little more nuanced than we at first thought.
What's happening is yet another case of Linux's special handling of
negative return values. When an ioctl handler returns a negative
return code to the kernel, it does errno = -code, and sets the
return code to -1. If you pass it a postive return code, however,
it just returns that straight to the application.

The pioctl code gets this right. However, the setpag code doesn't,
and so tries to return postive values, which is why ioctl appears
to be returning the error code in the return value, not in the
errno.

Change-Id: I192ff45ad15b72a493a3c9c98546b026761dd95f
Reviewed-on: http://gerrit.openafs.org/4222
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Marc Dionne <marc.c.dionne@gmail.com>
Reviewed-by: Marc Dionne <marc.c.dionne@gmail.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/sys/glue.c

index 80330de..3ba696c 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 #include <stdio.h>
-#include <errno.h>
 #ifdef AFS_SUN5_ENV
 #include <fcntl.h>
 #endif
 #ifdef AFS_LINUX20_ENV
 int proc_afs_syscall(long syscall, long param1, long param2, long param3,
                     long param4, int *rval) {
-    struct afsprocdata syscall_data;
-    int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
-    if(fd < 0)
-       fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
-    if(fd < 0)
-       return -1;
+  struct afsprocdata syscall_data;
+  int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
+  if(fd < 0)
+      fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
+  if(fd < 0)
+    return -1;
 
-    syscall_data.syscall = syscall;
-    syscall_data.param1 = param1;
-    syscall_data.param2 = param2;
-    syscall_data.param3 = param3;
-    syscall_data.param4 = param4;
+  syscall_data.syscall = syscall;
+  syscall_data.param1 = param1;
+  syscall_data.param2 = param2;
+  syscall_data.param3 = param3;
+  syscall_data.param4 = param4;
 
-    *rval = ioctl(fd, VIOC_SYSCALL, &syscall_data);
+  *rval = ioctl(fd, VIOC_SYSCALL, &syscall_data);
 
-    close(fd);
+  close(fd);
 
-    /* Callers expect us to emulate a syscall - return -1 on error, set errno */
-    if (*rval) {
-       errno = *rval;
-       *rval =  -1;
-    }
-    return 0;
+  return 0;
 }
 #endif