• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pipe2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pipe2函数的典型用法代码示例。如果您正苦于以下问题:C++ pipe2函数的具体用法?C++ pipe2怎么用?C++ pipe2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pipe2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: g_unix_open_pipe

/**
 * g_unix_open_pipe:
 * @fds: Array of two integers
 * @flags: Bitfield of file descriptor flags, as for fcntl()
 * @error: a #GError
 *
 * Similar to the UNIX pipe() call, but on modern systems like Linux
 * uses the pipe2() system call, which atomically creates a pipe with
 * the configured flags. The only supported flag currently is
 * %FD_CLOEXEC. If for example you want to configure %O_NONBLOCK, that
 * must still be done separately with fcntl().
 *
 * This function does not take %O_CLOEXEC, it takes %FD_CLOEXEC as if
 * for fcntl(); these are different on Linux/glibc.
 *
 * Returns: %TRUE on success, %FALSE if not (and errno will be set).
 *
 * Since: 2.30
 */
gboolean
g_unix_open_pipe (int     *fds,
                  int      flags,
                  GError **error)
{
  int ecode;

  /* We only support FD_CLOEXEC */
  g_return_val_if_fail ((flags & (FD_CLOEXEC)) == flags, FALSE);

#ifdef HAVE_PIPE2
  {
    int pipe2_flags = 0;
    if (flags & FD_CLOEXEC)
      pipe2_flags |= O_CLOEXEC;
    /* Atomic */
    ecode = pipe2 (fds, pipe2_flags);
    if (ecode == -1 && errno != ENOSYS)
      return g_unix_set_error_from_errno (error, errno);
    else if (ecode == 0)
      return TRUE;
    /* Fall through on -ENOSYS, we must be running on an old kernel */
  }
#endif
  ecode = pipe (fds);
  if (ecode == -1)
    return g_unix_set_error_from_errno (error, errno);

  if (flags == 0)
    return TRUE;

  ecode = fcntl (fds[0], F_SETFD, flags);
  if (ecode == -1)
    {
      int saved_errno = errno;
      close (fds[0]);
      close (fds[1]);
      return g_unix_set_error_from_errno (error, saved_errno);
    }
  ecode = fcntl (fds[1], F_SETFD, flags);
  if (ecode == -1)
    {
      int saved_errno = errno;
      close (fds[0]);
      close (fds[1]);
      return g_unix_set_error_from_errno (error, saved_errno);
    }
  return TRUE;
}
开发者ID:endlessm,项目名称:glib,代码行数:68,代码来源:glib-unix.c


示例2: coprocess_common

pid_t coprocess_common(const char *path, const char *command, 
		char *const argv[], char *const envp[], int pipefd[2]) {
	if (command) {
		int pfd_in[2];
		int pfd_out[2];
		pid_t pid;
		if (pipe2(pfd_in, O_CLOEXEC) == -1 || pipe2(pfd_out, O_CLOEXEC) == -1)
			return -1;
		switch (pid=fork()) {
			case -1:
				return -1;
			case 0:
				if (__builtin_expect(execs_fork_security && execs_fork_security(execs_fork_security_arg) != 0, 0))
					_exit(127);
				if (dup2(pfd_in[0],0) == -1 || dup2(pfd_out[1],1) == -1)
					_exit(127);
				close(pfd_in[0]);
				close(pfd_in[1]);
				close(pfd_out[0]);
				close(pfd_out[1]);
				if (argv) {
					if (path)
						execve(path, argv, envp);
					else
						execvpe(command, argv, envp);
				} else 
					execse(path, command, envp);
				_exit(127);
			default:
				pipefd[0]=pfd_out[0];
				pipefd[1]=pfd_in[1];
				close(pfd_in[0]);
				close(pfd_out[1]);
				return pid;
		}
	} else 
		return 1;
}
开发者ID:rd235,项目名称:s2argv-execs,代码行数:38,代码来源:noshell.c


示例3: SystemNative_Pipe

int32_t SystemNative_Pipe(int32_t pipeFds[2], int32_t flags)
{
    switch (flags)
    {
        case 0:
            break;
        case PAL_O_CLOEXEC:
#if HAVE_O_CLOEXEC
            flags = O_CLOEXEC;
#endif
            break;
        default:
            assert_msg(false, "Unknown pipe flag", (int)flags);
            errno = EINVAL;
            return -1;
    }

    int32_t result;
#if HAVE_PIPE2
    // If pipe2 is available, use it.  This will handle O_CLOEXEC if it was set.
    while ((result = pipe2(pipeFds, flags)) < 0 && errno == EINTR);
#else
    // Otherwise, use pipe.
    while ((result = pipe(pipeFds)) < 0 && errno == EINTR);

    // Then, if O_CLOEXEC was specified, use fcntl to configure the file descriptors appropriately.
#if HAVE_O_CLOEXEC
    if ((flags & O_CLOEXEC) != 0 && result == 0)
#else
    if ((flags & PAL_O_CLOEXEC) != 0 && result == 0)
#endif
    {
        while ((result = fcntl(pipeFds[0], F_SETFD, FD_CLOEXEC)) < 0 && errno == EINTR);
        if (result == 0)
        {
            while ((result = fcntl(pipeFds[1], F_SETFD, FD_CLOEXEC)) < 0 && errno == EINTR);
        }

        if (result != 0)
        {
            int tmpErrno = errno;
            close(pipeFds[0]);
            close(pipeFds[1]);
            errno = tmpErrno;
        }
    }
#endif
    return result;
}
开发者ID:KrzysztofCwalina,项目名称:corefx,代码行数:49,代码来源:pal_io.c


示例4: forkpty

int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
{
	int m, s, ec=0, p[2], cs;
	pid_t pid=-1;
	sigset_t set, oldset;

	if (openpty(&m, &s, name, tio, ws) < 0) return -1;

	sigfillset(&set);
	pthread_sigmask(SIG_BLOCK, &set, &oldset);
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);

	if (pipe2(p, O_CLOEXEC)) {
		close(s);
		goto out;
	}

	pid = fork();
	if (!pid) {
		close(m);
		close(p[0]);
		if (login_tty(s)) {
			write(p[1], &errno, sizeof errno);
			_exit(127);
		}
		close(p[1]);
		pthread_setcancelstate(cs, 0);
		pthread_sigmask(SIG_SETMASK, &oldset, 0);
		return 0;
	}
	close(s);
	close(p[1]);
	if (read(p[0], &ec, sizeof ec) > 0) {
		int status;
		waitpid(pid, &status, 0);
		pid = -1;
		errno = ec;
	}
	close(p[0]);

out:
	if (pid > 0) *pm = m;
	else close(m);

	pthread_setcancelstate(cs, 0);
	pthread_sigmask(SIG_SETMASK, &oldset, 0);

	return pid;
}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:49,代码来源:forkpty.c


示例5: _ribified_pipe2

int _ribified_pipe2(int pipefd[2], int flags) {

    if (0 > pipe2(pipefd, flags | O_NONBLOCK))
        return -1;

    if (0 == ribs_epoll_add(pipefd[0], EPOLLIN | EPOLLET, event_loop_ctx) &&
        0 == ribs_epoll_add(pipefd[1], EPOLLOUT | EPOLLET, event_loop_ctx))
        return 0;

    int my_error = errno;
    close(pipefd[0]);
    close(pipefd[1]);
    errno = my_error;
    return -1;
}
开发者ID:Pferd,项目名称:ribs2,代码行数:15,代码来源:ribify.c


示例6: MakePipe

void MakePipe(int out_pipefds[2]) {
#if THRILL_HAVE_PIPE2
    if (pipe2(out_pipefds, O_CLOEXEC) != 0)
        throw ErrnoException("Error creating pipe");
#elif defined(_MSC_VER)
    if (_pipe(out_pipefds, 256, O_BINARY) != 0)
        throw ErrnoException("Error creating pipe");
#else
    if (pipe(out_pipefds) != 0)
        throw ErrnoException("Error creating pipe");

    PortSetCloseOnExec(out_pipefds[0]);
    PortSetCloseOnExec(out_pipefds[1]);
#endif
}
开发者ID:bingmann,项目名称:thrill,代码行数:15,代码来源:porting.cpp


示例7: manage_server_event

static void
manage_server_event (struct item_s *it, uint32_t evt)
{
    struct sockaddr_storage ss;
    int cli, rc, opt;

    ASSERT (evt & EPOLLIN);
    (void) evt;
    socklen_t sslen = sizeof (ss);

    cli = accept4 (it->fd, SA (&ss), &sslen, O_NONBLOCK | O_CLOEXEC);
    if (cli >= 0) {

        opt = PIPE_SIZE / 2;
        setsockopt (cli, SOL_SOCKET, SO_RCVBUF, &opt, sizeof (opt));
        opt = PIPE_SIZE;
        setsockopt (cli, SOL_SOCKET, SO_SNDBUF, &opt, sizeof (opt));

        sock_set_chatty (cli, 1);

        struct item_s *c = malloc (sizeof (struct item_s));

        c->loaded = 0;
        c->pfd[0] = c->pfd[1] = -1;
        if (0 > (rc = pipe2 (c->pfd, O_NONBLOCK | O_CLOEXEC))) {
            (void) close (cli);
            free (c);
            return;
        }
        c->fd = cli;
        c->events = EPOLLIN;
        c->type = CLIENT;
        c->shut = 0;
        fcntl (c->pfd[1], F_SETPIPE_SZ, PIPE_SIZE);

        struct epoll_event evt;

retry_add:
        evt.data.ptr = c;
        evt.events = EPOLLIN;
        rc = epoll_ctl (fd_epoll, EPOLL_CTL_ADD, cli, &evt);
        if (rc < 0) {
            if (rc == EINTR)
                goto retry_add;
            abort ();
        }
    }
}
开发者ID:jfsmig,项目名称:lbtk,代码行数:48,代码来源:echo-tcp-splice.c


示例8: init_pipe

int init_pipe(/*out*/pipe_t* pipe)
{
   int err;

   static_assert(1 + &pipe->read == &pipe->write, "Arrayzugriff möglich");

   if (/*Fehler?*/ pipe2(&pipe->read, O_NONBLOCK|O_CLOEXEC)) {
      err = errno;
      goto ONERR;
   }

   return 0;
ONERR:
   TRACEEXIT_ERRLOG(err);
   return err;
}
开发者ID:je-so,项目名称:js-projekt,代码行数:16,代码来源:pipe.c


示例9: vlc_pipe

/**
 * Creates a pipe (see "man pipe" for further reference).
 */
int vlc_pipe (int fds[2])
{
#ifdef HAVE_PIPE2
    if (pipe2 (fds, O_CLOEXEC) == 0)
        return 0;
    if (errno != ENOSYS)
        return -1;
#endif

    if (pipe (fds))
        return -1;

    fcntl (fds[0], F_SETFD, FD_CLOEXEC);
    fcntl (fds[1], F_SETFD, FD_CLOEXEC);
    return 0;
}
开发者ID:Flameeyes,项目名称:vlc,代码行数:19,代码来源:filesystem.c


示例10: main

int main(void) {
  int pipe_fds[2];
  int i;
  char* buf = mmap(NULL, SIZE, PROT_READ | PROT_WRITE,
                   MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

  test_assert(buf != MAP_FAILED);
  test_assert(0 == pipe2(pipe_fds, O_NONBLOCK));
  for (i = 0; i < 10000; ++i) {
    test_assert(-1 == read(pipe_fds[0], buf, SIZE));
    test_assert(errno == EAGAIN);
  }

  atomic_puts("EXIT-SUCCESS");
  return 0;
}
开发者ID:CarterTsai,项目名称:rr,代码行数:16,代码来源:read_nothing.c


示例11: main

int
main(void)
{
	(void) close(0);
	(void) close(1);
	int fds[2];
	if (pipe(fds))
		perror_msg_and_fail("pipe");

	(void) close(0);
	(void) close(1);
	if (pipe2(fds, O_NONBLOCK))
		perror_msg_and_skip("pipe2");

	return 0;
}
开发者ID:Fox-Heracles,项目名称:platform_external_strace,代码行数:16,代码来源:pipe.c


示例12: netcv_open_device

int netcv_open_device(adapter *ad)
{
	//fprintf(stderr, "REEL: netcv_open_device (id=%d)\n", ad->id);

	SN.want_commit = 0;
	SN.ncv_rec = NULL;

	/* create DVR pipe for TS data transfer from libmcli to minisatip */
	int pipe_fd[2];
	if (pipe2 (pipe_fd, O_NONBLOCK)) LOGL (0, "netceiver: creating pipe failed");
	ad->dvr = pipe_fd[0];	// read end of pipe
	SN.pwfd = pipe_fd[1];	// write end of pipe
	LOGL(0, "netceiver: creating DVR pipe for adapter %d  -> dvr: %d", ad->id, ad->dvr);

	return 0;
}
开发者ID:lars18th,项目名称:minisatip,代码行数:16,代码来源:netceiver.c


示例13: popen_impl

// not thread safe - needs a lock when called from the main
// process.
int popen_impl(const char* cmd, const char* mode, pid_t* out_pid) {
  int p[2];
  auto const read = *mode == 'r';
  if (!read && *mode != 'w') return -1;

  if (pipe2(p, O_CLOEXEC) < 0) {
    return -1;
  }

  auto pid = fork();
  if (pid < 0) {
    close(p[0]);
    close(p[1]);
    return -1;
  }
  int child_pipe = read ? 1 : 0;
  if (pid == 0) {
    // child
    mprotect_1g_pages(PROT_READ);
    // If anything goes wrong, let the OOM killer kill this child process.
    Process::OOMScoreAdj(1000);
    // replace stdin or stdout with the appropriate end
    // of the pipe
    if (p[child_pipe] == child_pipe) {
      // pretty unlikely, but if it was we must clear CLOEXEC,
      // and the only way to do that is to dup it to a new fd,
      // and then dup2 it back
      p[child_pipe] = fcntl(child_pipe, F_DUPFD_CLOEXEC, 3);
    }
    dup2(p[child_pipe], child_pipe);
    // no need to close p[child_pipe] because of O_CLOEXEC

    signal(SIGINT, SIG_DFL);
    sigset_t eset;
    sigemptyset(&eset);
    sigprocmask(SIG_SETMASK, &eset, nullptr);
    execl("/bin/sh", "sh", "-c", cmd, nullptr);
    Logger::Warning("Failed to exec: `%s'", cmd);
    _Exit(1);
  }
  // parent

  // close the pipe we're not using
  close(p[child_pipe]);
  *out_pid = pid;
  return p[1-child_pipe];
}
开发者ID:swtaarrs,项目名称:hhvm,代码行数:49,代码来源:light-process.cpp


示例14: install_generic_signal_handle

void install_generic_signal_handle() {
    int pipes[2];
    struct sigaction action;
    sigset_t empty_mask;
    
    sigemptyset(&empty_mask);
    
    /* Fill action with handle_signal function */
    action.sa_sigaction = &handle_signal;
    action.sa_flags = SA_SIGINFO|SA_RESTART;
    action.sa_mask = empty_mask;

    singularity_message(DEBUG, "Assigning generic sigaction()s\n");
    if ( -1 == sigaction(SIGINT, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGINT signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    if ( -1 == sigaction(SIGQUIT, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGQUIT signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    if ( -1 == sigaction(SIGTERM, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGTERM signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    if ( -1 == sigaction(SIGHUP, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGHUP signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    if ( -1 == sigaction(SIGUSR1, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGUSR1 signal handler: %s\n", strerror(errno));
        ABORT(255);
    }
    if ( -1 == sigaction(SIGUSR2, &action, NULL) ) {
        singularity_message(ERROR, "Failed to install SIGUSR2 signal handler: %s\n", strerror(errno));
        ABORT(255);
    }

    /* Open pipes for handle_signal() to write to */
    singularity_message(DEBUG, "Creating generic signal pipes\n");
    if ( -1 == pipe2(pipes, O_CLOEXEC) ) {
        singularity_message(ERROR, "Failed to create communication pipes: %s\n", strerror(errno));
        ABORT(255);
    }
    generic_signal_rpipe = pipes[0];
    generic_signal_wpipe = pipes[1];
}
开发者ID:yqin,项目名称:singularity,代码行数:47,代码来源:fork.c


示例15: daemonize

int daemonize(void) {
    if (0 > pipe2(child_is_up_pipe, O_CLOEXEC))
        return LOGGER_ERROR("failed to create pipe"), -1;

    pid_t pid = fork();
    if (pid < 0) {
        LOGGER_PERROR("daemonize, fork");
        exit(EXIT_FAILURE);
    }

    if (pid > 0) {
        close(child_is_up_pipe[1]); /* close the write side */
        /* wait for child to come up */
        uint8_t t;
        int res;
        LOGGER_INFO("waiting for the child process [%d] to start...", pid);
        if (0 >= (res = read(child_is_up_pipe[0], &t, sizeof(t)))) {
            if (0 > res)
                LOGGER_PERROR("pipe");
            LOGGER_ERROR("child process failed to start");
            exit(EXIT_FAILURE);
        }
        LOGGER_INFO("child process started successfully");
        exit(EXIT_SUCCESS);
    }

    close(child_is_up_pipe[0]); /* close the read side */

    umask(0);

    if (0 > setsid()) {
        LOGGER_PERROR("daemonize, setsid");
        exit(EXIT_FAILURE);
    }

    int fdnull = open("/dev/null", O_RDWR);
    dup2(fdnull, STDIN_FILENO);
    dup2(fdnull, STDOUT_FILENO);
    dup2(fdnull, STDERR_FILENO);
    close(fdnull);

    pid = getpid();

    LOGGER_INFO("child process started (pid=%d)", pid);

    return 0;
}
开发者ID:niosocket,项目名称:ribs2,代码行数:47,代码来源:daemonize.c


示例16: startup

static void
startup(void)
{
    guint id;

    if (pipe2(pfd, O_CLOEXEC) < 0) {
        SOL_WRN("pipe()");
        goto error;
    }

    if (!sol_glib_integration()) {
        SOL_WRN("sol_glib_integration()");
        goto error;
    }

    fork_run = sol_platform_linux_fork_run(on_fork, on_child_exit, NULL);
    if (!fork_run) {
        SOL_WRN("sol_platform_linux_fork_run()");
        goto error;
    }

    id = g_idle_add(on_idle, NULL);
    if (id == 0) {
        SOL_WRN("g_idle_add()");
        goto error;
    }

    id = g_timeout_add(100, on_timeout, NULL);
    if (id == 0) {
        SOL_WRN("g_timeout_add()");
        goto error;
    }

    id = g_unix_fd_add(pfd[0], G_IO_IN, on_fd, NULL);
    if (id == 0) {
        SOL_WRN("g_unix_fd_add()");
        goto error;
    }

    sol_timeout_add(5000, on_watchdog, NULL);
    return;

error:
    sol_quit_with_code(EXIT_FAILURE);
    return;
}
开发者ID:brunobottazzini,项目名称:soletta,代码行数:46,代码来源:test-mainloop-glib-integration.c


示例17: fcd_lib_cmd_spawn

/*
 * Spawns child process, creating pipe to read child command's output if
 * requested (create_output_pipe != 0).  On success, returns read fd of child
 * output pipe (or 0 if create_output_pipe == 0); returns -1 on error.
 */
static int fcd_lib_cmd_spawn(pid_t *child, char **cmd, const int *reaper_pipe,
			     int create_output_pipe)
{
	int output_pipe[2];

	if (create_output_pipe) {

		/* CLOEXEC will not be inherited by dup2'ed file descriptor */
		if (pipe2(output_pipe, O_CLOEXEC) == -1) {
			FCD_PERROR("pipe2");
			return -1;
		}
	}

	*child = fcd_proc_fork(reaper_pipe);
	if (*child == -1) {
		FCD_PERROR("fork");
		if (create_output_pipe) {
			if (close(output_pipe[0]) == -1)
				FCD_PERROR("close");
			if (close(output_pipe[1]) == -1)
				FCD_PERROR("close");
		}
		return -1;
	}

	if (*child == 0) {
		fcd_lib_cmd_child(create_output_pipe ? output_pipe[1] : -1,
				  cmd);
	}

	if (create_output_pipe)	{

		if (close(output_pipe[1]) == -1) {
			FCD_PERROR("close");
			if (close(output_pipe[0]) == -1) {
				FCD_PERROR("close");
				FCD_ABORT("Failed to close child pipe\n");
			}
			fcd_proc_kill(*child, reaper_pipe);
			return -1;
		}
	}

	return create_output_pipe ? output_pipe[0] : 0;
}
开发者ID:ipilcher,项目名称:n5550,代码行数:51,代码来源:lib.c


示例18: EnableRDS

bool
EnableRDS(uint32_t aMask)
{
  if (!sRadioEnabled || !sRDSSupported)
    return false;

  if (sMsmFMMode)
    setControl(V4L2_CID_PRIVATE_TAVARUA_RDSGROUP_MASK, aMask);

  if (sRDSEnabled)
    return true;

  int pipefd[2];
  int rc = pipe2(pipefd, O_NONBLOCK);
  if (rc < 0) {
    HAL_LOG("Could not create RDS thread signaling pipes (%d)", rc);
    return false;
  }

  ScopedClose writefd(pipefd[1]);
  ScopedClose readfd(pipefd[0]);

  rc = setControl(V4L2_CID_RDS_RECEPTION, true);
  if (rc < 0) {
    HAL_LOG("Could not enable RDS reception (%d)", rc);
    return false;
  }

  sRDSPipeFD = writefd;

  sRDSEnabled = true;

  rc = pthread_create(&sRDSThread, nullptr,
                      readRDSDataThread, (void*)pipefd[0]);
  if (rc) {
    HAL_LOG("Could not start RDS reception thread (%d)", rc);
    setControl(V4L2_CID_RDS_RECEPTION, false);
    sRDSEnabled = false;
    return false;
  }

  readfd.forget();
  writefd.forget();
  return true;
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:45,代码来源:GonkFMRadio.cpp


示例19: main

int main(int argc, char *argv[])
{
    int fd[2];
    pipe2(fd, O_NONBLOCK);
    int child = fork();
    if (child) {
        close(fd[1]);
        char buf;
        for (;;) {
            wait(NULL);
            if (read(fd[0], &buf, 1) > 0)
                break;
            ptrace(PTRACE_SYSCALL, child, NULL, NULL);
        }

        struct user_regs_struct regs;
        for (;;) {
            ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
            wait(NULL);
            ptrace(PTRACE_GETREGS, child, NULL, &regs);
#if defined(__i386__)
#define instruction_pointer regs.eip
#define upper_bound 0xb0000000
#elif defined(__x86_64__)
#define instruction_pointer regs.rip
#define upper_bound 0x700000000000
#else
#error "That platform is not supported."
#endif
            if (instruction_pointer < upper_bound) {
                unsigned long instruction = ptrace(PTRACE_PEEKTEXT, child, instruction_pointer, NULL);
                if ((instruction & 0xffff) == 0x25ff /* jmp r/m32 */) {
                    printf("0x%lx\n", instruction_pointer);
                    break;
                }
            }
        }
    } else {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        close(fd[0]);
        dup2(fd[1], 2);
        execl("/bin/su", "su", "not-a-valid-user", NULL);
    }
    return 0;
}
开发者ID:srclib,项目名称:CVE-2012-0056,代码行数:45,代码来源:ptrace-offset-finder.c


示例20: virPolkitAgentCreate

/* virPolkitAgentCreate:
 *
 * Allocate and setup a polkit agent
 *
 * Returns a virCommandPtr on success and NULL on failure
 */
virPolkitAgentPtr
virPolkitAgentCreate(void)
{
    virPolkitAgentPtr agent = NULL;
    int pipe_fd[2] = {-1, -1};
    struct pollfd pollfd;
    int outfd = STDOUT_FILENO;
    int errfd = STDERR_FILENO;

    if (!isatty(STDIN_FILENO))
        goto error;

    if (pipe2(pipe_fd, 0) < 0)
        goto error;

    if (VIR_ALLOC(agent) < 0)
        goto error;

    agent->cmd = virCommandNewArgList(PKTTYAGENT, "--process", NULL);

    virCommandAddArgFormat(agent->cmd, "%lld", (long long int) getpid());
    virCommandAddArg(agent->cmd, "--notify-fd");
    virCommandAddArgFormat(agent->cmd, "%d", pipe_fd[1]);
    virCommandAddArg(agent->cmd, "--fallback");
    virCommandSetInputFD(agent->cmd, STDIN_FILENO);
    virCommandSetOutputFD(agent->cmd, &outfd);
    virCommandSetErrorFD(agent->cmd, &errfd);
    virCommandPassFD(agent->cmd, pipe_fd[1], VIR_COMMAND_PASS_FD_CLOSE_PARENT);
    if (virCommandRunAsync(agent->cmd, NULL) < 0)
        goto error;

    pollfd.fd = pipe_fd[0];
    pollfd.events = POLLHUP;

    if (poll(&pollfd, 1, -1) < 0)
        goto error;

    return agent;

 error:
    VIR_FORCE_CLOSE(pipe_fd[0]);
    VIR_FORCE_CLOSE(pipe_fd[1]);
    virPolkitAgentDestroy(agent);
    return NULL;
}
开发者ID:Archer-sys,项目名称:libvirt,代码行数:51,代码来源:virpolkit.c



注:本文中的pipe2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pipe_buffer_unmap函数代码示例发布时间:2022-05-30
下一篇:
C++ pipe函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap