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

C++ clearenv函数代码示例

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

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



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

示例1: switch_user

int
switch_user(struct russ_sconn *sconn) {
    uid_t	uid;
    gid_t	gid;

    uid = sconn->creds.uid;
    gid = sconn->creds.gid;

#if 0
    if (uid == 0) {
        russ_sconn_fatal(sconn, "error: cannot run for root (uid of 0)", -1);
        exit(0);
    }
#endif

    /* set up env */
    if ((chdir("/") < 0)
            || (clearenv() < 0)) {
        russ_sconn_fatal(sconn, "error: cannot set environment", RUSS_EXIT_FAILURE);
        exit(0);
    }

    /* switch user */
    if (russ_switch_userinitgroups(uid, gid) < 0) {
        russ_sconn_fatal(sconn, RUSS_MSG_NOSWITCHUSER, RUSS_EXIT_FAILURE);
        exit(0);
    }
    return 0;
}
开发者ID:johnm-dev,项目名称:russng,代码行数:29,代码来源:rusrv_ssh.c


示例2: setup_session

static void
setup_session(struct weston_launch *wl)
{
	char **env;
	char *term;
	int i;

	if (wl->tty != STDIN_FILENO) {
		if (setsid() < 0)
			error(1, errno, "setsid failed");
		if (ioctl(wl->tty, TIOCSCTTY, 0) < 0)
			error(1, errno, "TIOCSCTTY failed - tty is in use");
	}

	term = getenv("TERM");
	clearenv();
	if (term)
		setenv("TERM", term, 1);
	setenv("USER", wl->pw->pw_name, 1);
	setenv("LOGNAME", wl->pw->pw_name, 1);
	setenv("HOME", wl->pw->pw_dir, 1);
	setenv("SHELL", wl->pw->pw_shell, 1);

	env = pam_getenvlist(wl->ph);
	if (env) {
		for (i = 0; env[i]; ++i) {
			if (putenv(env[i]) < 0)
				error(0, 0, "putenv %s failed", env[i]);
		}
		free(env);
	}
}
开发者ID:kendling,项目名称:weston,代码行数:32,代码来源:weston-launch.c


示例3: main

int main(void)
{
	pid_t pid;
	int status, wpid;
	char *argv[] = {
		"/bin/ls",
		"-laF",
		NULL,
	};

	clearenv();
	if ((pid = vfork()) == 0) {
		printf("Hi.  I'm the child process...\n");
		execvp(argv[0], argv);
		_exit(0);
	}

	printf("Hello.  I'm the parent process.\n");
	while (1) {
		wpid = wait(&status);
		if (wpid > 0 && wpid != pid) {
			continue;
		}
		if (wpid == pid)
			break;
	}

	printf("Child process exited.\nGoodbye.\n");
	return EXIT_SUCCESS;
}
开发者ID:Jaden-J,项目名称:uClibc,代码行数:30,代码来源:vfork.c


示例4: load_env

/* The environment file must exist, may be empty, and is expected to be of the format:
 * key=value\0key=value\0...
 */
static void load_env(const char *env)
{
	struct stat		st;
	char			*map, *k, *v;
	typeof(st.st_size)	i;

	map_file(env, PROT_READ|PROT_WRITE, MAP_PRIVATE, &st, (void **)&map);

	pexit_if(clearenv() != 0,
		"Unable to clear environment");

	if(!st.st_size)
		return;

	map[st.st_size - 1] = '\0'; /* ensure the mapping is null-terminated */

	for(i = 0; i < st.st_size;) {
		k = &map[i];
		i += strlen(k) + 1;
		exit_if((v = strchr(k, '=')) == NULL,
			"Malformed environment entry: \"%s\"", k);
		/* a private writable map is used permitting s/=/\0/ */
		*v = '\0';
		v++;
		pexit_if(setenv(k, v, 1) == -1,
			"Unable to set env variable: \"%s\"=\"%s\"", k, v);
	}
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:31,代码来源:diagexec.c


示例5: main

int main(int argc, char **argv)
{
	clearenv();

	init();

	printf("Initial: ");
	print();

	check_perms();

	printf("* TEMPORARY DROP \n");
	drop_temporarily();

	check_perms();

	printf("* RESTORE \n");
	restore();

	check_perms();

	printf("* PERNAMENT DROP \n");
	drop_pernamently();

	check_perms();


	printf("* RESTORE (we should fail now) \n");
	restore();

	check_perms();
		

	return 0;
}
开发者ID:blaa,项目名称:OTPasswd,代码行数:35,代码来源:suid.c


示例6: lxc_attach_set_environment

int lxc_attach_set_environment(enum lxc_attach_env_policy_t policy, char** extra_env, char** extra_keep)
{
	/* TODO: implement extra_env, extra_keep
	 * Rationale:
	 *  - extra_env is an array of strings of the form
	 *    "VAR=VALUE", which are to be set (after clearing or not,
	 *    depending on the value of the policy variable)
	 *  - extra_keep is an array of strings of the form
	 *    "VAR", which are extra environment variables to be kept
	 *    around after clearing (if that is done, otherwise, the
	 *    remain anyway)
	 */
	(void) extra_env;
	(void) extra_keep;

	if (policy == LXC_ATTACH_CLEAR_ENV) {
		if (clearenv()) {
			SYSERROR("failed to clear environment");
			/* don't error out though */
		}
	}

	if (putenv("container=lxc")) {
		SYSERROR("failed to set environment variable");
		return -1;
	}

	return 0;
}
开发者ID:abstrakraft,项目名称:lxc-android-lxc,代码行数:29,代码来源:attach.c


示例7: alcove_sys_clearenv

/*
 * clearenv(3)
 *
 */
    ssize_t
alcove_sys_clearenv(alcove_state_t *ap, const char *arg, size_t len,
        char *reply, size_t rlen)
{
#ifdef __linux__
    int rv = 0;

    UNUSED(ap);
    UNUSED(arg);
    UNUSED(len);

    rv = clearenv();

    return (rv < 0)
        ? alcove_mk_errno(reply, rlen, errno)
        : alcove_mk_atom(reply, rlen, "ok");
#else
    UNUSED(ap);
    UNUSED(arg);
    UNUSED(len);

    environ = NULL;
    return alcove_mk_atom(reply, rlen, "ok");
#endif
}
开发者ID:msantos,项目名称:alcove,代码行数:29,代码来源:clearenv.c


示例8: Copyright

/*
  Stolen from su for GNU.
  Copyright (C) 1992-2004 Free Software Foundation, Inc.
  License: GPL v2 or later.
*/
static
void modify_environment(const struct passwd *pw)
{
  char *term;
  char *display;
  char *path;
  
  term = getenv("TERM");
  display = getenv("DISPLAY");
  path = getenv("PATH");
  
#if HAVE_CLEARENV
  clearenv();
#else
  extern char **environ;   
  environ = n_malloc(2 * sizeof (char *));
  environ[0] = 0;
#endif
  
  if (term)
      do_putenv("TERM", term);
  
  if (display)
      do_putenv("DISPLAY", display);

  if (path)
      do_putenv("PATH", path);
  
  do_putenv("HOME", pw->pw_dir);
  do_putenv("SHELL", pw->pw_shell);
  do_putenv("USER", pw->pw_name);
  do_putenv("LOGNAME", pw->pw_name);
}
开发者ID:megabajt,项目名称:poldek,代码行数:38,代码来源:su.c


示例9: env_main

void env_main(void)
{
  char **ev;
  char **command = NULL;
  char *del = "=";

  if (toys.optflags) clearenv();

  for (ev = toys.optargs; *ev != NULL; ev++) {
    char *env, *val = NULL;

    env = strtok(*ev, del);

    if (env) val = strtok(NULL, del);

    if (val) setenv(env, val, 1);
    else {
      command = ev;
      break;
    }
  }

  if (!command) {
    char **ep;
    if (environ) for (ep = environ; *ep; ep++) xputs(*ep);
  } else xexec_optargs(command - toys.optargs);

}
开发者ID:0x6e3078,项目名称:toybox,代码行数:28,代码来源:env.c


示例10: main

int main(int argc, char **argv)
{
	int c;

	progname = basename(*argv);

	if (argc < 2) usage();

	clearenv();
	putenv("HOME=/");
	putenv("SHELL=/bin/sh");
	putenv("UID=0");
	putenv("USER=root");
	putenv("PATH=/bin");

	opterr = 0;
	optind = 1;

	while ((c = getopt(argc, argv, "n:")) != -1) {
		switch (c) {
			case 'n':
				putenv(optarg);
				break;
			default: usage(); break;
		}
	}

	execvp(*(argv+optind), argv+optind);
	return 127;
}
开发者ID:robbie-cao,项目名称:lynxware,代码行数:30,代码来源:minenv.c


示例11: main

int
main(int argc, char *argv[])
{
    int j;
    char **ep;

    clearenv();         /* Erase entire environment */

    /* Add any definitions specified on command line to environment */

    for (j = 1; j < argc; j++)
        if (putenv(argv[j]) != 0)
            errExit("putenv: %s", argv[j]);

    /* Add a definition for GREET if one does not already exist */

    if (setenv("GREET", "Hello world", 0) == -1)
        errExit("setenv");

    /* Remove any existing definition of BYE */

    unsetenv("BYE");

    /* Display current environment */

    for (ep = environ; *ep != NULL; ep++)
        puts(*ep);

    exit(EXIT_SUCCESS);
}
开发者ID:Cergoo,项目名称:junk,代码行数:30,代码来源:modify_env.c


示例12: fpm_env_init_child

int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
{
	struct key_value_s *kv;
	char *title;
	spprintf(&title, 0, "pool %s", wp->config->name);
	fpm_env_setproctitle(title);
	efree(title);

	if (wp->config->clear_env) {
		clearenv();
	}

	for (kv = wp->config->env; kv; kv = kv->next) {
		setenv(kv->key, kv->value, 1);
	}

	if (wp->user) {
		setenv("USER", wp->user, 1);
	}

	if (wp->home) {
		setenv("HOME", wp->home, 1);
	}

	return 0;
}
开发者ID:0x1111,项目名称:php-src,代码行数:26,代码来源:fpm_env.c


示例13: getpwnam

void UserTable::RunAsUser(char* const* argv) const
{
  struct passwd* pwd = getpwnam(m_user.c_str());
  if (    pwd == NULL                 // check query result
      ||  setgid(pwd->pw_gid) != 0    // check GID
      ||  initgroups(m_user.c_str(),pwd->pw_gid) != 0 // check supplementary groups
      ||  setuid(pwd->pw_uid) != 0)    // check UID
  {
    goto failed;
  }

  if (pwd->pw_uid != 0) {
    if (clearenv() != 0)
      goto failed;

    if (    setenv("LOGNAME",   pwd->pw_name,   1) != 0
        ||  setenv("USER",      pwd->pw_name,   1) != 0
        ||  setenv("USERNAME",  pwd->pw_name,   1) != 0
        ||  setenv("HOME",      pwd->pw_dir,    1) != 0
        ||  setenv("SHELL",     pwd->pw_shell,  1) != 0
        ||  setenv("PATH",      DEFAULT_PATH,   1) != 0)
    {
      goto failed;
    }
  }

  execvp(argv[0], argv);  // this may return only on failure

failed:

  syslog(LOG_ERR, "cannot exec process: %s", strerror(errno));
  _exit(1);
}
开发者ID:danfruehauf,项目名称:incron,代码行数:33,代码来源:usertable.cpp


示例14: loadenv

/*
 * load environment variable
 */
bool_t loadenv(char * file)
{
	struct xml * root, * env;

	root = xml_parse_file(file);
	if(!root || !root->name)
		return FALSE;

	if(strcmp(root->name, "environment") != 0)
	{
		xml_free(root);
		return FALSE;
	}

	clearenv();

	for(env = xml_child(root, "env"); env; env = env->next)
	{
		if(env->txt)
			putenv(env->txt);
	}

	xml_free(root);
	return TRUE;
}
开发者ID:rharter,项目名称:xboot-clone,代码行数:28,代码来源:environ.c


示例15: main

int main (int argc, char *argv[]) {
   int i;
   char **var;
  
   /* Si intende aggiungere una variabile d'ambiente come argomento */
   if (argc < 4) {
      fprintf(stderr, "Uso: %s name=value\n", argv[0]);
      exit(EXIT_FAILURE);
   }

   /* Cancella l'intero ambiente */
   clearenv();

   /* La variabile d'ambiente acquisita come argomento viene aggiunta alla
   environment list; ora vuota */
   for (i = 1; i < argc; i++)
      if (putenv (argv[i]) != 0) {
      	 fprintf (stderr, "Err.(%s) - put env\n", strerror(errno));
	    exit(EXIT_FAILURE);
   }
   
   /* Si aggiunge una ulteriore variabile d'ambiente con setenv() */
   if (setenv ("E-MAIL", "[email protected]", 0) < 0) {
      fprintf (stderr, "Err.(%s) - set env\n", strerror(errno));
      exit(EXIT_FAILURE);
   }
   
   /* Poiche' l'intero ambiente e' stato cancellato da clearenv(), l'ouput
   sara' molto breve; l'environment list infatti comprendera' solo le due
   variabili d'ambiente aggiunte nell'ambito del processo in esecuzione */
   for (var = environ; *var != NULL; var++)
      printf("%s\n", *var);
   
   exit (EXIT_SUCCESS);
}
开发者ID:b3h3moth,项目名称:L-LP,代码行数:35,代码来源:04_read_and_set_env_vars_2.c


示例16: main

int
main(int argc, char** argv)
{
	set_env();
	environ = NULL;
	test_env();

	set_env();
	environ[0] = NULL;
	test_env();

	static char* emptyEnv[1] = {NULL};
	set_env();
	environ = emptyEnv;
	test_env();

	set_env();
	environ = (char**)calloc(1, sizeof(*environ));
	test_env();

	// clearenv() is not part of the POSIX specs
#if 1
	set_env();
	clearenv();
	test_env();
#endif

	return 0;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:29,代码来源:clearenv.cpp


示例17: TEST

TEST(UNISTD_TEST, clearenv) {
  extern char** environ;

  // Guarantee that environ is not initially empty...
  ASSERT_EQ(0, setenv("test-variable", "a", 1));

  // Stash a copy.
  std::vector<char*> old_environ;
  for (size_t i = 0; environ[i] != NULL; ++i) {
    old_environ.push_back(strdup(environ[i]));
  }

  ASSERT_EQ(0, clearenv());

  EXPECT_TRUE(environ == NULL || environ[0] == NULL);
  EXPECT_EQ(NULL, getenv("test-variable"));
  EXPECT_EQ(0, setenv("test-variable", "post-clear", 1));
  EXPECT_STREQ("post-clear", getenv("test-variable"));

  // Put the old environment back.
  for (size_t i = 0; i < old_environ.size(); ++i) {
    EXPECT_EQ(0, putenv(old_environ[i]));
  }

  // Check it wasn't overwritten.
  EXPECT_STREQ("a", getenv("test-variable"));

  EXPECT_EQ(0, unsetenv("test-variable"));
}
开发者ID:0xDEC0DE8,项目名称:platform_bionic,代码行数:29,代码来源:unistd_test.cpp


示例18: xlsh_session_exec

int xlsh_session_exec(pam_handle_t* handle, const char* session, const char* arg0)
{
  struct passwd* pwinfo;
  const char* pwname;
  char terminal[256];
  pid_t proc_shell;
  int   proc_wait = 0;

  const char* _arg0 = arg0;
  if(!arg0) _arg0 = session;

  pam_get_item(handle, PAM_USER, (const void**)&pwname);
  pwinfo = getpwnam(pwname);
  if(!pwinfo)
    return XLSH_ERROR;

  if((proc_shell = fork()) == 0) {
    chdir(pwinfo->pw_dir);

    if(initgroups(pwname, pwinfo->pw_gid) == -1)
      exit(EXIT_FAILURE);
    if(setgid(pwinfo->pw_gid) == -1)
      exit(EXIT_FAILURE);
    if(setuid(pwinfo->pw_uid) == -1)
      exit(EXIT_FAILURE);

    if(getenv("TERM"))
      strncpy(terminal, getenv("TERM"), 256);
    else
      *terminal = 0;

    clearenv();
    setenv("USER", pwinfo->pw_name, 1);
    setenv("LOGNAME", pwinfo->pw_name, 1);
    setenv("HOME", pwinfo->pw_dir, 1);
    setenv("PATH", xlsh_config[XLSH_ID_PATH].value, 1);

    if(xlsh_X) {
      setenv("SHELL", pwinfo->pw_shell, 1);
      setenv("DISPLAY", xlsh_config[XLSH_ID_DISPLAY].value, 1);
      if(libxlsh_proc_exec(XLSH_XRDB, 0) > 0)
        wait(&proc_wait);
    }
    else
      setenv("SHELL", session, 1);

    if(*terminal)
      setenv("TERM", terminal, 1);

    execlp(session, _arg0, (char*)0);
    exit(EXIT_FAILURE);
  }
  else if(proc_shell == -1)
    return XLSH_ERROR;

  return XLSH_EOK;
}
开发者ID:drwilly,项目名称:xlsh,代码行数:57,代码来源:xlsh.c


示例19: START_TEST

END_TEST

START_TEST(test_clearenv)
{
	int ret;
	ret = clearenv();
	fail_if(ret != -1);
	fail_if(errno != ENOSYS);
}
开发者ID:insane-adding-machines,项目名称:test,代码行数:9,代码来源:unit_stubs.c


示例20: while

bool Connection::receiveActions()
{
    Logger::logDebug("Connection: enter: %s", __FUNCTION__);

    while (1)
    {
        uint32_t action = 0;

        // Get the action.
        recvMsg(&action);

        switch (action)
        {
        case INVOKER_MSG_EXEC:
            receiveExec();
            break;

        case INVOKER_MSG_ARGS:
            receiveArgs();
            break;

        case INVOKER_MSG_ENV:
            // Clean-up all the env variables
            clearenv();
            receiveEnv();
            break;

        case INVOKER_MSG_PRIO:
            receivePriority();
            break;

        case INVOKER_MSG_DELAY:
            receiveDelay();
            break;

        case INVOKER_MSG_IO:
            receiveIO();
            break;

        case INVOKER_MSG_IDS:
            receiveIDs();
            break;

        case INVOKER_MSG_END:
            sendMsg(INVOKER_MSG_ACK);

            if (m_sendPid)
                sendPid(getpid());

            return true;

        default:
            Logger::logError("Connection: received invalid action (%08x)\n", action);
            return false;
        }
    }
}
开发者ID:dudochkin-victor,项目名称:touch-applauncherd,代码行数:57,代码来源:connection.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ clearerr函数代码示例发布时间:2022-05-30
下一篇:
C++ cleardevice函数代码示例发布时间: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