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


C++ clearenv函数代码示例

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


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


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