From ff2933a122ddf9421ebcacdc7e4ec5f44333f894 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Tue, 15 Mar 2011 00:06:19 +0000 Subject: [PATCH] Revert "Linux: normalize error return for emulated syscalls" 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 Tested-by: Marc Dionne Reviewed-by: Marc Dionne Reviewed-by: Derrick Brashear --- src/sys/glue.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/sys/glue.c b/src/sys/glue.c index 80330de9a..3ba696cb3 100644 --- a/src/sys/glue.c +++ b/src/sys/glue.c @@ -20,7 +20,6 @@ #include #include #include -#include #ifdef AFS_SUN5_ENV #include #endif @@ -29,29 +28,24 @@ #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 -- 2.39.5