Ejemplo n.º 1
0
void
_exit(int status)
{
	int		flags;
	int             i;
	struct itimerval itimer;

	/* Disable the interval timer: */
	itimer.it_interval.tv_sec  = 0;
	itimer.it_interval.tv_usec = 0;
	itimer.it_value.tv_sec     = 0;
	itimer.it_value.tv_usec    = 0;
	setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL);

	/* Close the pthread kernel pipe: */
	_thread_sys_close(_thread_kern_pipe[0]);
	_thread_sys_close(_thread_kern_pipe[1]);

	/*
	 * Enter a loop to set all file descriptors to blocking
	 * if they were not created as non-blocking:
	 */
	for (i = 0; i < _thread_max_fdtsize; i++) {
		/* Check if this file descriptor is in use: */
		if (_thread_fd_table[i] != NULL &&
		    _thread_fd_table[i]->status_flags != NULL &&
		    !(_thread_fd_table[i]->status_flags->flags & O_NONBLOCK)) {
			/* Get the current flags: */
			flags = _thread_sys_fcntl(i, F_GETFL, NULL);
			/* Clear the nonblocking file descriptor flag: */
			_thread_sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK);
		}
	}

	/* Call the _exit syscall: */
	_thread_sys__exit(status);
}
Ejemplo n.º 2
0
int
fcntl(int fd, int cmd, ...)
{
	va_list ap;
	int rv;

	va_start(ap, cmd);
	switch (cmd) {
	case F_DUPFD:
	case F_DUPFD_CLOEXEC:
	case F_SETFD:
	case F_SETFL:
	case F_SETOWN:
		rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, int));
		break;
	case F_GETFD:
	case F_GETFL:
	case F_GETOWN:
		rv = _thread_sys_fcntl(fd, cmd);
		break;
	case F_GETLK:
	case F_SETLK:
		rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, struct flock *));
		break;
	case F_SETLKW:
	{
		pthread_t self = pthread_self();

		_enter_cancel(self);
		rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, struct flock *));
		_leave_cancel(self);
		break;
	}
	default:	/* should never happen? */
		rv = _thread_sys_fcntl(fd, cmd, va_arg(ap, void *));
		break;
	}
	va_end(ap);
	return (rv);
}