コード例 #1
0
MessagePumpLibevent::~MessagePumpLibevent() {
    assert(wakeup_event_);
    assert(event_base_);
    event_del(wakeup_event_);
    delete wakeup_event_;
    if (wakeup_pipe_in_ >= 0) {
        if (IGNORE_EINTR(close(wakeup_pipe_in_)) < 0)
            std::cerr << "close wakeup_pipe_in_";
    }
    if (wakeup_pipe_out_ >= 0) {
        if (IGNORE_EINTR(close(wakeup_pipe_out_)) < 0)
            std::cerr << "close wakeup_pipe_out_";
    }
    event_base_free(event_base_);
}
コード例 #2
0
void DrainerObject::closeSocket() {
#ifdef _WIN32
    closesocket(mSocket);
#else
    IGNORE_EINTR(close(mSocket));
#endif
}
コード例 #3
0
ファイル: SandboxChroot.cpp プロジェクト: LordJZ/gecko-dev
static void
AlwaysClose(int fd)
{
  if (IGNORE_EINTR(close(fd)) != 0) {
    SANDBOX_LOG_ERROR("close: %s", strerror(errno));
    MOZ_CRASH("failed to close()");
  }
}
コード例 #4
0
void socketClose(int socket) {
    int save_errno = errno;
#ifdef _WIN32
    ::closesocket(socket);
#else
    IGNORE_EINTR(::close(socket));
#endif
    errno = save_errno;
}
コード例 #5
0
ファイル: util.c プロジェクト: AlexeySalmin/tlsdate
int file_write(int fd, void *buf, size_t sz)
{
	struct iovec iov[1];
	ssize_t ret;
	iov[0].iov_base = buf;
	iov[0].iov_len = sz;
	ret = IGNORE_EINTR (pwritev (fd, iov, 1, 0));
	if (ret != sz)
	{
		return -1;
	}
	return 0;
}
コード例 #6
0
ファイル: mdmopen.c プロジェクト: 3dfxmadscientist/mdm
int 
main (int argc, char *argv[])
{
	char vtname[256];
	int status;
	int cmd_start = 1;
	char *command = NULL;

	if (getuid () != geteuid () ||
	    getuid () != 0) {
		fprintf (stderr, "mdmopen: Only root wants to run me\n");
		return 66;
	}

	signal (SIGTERM, sighandler);
	signal (SIGINT, sighandler);
	signal (SIGHUP, sighandler);

	if (argc <= 1) {
		fprintf (stderr, "mdmopen: must supply a command!\n");
		return 66;
	}

	command = argv[1];

	if (strcmp (argv[1], "-l") == 0) {
		char *p;
		if (argc <= 2) {
			fprintf (stderr, "mdmopen: must supply a command!\n");
			return 66;
		}
		/* prepend '-' and start the command at
		 * argument 2 */
		cmd_start = 2;
		command = argv[2];
		argv[2] = malloc (strlen (command) + 2);
		if (argv[2] == NULL) {
			fprintf (stderr, "mdmopen: cannot allocate memory!\n");
			return 66;
		}
		p = strrchr (command, '/');
		if (p != NULL) {
			/* make it "-basename" */
			strcpy (argv[2]+1, p+1);
		} else {
			strcpy (argv[2]+1, command);
		}
		*(argv[2]) = '-';
	}

	fd = open (MDMCONSOLEDEVICE, O_WRONLY, 0);
	if (fd < 0) {
		perror ("mdmopen: Failed to open " MDMCONSOLEDEVICE);	
		return 66;
	}

	errno = 0;
	if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || (vtno == -1)) {
		perror ("mdmopen: Cannot find a free VT");
		IGNORE_EINTR (close (fd));
		return 66;
	}

	if (ioctl(fd, VT_GETSTATE, &vt) < 0) {
		perror ("mdmopen: can't get VTstate");
		IGNORE_EINTR (close(fd));
		return 66;
	}

	snprintf (vtname, sizeof (vtname), VTNAME, vtno);

	chown (vtname, 0, -1);

	child_pid = fork();
	if (child_pid == 0) {
		char VT_NUMBER[256];

		if (getenv ("UNSAFE_TO_TRANSLATE") != NULL &&
		    strcmp (getenv ("UNSAFE_TO_TRANSLATE"), "yes") == 0) {
			putenv ("LANG=C");

			/* portable way to truly unset with putenv? */
			putenv ("LC_ALL=");
			putenv ("LC_MESSAGES=");
			putenv ("LC_ALL");
			putenv ("LC_MESSAGES");
		}

#ifdef __linux__
		putenv ("TERM=linux");
#endif

		snprintf (VT_NUMBER, sizeof (VT_NUMBER), "VT_NUMBER=%d", vtno);
		putenv (VT_NUMBER);

		signal (SIGTERM, SIG_DFL);
		signal (SIGINT, SIG_DFL);
		signal (SIGHUP, SIG_DFL);

		/* leave current vt */
		if (
#ifdef   ESIX_5_3_2_D
		setpgrp() < 0
#else
		setsid() < 0
#endif      
		) {
			fprintf(stderr, "open: Unable to set new session (%s)\n",
				strerror(errno));
		}
		IGNORE_EINTR (close (0));
		IGNORE_EINTR (close (1));
		IGNORE_EINTR (close (2));
		IGNORE_EINTR (close (fd));

		/* and grab new one */
		fd = open (vtname, O_RDWR);
		if (fd < 0) { /* Shouldn't happen */
			_exit (66); /* silently die */
		}
		dup(fd);
		dup(fd);

		/* 
		* Can't tell anyone if any of these fail, so throw away
		* the return values 
		 */
		(void) ioctl(fd, VT_ACTIVATE, vtno);
		/* wait to be really sure we have switched */
		(void) ioctl(fd, VT_WAITACTIVE, vtno);

#ifdef __linux__
		/* Turn on fonts */
		IGNORE_EINTR (write (0, "\033(K", 3));
#endif /* __linux__ */

		execvp (command, &argv[cmd_start]);

		_exit (66); /* failed */
	}

	if (child_pid < 0) {
		perror ("mdmopen: fork() error");
		return 66;
	}

	do_switchback = TRUE;

	IGNORE_EINTR (waitpid (child_pid, &status, 0));
	child_pid = -1;

	do_switchback = FALSE;

	/* Switch back... */
	(void) ioctl(fd, VT_ACTIVATE, vt.v_active);
	/* wait to be really sure we have switched */
	(void) ioctl(fd, VT_WAITACTIVE, vt.v_active);

	IGNORE_EINTR (close (fd));

	if (WIFEXITED (status))
		return WEXITSTATUS (status);
	else
		return 66;
}