当前位置: 首页>>代码示例>>C++>>正文


C++ posix_spawnattr_init函数代码示例

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


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

示例1: TEST

TEST(spawn, posix_spawnattr_setsschedparam_posix_spawnattr_getsschedparam) {
  posix_spawnattr_t sa;
  ASSERT_EQ(0, posix_spawnattr_init(&sa));

  sched_param sp;
  ASSERT_EQ(0, posix_spawnattr_getschedparam(&sa, &sp));
  ASSERT_EQ(0, sp.sched_priority);

  sched_param sp123 = { .sched_priority = 123 };
  ASSERT_EQ(0, posix_spawnattr_setschedparam(&sa, &sp123));

  ASSERT_EQ(0, posix_spawnattr_getschedparam(&sa, &sp));
  ASSERT_EQ(123, sp.sched_priority);

  ASSERT_EQ(0, posix_spawnattr_destroy(&sa));
}

TEST(spawn, posix_spawnattr_setschedpolicy_posix_spawnattr_getschedpolicy) {
  posix_spawnattr_t sa;
  ASSERT_EQ(0, posix_spawnattr_init(&sa));

  int p;
  ASSERT_EQ(0, posix_spawnattr_getschedpolicy(&sa, &p));
  ASSERT_EQ(0, p);

  ASSERT_EQ(0, posix_spawnattr_setschedpolicy(&sa, SCHED_FIFO));

  ASSERT_EQ(0, posix_spawnattr_getschedpolicy(&sa, &p));
  ASSERT_EQ(SCHED_FIFO, p);

  ASSERT_EQ(0, posix_spawnattr_destroy(&sa));
}
开发者ID:android,项目名称:platform_bionic,代码行数:32,代码来源:spawn_test.cpp

示例2: Open

static int Open (vlc_object_t *obj)
{
    vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
    vlc_inhibit_sys_t *p_sys = malloc (sizeof (*p_sys));
    if (p_sys == NULL)
        return VLC_ENOMEM;

    posix_spawnattr_init (&p_sys->attr);
    /* Reset signal handlers to default and clear mask in the child process */
    {
        sigset_t set;

        sigemptyset (&set);
        posix_spawnattr_setsigmask (&p_sys->attr, &set);
        sigaddset (&set, SIGPIPE);
        posix_spawnattr_setsigdefault (&p_sys->attr, &set);
        posix_spawnattr_setflags (&p_sys->attr, POSIX_SPAWN_SETSIGDEF
                                              | POSIX_SPAWN_SETSIGMASK);
    }

    ih->p_sys = p_sys;
    if (vlc_timer_create (&p_sys->timer, Timer, ih))
    {
        posix_spawnattr_destroy (&p_sys->attr);
        free (p_sys);
        return VLC_ENOMEM;
    }

    ih->inhibit = Inhibit;
    return VLC_SUCCESS;
}
开发者ID:0xheart0,项目名称:vlc,代码行数:31,代码来源:xdg.c

示例3: tc_libc_spawn_posix_spawnattr_setgetschedparam

/**
* @fn                   : tc_libc_spawn_posix_spawnattr_SetGetschedparam
* @brief                : sets and gets the value of the scheduling parameters attribute
* @scenario             : The scheduling parameters attribute governs the parameter assigned to a new process image in a spawn operation
* @API's covered        : posix_spawnattr_init, posix_spawnattr_setschedparam, posix_spawnattr_getschedparam
* @Preconditions        : posix_spawnattr_init
* @Postconditions       : none
* @Return               : void
*/
static void tc_libc_spawn_posix_spawnattr_setgetschedparam(void)
{
	int ret_chk = ERROR;
	pid_t pid;
	struct sched_param setParam;
	struct sched_param getParam;
	posix_spawnattr_t st_attr;

	ret_chk = posix_spawnattr_init(&st_attr);
	TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);

	setParam.sched_priority = HIGH_PRIORITY;
	ret_chk = posix_spawnattr_setschedparam(&st_attr, &setParam);
	TC_ASSERT_EQ("posix_spawnattr_setschedparam", ret_chk, OK);

	ret_chk = task_spawn(&pid, "spawn", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
	sleep(SEC_4);
	TC_ASSERT_EQ("task_spawn", ret_chk, OK);

	ret_chk = posix_spawnattr_getschedparam(&st_attr, &getParam);
	TC_ASSERT_EQ("posix_spawnattr_getschedparam", ret_chk, OK);
	TC_ASSERT_EQ("posix_spawnattr_getschedparam", setParam.sched_priority, getParam.sched_priority);

	TC_SUCCESS_RESULT();
}
开发者ID:carhero,项目名称:TizenRT,代码行数:34,代码来源:tc_libc_spawn.c

示例4: spawn_win32

static void spawn_win32(void) {
  char module_name[WATCHMAN_NAME_MAX];
  GetModuleFileName(NULL, module_name, sizeof(module_name));
  char *argv[MAX_DAEMON_ARGS] = {
    module_name,
    "--foreground",
    NULL
  };
  posix_spawn_file_actions_t actions;
  posix_spawnattr_t attr;
  pid_t pid;
  int i;

  for (i = 0; daemon_argv[i]; i++) {
    append_argv(argv, daemon_argv[i]);
  }

  posix_spawnattr_init(&attr);
  posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP);
  posix_spawn_file_actions_init(&actions);
  posix_spawn_file_actions_addopen(&actions,
      STDIN_FILENO, "/dev/null", O_RDONLY, 0);
  posix_spawn_file_actions_addopen(&actions,
      STDOUT_FILENO, log_name, O_WRONLY|O_CREAT|O_APPEND, 0600);
  posix_spawn_file_actions_adddup2(&actions,
      STDOUT_FILENO, STDERR_FILENO);
  posix_spawnp(&pid, argv[0], &actions, &attr, argv, environ);
  posix_spawnattr_destroy(&attr);
  posix_spawn_file_actions_destroy(&actions);
}
开发者ID:Jerry-goodboy,项目名称:watchman,代码行数:30,代码来源:main.c

示例5: spawn_via_gimli

static void spawn_via_gimli(void)
{
  char *argv[MAX_DAEMON_ARGS] = {
    GIMLI_MONITOR_PATH,
#ifdef WATCHMAN_STATE_DIR
    "--trace-dir=" WATCHMAN_STATE_DIR "/traces",
#endif
    "--pidfile", pid_file,
    "watchman",
    "--foreground",
    NULL
  };
  posix_spawn_file_actions_t actions;
  posix_spawnattr_t attr;
  pid_t pid;
  int i;

  for (i = 0; daemon_argv[i]; i++) {
    append_argv(argv, daemon_argv[i]);
  }

  close_random_fds();

  posix_spawnattr_init(&attr);
  posix_spawn_file_actions_init(&actions);
  posix_spawn_file_actions_addopen(&actions,
      STDOUT_FILENO, log_name, O_WRONLY|O_CREAT|O_APPEND, 0600);
  posix_spawn_file_actions_adddup2(&actions,
      STDOUT_FILENO, STDERR_FILENO);
  posix_spawnp(&pid, argv[0], &actions, &attr, argv, environ);
  posix_spawnattr_destroy(&attr);
  posix_spawn_file_actions_destroy(&actions);
}
开发者ID:Jerry-goodboy,项目名称:watchman,代码行数:33,代码来源:main.c

示例6: target_proc

void target_proc(struct execute_context *ctx)
{
    int ret;

    char **args = ctx->passing_args;
    short ps_flags = 0;
    pid_t pid;
    posix_spawn_file_actions_t actions;
    posix_spawnattr_t attrs;

    if (args == NULL) {
        return;
    }

    RESET_ERROR;
    posix_spawn_file_actions_init(&actions);
    posix_spawnattr_init(&attrs);

#ifndef _POSIX_SPAWN_DISABLE_ASLR
#   define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
    ps_flags |= POSIX_SPAWN_SETEXEC;
    ps_flags |= _POSIX_SPAWN_DISABLE_ASLR;
    ret = posix_spawnattr_setflags(&attrs, ps_flags);
    if (ret != 0) {
        fprintf(stderr, "cannot set posix_spawn flags\n");
        return;
    }

    /* attached */
    ret = ptrace(PT_TRACE_ME, 0, 0, 0);
    posix_spawn(&pid, args[0], &actions, &attrs, args, NULL);
    fprintf(stderr, "Failed\n");
    exit(1);
}
开发者ID:YukiSakamoto,项目名称:Darwin_Trace,代码行数:35,代码来源:tracer.c

示例7: rb_spawn_process

pid_t
rb_spawn_process(const char *path, const char **argv)
{
    pid_t pid;
    const void *arghack = argv;
    char **myenviron;
    int error;
    posix_spawnattr_t spattr;
    posix_spawnattr_init(&spattr);
#ifdef POSIX_SPAWN_USEVFORK
    posix_spawnattr_setflags(&spattr, POSIX_SPAWN_USEVFORK);
#endif
#ifdef __APPLE__
    myenviron = *_NSGetEnviron(); /* apple needs to go fuck themselves for this */
#else
    myenviron = environ;
#endif
    error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron);
    posix_spawnattr_destroy(&spattr);
    if (error != 0) {
        errno = error;
        pid = -1;
    }
    return pid;
}
开发者ID:CustomIRCd,项目名称:elemental-ircd,代码行数:25,代码来源:unix.c

示例8: main

int main(int argc, char **argv)
{
  extern char **environ;
  pid_t pid;
  posix_spawnattr_t attr;
  int res, status = 1;
  char *default_argv[] = {"/bin/sh", NULL};

  if (argc >= 2)
    ++ argv;
  else
    argv = default_argv;

  res = posix_spawnattr_init(&attr);
  if (res != 0)
    return res;

  res = posix_spawnattr_setflags(&attr, _POSIX_SPAWN_DISABLE_ASLR);
  if (res != 0)
    return res;

  res = posix_spawn(&pid, argv[0], NULL, &attr, argv, environ);
  if (res != 0)
    return res;

  if (waitpid(pid, &status, 0) == -1)
    return 1;

  if (!WIFEXITED(status))
    return 1;

  return WEXITSTATUS(status);
}
开发者ID:CarterTsai,项目名称:clasp,代码行数:33,代码来源:noaslr.c

示例9: Launch_posixSpawnSuspended

/*
 * Static function implementations
 */
pid_t Launch_posixSpawnSuspended(cpu_type_t cpuType, const char *path, char** argv) {
	pid_t retVal = -1;
	
	if (path == NULL || argv == NULL) {
		Log_invalidArgument("path: %p, argv: %p", path, argv);
		
	} else {
		posix_spawnattr_t attr = 0;
		int ret = posix_spawnattr_init(&attr);
		if (ret != 0) {
			Log_errorPosix(ret, "posix_spawnattr_init");
			
		} else {
			sigset_t no_signals = 0;
			sigset_t all_signals = 0;
			sigemptyset(&no_signals);
			sigfillset(&all_signals);
			posix_spawnattr_setsigmask(&attr, &no_signals);
			posix_spawnattr_setsigdefault(&attr, &all_signals);

			if (cpuType != CPU_TYPE_ANY) {
				size_t ocount = 0;
				// if specified choose the arch from the fat binary to run
				ret = posix_spawnattr_setbinpref_np(&attr, 1, &cpuType, &ocount);
				if (ret != 0) {
					Log_errorPosix(ret, "posix_spawnattr_setbinpref_np");
				}
			}
			
			if (ret == 0) {
				ret = posix_spawnattr_setflags(&attr, 
											     POSIX_SPAWN_START_SUSPENDED 
											   | _POSIX_SPAWN_DISABLE_ASLR 
											   | POSIX_SPAWN_SETSIGDEF 
											   | POSIX_SPAWN_SETSIGMASK);
				if (ret != 0) {
					Log_errorPosix(ret, "posix_spawnattr_setflags");
					
				} else {
					pid_t pid = -1;
					ret = posix_spawnp(&pid, 
									   path, 
									   NULL, 
									   &attr, 
									   (char * const*)argv, 
									   (char * const*)NULL);
					if (ret != 0) {
						Log_errorPosix(ret, "posix_spawnp");
						
					} else {
						retVal = pid;
					}
				}
			}
			posix_spawnattr_destroy(&attr);
		}
	}
	return retVal;
}
开发者ID:mountainstorm,项目名称:Flow,代码行数:62,代码来源:Launch.c

示例10: do_spawn_test

/*
 * Helper function for posix_spawn test
 * 	arch: target architecture to spawn for
 */
int do_spawn_test(int arch, int shouldfail)
{
	int my_err, my_pid, my_status;
	size_t my_size;
	posix_spawnattr_t attr;

	char * args[] = {"helpers/arch", NULL};
	
	my_err = posix_spawnattr_init(&attr);
	if (my_err != 0) {
		printf("posix_spawnattr_init failed\n");
		goto done;
	}

	/* set spawn to only succeed for arch 'arch' */
	my_err = posix_spawnattr_setbinpref_np(&attr, 1, &arch, &my_size);
	if (my_err != 0 || my_size != 1) {
		printf("posix_spawnattr_setbinpref_np failed\n");
		goto done;
	}

	/* spawn off child process */
	my_err = posix_spawn(&my_pid, args[0], NULL, &attr, args, NULL);
	if (shouldfail) {
		if( my_err == 0) {
			printf("posix_spawn should have failed on arch %d\n", arch);
			goto done;
		}
		my_err = 0;
	} else {
		/*
		 * child should exit with return code == arch; note that the
		 * posix_spawn error numers are *returned*, NOT set in errno!!!
		 */
		if (my_err != 0) {
			printf("posix_spawn failed with errno %d - %s\n", my_err, strerror(my_err));
			goto done;
		}

		my_err = wait4(my_pid, &my_status, 0, NULL);
		if (my_err == -1) {
			printf("wait4 failed with errno %d - %s\n", errno, strerror(errno));
			goto done;
		}
		my_err = 0;

		if (WEXITSTATUS(my_status) != (arch & 0xff)) {
			printf("child exited with status %d (expected %d)\n", 
					(WEXITSTATUS(my_status)), 
					(arch & 0xff));
			my_err = -1;
			goto done;
		}
	}

done:
	return my_err;
}
开发者ID:Apple-FOSS-Mirror,项目名称:xnu,代码行数:62,代码来源:misc.c

示例11: setup_spawnattr

static void
setup_spawnattr(posix_spawnattr_t* spawnattr)
{
    size_t ocount;
    size_t count;
    cpu_type_t cpu_types[1];
    short flags = 0;
#ifdef __LP64__
    int   ch;
#endif

    if ((errno = posix_spawnattr_init(spawnattr)) != 0) {
        err(2, "posix_spawnattr_int");
        /* NOTREACHTED */
    }

    count = 1;

    /* Run the real python executable using the same architecture as this
     * executable, this allows users to control the architecture using
     * "arch -ppc python"
     */

#if defined(__ppc64__)
    cpu_types[0] = CPU_TYPE_POWERPC64;

#elif defined(__x86_64__)
    cpu_types[0] = CPU_TYPE_X86_64;

#elif defined(__ppc__)
    cpu_types[0] = CPU_TYPE_POWERPC;
#elif defined(__i386__)
    cpu_types[0] = CPU_TYPE_X86;
#else
#       error "Unknown CPU"
#endif

    if (posix_spawnattr_setbinpref_np(spawnattr, count,
                            cpu_types, &ocount) == -1) {
        err(1, "posix_spawnattr_setbinpref");
        /* NOTREACHTED */
    }
    if (count != ocount) {
        fprintf(stderr, "posix_spawnattr_setbinpref failed to copy\n");
        exit(1);
        /* NOTREACHTED */
    }


    /*
     * Set flag that causes posix_spawn to behave like execv
     */
    flags |= POSIX_SPAWN_SETEXEC;
    if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {
        err(1, "posix_spawnattr_setflags");
        /* NOTREACHTED */
    }
}
开发者ID:0xcc,项目名称:python-read,代码行数:58,代码来源:pythonw.c

示例12: do_test_setsid

static void
do_test_setsid (bool test_setsid)
{
  pid_t sid, child_sid;
  int res;

  /* Current session ID.  */
  sid = getsid(0);
  if (sid == (pid_t) -1)
    FAIL_EXIT1 ("getsid (0): %m");

  posix_spawnattr_t attrp;
  /* posix_spawnattr_init should not fail (it basically memset the
     attribute).  */
  posix_spawnattr_init (&attrp);
  if (test_setsid)
    {
      res = posix_spawnattr_setflags (&attrp, POSIX_SPAWN_SETSID);
      if (res != 0)
	{
	  errno = res;
	  FAIL_EXIT1 ("posix_spawnattr_setflags: %m");
	}
    }

  /* Program to run.  */
  char *args[2] = { (char *) "true", NULL };
  pid_t child;

  res = posix_spawnp (&child, "true", NULL, &attrp, args, environ);
  /* posix_spawnattr_destroy is noop.  */
  posix_spawnattr_destroy (&attrp);

  if (res != 0)
    {
      errno = res;
      FAIL_EXIT1 ("posix_spawnp: %m");
    }

  /* Child should have a different session ID than parent.  */
  child_sid = getsid (child);

  if (child_sid == (pid_t) -1)
    FAIL_EXIT1 ("getsid (%i): %m", child);

  if (test_setsid)
    {
      if (child_sid == sid)
	FAIL_EXIT1 ("child session ID matched parent one");
    }
  else
    {
      if (child_sid != sid)
	FAIL_EXIT1 ("child session ID did not match parent one");
    }
}
开发者ID:riscv,项目名称:riscv-glibc,代码行数:56,代码来源:tst-posix_spawn-setsid.c

示例13: lua_newuserdata

struct spawn_params *spawn_param_init(lua_State *L)
{
  struct spawn_params *p = lua_newuserdata(L, sizeof *p);
  p->L = L;
  p->command = 0;
  p->argv = p->envp = 0;
  posix_spawn_file_actions_init(&p->redirect);
  posix_spawnattr_init(&p->attr);
  posix_spawnattr_setflags(&p->attr, POSIX_SPAWN_USEVFORK);
  return p;
}
开发者ID:o-lim,项目名称:lua-ex,代码行数:11,代码来源:spawn.c

示例14: VG_REPLACE_FUNCTION_ZU

pid_t VG_REPLACE_FUNCTION_ZU(libastZdsoZd1, spawnveg)(const char *command,
                                                      char **argv,
                                                      char **envp,
                                                      pid_t pgid)
{
   int err = 0;
   pid_t pid;
   posix_spawnattr_t attr;
   int attr_init_done = 0;

   err = posix_spawnattr_init(&attr);
   if (err != 0)
      goto out;
   attr_init_done = 1;

   err = posix_spawnattr_init(&attr);
   if (err != 0)
      goto out;

   if (pgid != 0) {
      if (pgid <= 1)
         pgid = 0;
      err = posix_spawnattr_setpgroup(&attr, pgid);
      if (err != 0)
         goto out;
      err = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP);
      if (err != 0)
         goto out;
   }

   err = posix_spawn(&pid, command, NULL, &attr, argv, envp ? envp : environ);

out:
   if (attr_init_done)
      posix_spawnattr_destroy(&attr);
   if (err != 0) {
      errno = err;
      return -1;
   }
   return pid;
}
开发者ID:TUM-LIS,项目名称:valgrind-tracegen,代码行数:41,代码来源:vg_preloaded.c

示例15: tc_libc_spawn_posix_spawnattr_init

/**
* @fn                   :tc_libc_spawn_posix_spawnattr_init
* @brief                :Initializes the given spawn attributes object.
* @scenario             :Initializes the given spawn attributes object with the default value for all the attributes
* @API's covered        :posix_spawnattr_init
* @Preconditions        :none
* @Postconditions       :none
* @Return               :void
*/
static void tc_libc_spawn_posix_spawnattr_init(void)
{
	int ret_chk = ERROR;
	posix_spawnattr_t st_attr;

	ret_chk = posix_spawnattr_init(&st_attr);
	TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);
	TC_ASSERT_EQ("posix_spawnattr_init", st_attr.flags, 0);
	TC_ASSERT_EQ("posix_spawnattr_init", st_attr.stacksize, CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE);

	TC_SUCCESS_RESULT();
}
开发者ID:carhero,项目名称:TizenRT,代码行数:21,代码来源:tc_libc_spawn.c


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