Author: bonefish Date: 2011-06-07 00:37:29 +0200 (Tue, 07 Jun 2011) New Revision: 41991 Changeset: https://dev.haiku-os.org/changeset/41991 Modified: haiku/branches/developer/bonefish/signals/src/kits/network/socket.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/fcntl.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/poll.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread_cond.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/semaphore.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigsuspend.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigtimedwait.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigwait.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/flock.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/mman.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/select.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/wait.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/xsi_msg_queue.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/clock_support.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/close.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/pause.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/read.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sleep.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sync.c haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/system.cpp haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/write.c Log: Made all functions cancellation points that POSIX requires to be ones. Modified: haiku/branches/developer/bonefish/signals/src/kits/network/socket.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/kits/network/socket.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/kits/network/socket.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -12,6 +12,7 @@ #include <errno.h> #include <netinet/in.h> +#include <pthread.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> @@ -176,7 +177,8 @@ addressLength = sizeof(struct sockaddr_in); } - RETURN_AND_SET_ERRNO(_kern_connect(socket, address, addressLength)); + RETURN_AND_SET_ERRNO_TEST_CANCEL( + _kern_connect(socket, address, addressLength)); } @@ -205,6 +207,9 @@ } int acceptSocket = _kern_accept(socket, address, &addressLength); + + pthread_testcancel(); + if (acceptSocket < 0) { errno = acceptSocket; return -1; @@ -224,7 +229,7 @@ extern "C" ssize_t recv(int socket, void *data, size_t length, int flags) { - RETURN_AND_SET_ERRNO(_kern_recv(socket, data, length, flags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_recv(socket, data, length, flags)); } @@ -248,6 +253,9 @@ ssize_t bytesReceived = _kern_recvfrom(socket, data, length, flags, address, &addressLength); + + pthread_testcancel(); + if (bytesReceived < 0) { errno = bytesReceived; return -1; @@ -267,14 +275,14 @@ extern "C" ssize_t recvmsg(int socket, struct msghdr *message, int flags) { - RETURN_AND_SET_ERRNO(_kern_recvmsg(socket, message, flags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_recvmsg(socket, message, flags)); } extern "C" ssize_t send(int socket, const void *data, size_t length, int flags) { - RETURN_AND_SET_ERRNO(_kern_send(socket, data, length, flags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_send(socket, data, length, flags)); } @@ -290,15 +298,15 @@ addressLength = sizeof(struct sockaddr_in); } - RETURN_AND_SET_ERRNO(_kern_sendto(socket, data, length, flags, address, - addressLength)); + RETURN_AND_SET_ERRNO_TEST_CANCEL( + _kern_sendto(socket, data, length, flags, address, addressLength)); } extern "C" ssize_t sendmsg(int socket, const struct msghdr *message, int flags) { - RETURN_AND_SET_ERRNO(_kern_sendmsg(socket, message, flags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_sendmsg(socket, message, flags)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/fcntl.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/fcntl.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/fcntl.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -9,6 +9,7 @@ #include <errno.h> #include <fcntl.h> +#include <pthread.h> #include <stdarg.h> #include <unistd.h> @@ -20,14 +21,9 @@ int creat(const char *path, mode_t mode) { - int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, - mode & ~__gUmask); + RETURN_AND_SET_ERRNO_TEST_CANCEL( + _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask)); // adapt the permissions as required by POSIX - if (status < 0) { - errno = status; - return -1; - } - return status; } @@ -43,12 +39,7 @@ va_end(args); } - int status = _kern_open(-1, path, openMode, perms); - if (status < 0) { - errno = status; - return -1; - } - return status; + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(-1, path, openMode, perms)); } @@ -64,12 +55,7 @@ va_end(args); } - int status = _kern_open(fd, path, openMode, perms); - if (status < 0) { - errno = status; - return -1; - } - return status; + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(fd, path, openMode, perms)); } @@ -81,5 +67,10 @@ uint32 argument = va_arg(args, uint32); va_end(args); - RETURN_AND_SET_ERRNO(_kern_fcntl(fd, op, argument)); + status_t error = _kern_fcntl(fd, op, argument); + + if (op == F_SETLKW) + pthread_testcancel(); + + RETURN_AND_SET_ERRNO(error); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/poll.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/poll.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/poll.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,21 +1,21 @@ -/* +/* * Copyright 2002-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. * Distributed under the terms of the MIT License. */ +#include <poll.h> + #include <errno.h> -#include <poll.h> +#include <pthread.h> + +#include <syscall_utils.h> + #include <syscalls.h> int poll(struct pollfd *fds, nfds_t numfds, int timeout) { - int result = _kern_poll(fds, numfds, timeout * 1000LL); - if (result < 0) { - errno = result; - return -1; - } - return result; + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_poll(fds, numfds, timeout * 1000LL)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -13,6 +13,8 @@ #include <TLS.h> +#include <syscall_utils.h> + #include <syscalls.h> #include <thread_defs.h> #include <tls.h> @@ -185,7 +187,7 @@ status_t dummy; status_t error = wait_for_thread(thread->id, &dummy); if (error == B_BAD_THREAD_ID) - return ESRCH; + RETURN_AND_TEST_CANCEL(ESRCH); if (_value != NULL) *_value = thread->exit_value; @@ -193,7 +195,7 @@ if ((atomic_or(&thread->flags, THREAD_DETACHED) & THREAD_DEAD) != 0) free(thread); - return B_TO_POSIX_ERROR(error); + RETURN_AND_TEST_CANCEL(error); } @@ -213,7 +215,7 @@ if (status == B_BAD_THREAD_ID) return ESRCH; - return B_TO_POSIX_ERROR(status); + return status; } return 0; Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread_cond.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread_cond.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/pthread/pthread_cond.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -12,6 +12,8 @@ #include <stdio.h> #include <string.h> +#include <syscall_utils.h> + #include <syscalls.h> #include <user_mutex_defs.h> @@ -109,7 +111,7 @@ int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* _mutex) { - return cond_wait(cond, _mutex, B_INFINITE_TIMEOUT); + RETURN_AND_TEST_CANCEL(cond_wait(cond, _mutex, B_INFINITE_TIMEOUT)); } @@ -118,10 +120,10 @@ const struct timespec* tv) { if (tv == NULL || tv->tv_nsec < 0 || tv->tv_nsec >= 1000 * 1000 * 1000) - return EINVAL; + RETURN_AND_TEST_CANCEL(EINVAL); - return cond_wait(cond, mutex, - tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL); + RETURN_AND_TEST_CANCEL( + cond_wait(cond, mutex, tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/semaphore.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/semaphore.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/semaphore.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,5 +1,5 @@ /* - * Copyright 2008, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@xxxxxxx * Distributed under the terms of the MIT License. */ @@ -114,7 +114,8 @@ bigtime_t timeoutMicros = ((bigtime_t)timeout->tv_sec) * 1000000 + timeout->tv_nsec / 1000; - RETURN_AND_SET_ERRNO(_kern_realtime_sem_wait(semaphore->id, timeoutMicros)); + RETURN_AND_SET_ERRNO_TEST_CANCEL( + _kern_realtime_sem_wait(semaphore->id, timeoutMicros)); } @@ -128,8 +129,8 @@ int sem_wait(sem_t* semaphore) { - RETURN_AND_SET_ERRNO(_kern_realtime_sem_wait(semaphore->id, - B_INFINITE_TIMEOUT)); + RETURN_AND_SET_ERRNO_TEST_CANCEL( + _kern_realtime_sem_wait(semaphore->id, B_INFINITE_TIMEOUT)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigsuspend.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigsuspend.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigsuspend.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -11,6 +11,7 @@ #include <signal.h> #include <errno.h> +#include <pthread.h> #include <syscall_utils.h> @@ -32,6 +33,9 @@ __sigsuspend(const sigset_t* mask) { errno = _kern_sigsuspend(mask); + + pthread_testcancel(); + return -1; } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigtimedwait.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigtimedwait.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigtimedwait.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -7,6 +7,7 @@ #include <signal.h> #include <errno.h> +#include <pthread.h> #include <syscall_utils.h> @@ -36,6 +37,9 @@ } status_t error = _kern_sigwait(set, info, flags, timeoutMicros); + + pthread_testcancel(); + if (error != B_OK) RETURN_AND_SET_ERRNO(error); Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigwait.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigwait.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/signal/sigwait.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -7,6 +7,8 @@ #include <signal.h> +#include <pthread.h> + #include <symbol_versioning.h> #include <syscalls.h> @@ -36,6 +38,9 @@ { siginfo_t info; status_t error = _kern_sigwait(set, &info, 0, 0); + + pthread_testcancel(); + if (error != B_OK) return error; Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/flock.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/flock.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/flock.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -4,16 +4,21 @@ */ -#include <syscalls.h> +#include <sys/file.h> -#include <sys/file.h> #include <errno.h> +#include <pthread.h> +#include <syscalls.h> + int flock(int fd, int op) { status_t status = _kern_flock(fd, op); + + pthread_testcancel(); + if (status < B_OK) { errno = status; return -1; Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/mman.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/mman.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/mman.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -154,7 +154,7 @@ int msync(void* address, size_t length, int flags) { - RETURN_AND_SET_ERRNO(_kern_sync_memory(address, length, flags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_sync_memory(address, length, flags)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/select.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/select.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/select.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -8,6 +8,7 @@ #include <sys/select.h> #include <errno.h> +#include <pthread.h> #include <syscall_utils.h> @@ -42,7 +43,7 @@ status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, beosSignalMask != NULL ? &signalMask : NULL); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(status); } @@ -59,7 +60,7 @@ status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, sigMask); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(status); } @@ -72,9 +73,10 @@ if (tv) timeout = tv->tv_sec * 1000000LL + tv->tv_usec; - status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, NULL); + status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, + NULL); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(status); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/wait.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/wait.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/wait.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -8,6 +8,7 @@ #include <sys/wait.h> #include <errno.h> +#include <pthread.h> #include <syscall_utils.h> @@ -28,6 +29,9 @@ // wait siginfo_t info; pid_t child = _kern_wait_for_child(pid, options, &info); + + pthread_testcancel(); + if (child < 0) RETURN_AND_SET_ERRNO(child); @@ -87,23 +91,23 @@ case P_PID: // the child with the given ID if (id <= 0) - RETURN_AND_SET_ERRNO(EINVAL); + RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL); break; case P_PGID: // any child in the given process group if (id <= 1) - RETURN_AND_SET_ERRNO(EINVAL); + RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL); id = -id; break; default: - RETURN_AND_SET_ERRNO(EINVAL); + RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL); } pid_t child = _kern_wait_for_child(id, options, info); if (child >= 0 || child == B_WOULD_BLOCK) return 0; - RETURN_AND_SET_ERRNO(child); + RETURN_AND_SET_ERRNO_TEST_CANCEL(child); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/xsi_msg_queue.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/xsi_msg_queue.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/sys/xsi_msg_queue.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -37,8 +37,8 @@ msgrcv(int messageQueueID, void *messagePointer, size_t messageSize, long messageType, int messageFlags) { - RETURN_AND_SET_ERRNO(_kern_xsi_msgrcv(messageQueueID, messagePointer, - messageSize, messageType, messageFlags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_xsi_msgrcv(messageQueueID, + messagePointer, messageSize, messageType, messageFlags)); } @@ -46,6 +46,6 @@ msgsnd(int messageQueueID, const void *messagePointer, size_t messageSize, int messageFlags) { - RETURN_AND_SET_ERRNO(_kern_xsi_msgsnd(messageQueueID, messagePointer, - messageSize, messageFlags)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_xsi_msgsnd(messageQueueID, + messagePointer, messageSize, messageFlags)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/clock_support.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/clock_support.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/time/clock_support.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -7,6 +7,7 @@ #include <time.h> #include <errno.h> +#include <pthread.h> #include <sys/resource.h> #include <unistd.h> @@ -100,7 +101,7 @@ { // convert time to microseconds (round up) if (time->tv_nsec < 0 || time->tv_nsec >= 1000000000) - return EINVAL; + RETURN_AND_TEST_CANCEL(EINVAL); bigtime_t microSeconds = (bigtime_t)time->tv_sec * 1000000 + (time->tv_nsec + 999) / 1000; @@ -132,7 +133,7 @@ } } - return error; + RETURN_AND_TEST_CANCEL(error); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/close.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/close.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/close.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,22 +1,21 @@ -/* +/* ** Copyright 2001, Manuel J. Petit. All rights reserved. ** Distributed under the terms of the NewOS License. */ #include <unistd.h> -#include <syscalls.h> + #include <errno.h> +#include <pthread.h> +#include <syscall_utils.h> +#include <syscalls.h> + + int close(int fd) { - int retval = _kern_close(fd); - if (retval < 0) { - errno = retval; - retval = -1; - } - - return retval; + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_close(fd)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/pause.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/pause.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/pause.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -10,6 +10,7 @@ #include <syscalls.h> #include <errno.h> +#include <pthread.h> #include <signal.h> @@ -20,6 +21,9 @@ sigemptyset(&mask); errno = _kern_sigsuspend(&mask); + + pthread_testcancel(); + return -1; } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/read.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/read.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/read.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,25 +1,22 @@ -/* +/* * Copyright 2001, Manuel J. Petit. All rights reserved. * Distributed under the terms of the NewOS License. */ -/* +/* * Copyright 2002-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. * Distributed under the terms of the MIT License. */ #include <unistd.h> -#include <syscalls.h> + #include <errno.h> +#include <pthread.h> +#include <syscall_utils.h> -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include <syscalls.h> ssize_t @@ -27,33 +24,25 @@ { ssize_t status = _kern_read(fd, -1, buffer, bufferSize); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(status); } ssize_t read_pos(int fd, off_t pos, void* buffer, size_t bufferSize) { - ssize_t status; - if (pos < 0) { - errno = B_BAD_VALUE; - return -1; - } - status = _kern_read(fd, pos, buffer, bufferSize); + if (pos < 0) + RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_read(fd, pos, buffer, bufferSize)); } ssize_t pread(int fd, void* buffer, size_t bufferSize, off_t pos) { - ssize_t status; - if (pos < 0) { - errno = B_BAD_VALUE; - return -1; - } - status = _kern_read(fd, pos, buffer, bufferSize); + if (pos < 0) + RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_read(fd, pos, buffer, bufferSize)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sleep.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sleep.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sleep.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,9 +1,12 @@ -/* +/* ** Copyright 2001, Manuel J. Petit. All rights reserved. ** Distributed under the terms of the NewOS License. */ #include <unistd.h> + +#include <pthread.h> + #include <syscalls.h> @@ -20,6 +23,9 @@ usecs *= (bigtime_t) seconds; err = snooze_until(start + usecs, B_SYSTEM_TIMEBASE); + + pthread_testcancel(); + if (err) return seconds - (unsigned)((system_time() - start) / 1000000); Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sync.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sync.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/sync.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,24 +1,23 @@ -/* +/* ** Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. ** Distributed under the terms of the Haiku License. */ #include <unistd.h> -#include <syscalls.h> + #include <errno.h> +#include <pthread.h> +#include <syscall_utils.h> +#include <syscalls.h> + + int fsync(int fd) { - int status = _kern_fsync(fd); - if (status < 0) { - errno = status; - status = -1; - } - - return status; + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_fsync(fd)); } Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/system.cpp =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/system.cpp 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/system.cpp 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,16 +1,20 @@ /* - * Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2004-2011, Ingo Weinhold, ingo_weinhold@xxxxxxx * Distributed under the terms of the MIT License. */ #include <image.h> #include <errno.h> +#include <pthread.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h> +#include <syscall_utils.h> + + extern "C" int system(const char *command) { @@ -21,10 +25,8 @@ int argc = 3; thread_id thread = load_image(argc, argv, (const char **)environ); - if (thread < 0) { - errno = thread; - return -1; - } + if (thread < 0) + RETURN_AND_SET_ERRNO_TEST_CANCEL(thread); resume_thread(thread); Modified: haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/write.c =================================================================== --- haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/write.c 2011-06-06 22:32:50 UTC (rev 41990) +++ haiku/branches/developer/bonefish/signals/src/system/libroot/posix/unistd/write.c 2011-06-06 22:37:29 UTC (rev 41991) @@ -1,23 +1,20 @@ -/* +/* * Copyright 2002-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved. * Distributed under the terms of the MIT License. - * + * * Copyright 2001, Manuel J. Petit. All rights reserved. * Distributed under the terms of the NewOS License. */ #include <unistd.h> -#include <syscalls.h> + #include <errno.h> +#include <pthread.h> +#include <syscall_utils.h> -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include <syscalls.h> ssize_t @@ -25,33 +22,25 @@ { int status = _kern_write(fd, -1, buffer, bufferSize); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(status); } ssize_t write_pos(int fd, off_t pos, const void *buffer, size_t bufferSize) { - ssize_t status; - if (pos < 0) { - errno = B_BAD_VALUE; - return -1; - } - status = _kern_write(fd, pos, buffer, bufferSize); + if (pos < 0) + RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_write(fd, pos, buffer, bufferSize)); } ssize_t pwrite(int fd, const void *buffer, size_t bufferSize, off_t pos) { - ssize_t status; - if (pos < 0) { - errno = B_BAD_VALUE; - return -1; - } - status = _kern_write(fd, pos, buffer, bufferSize); + if (pos < 0) + RETURN_AND_SET_ERRNO_TEST_CANCEL(B_BAD_VALUE); - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_write(fd, pos, buffer, bufferSize)); }