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

C++ setenv函数代码示例

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

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



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

示例1: nvram2env_attach

static int
nvram2env_attach(device_t dev)
{
	struct nvram2env_softc * sc = device_get_softc(dev);
	struct nvram * nv;
	char *pair, *value, *assign;
	uint32_t sig, size, i;

	if (sc->bst == 0 || sc->addr == 0)
		return (ENXIO);

	if (bus_space_map(sc->bst, sc->addr, NVRAM_MAX_SIZE, 0,
		&sc->bsh) != 0)
		return (ENXIO);

	sig  = read_4(sc, 0);
	size = read_4(sc, 4);
#if 1
	if (bootverbose)
		device_printf(dev, " size=0x%05x maxsize=0x%05x\n", size, sc->maxsize);
#endif
	size = (size > sc->maxsize)?sc->maxsize:size;


	if (sig == sc->sig || (sc->flags & NVRAM_FLAGS_UBOOT))
	{

		/* align and shift size to 32bit size*/
		size += 3;
		size >>= 2;

		nv = malloc(size<<2, M_DEVBUF, M_WAITOK | M_ZERO);
		if (!nv)
			return (ENOMEM);

		for (i = 0; i < size; i ++)
			((uint32_t *)nv)[i] = read_4(sc, i<<2);

		if (sc->flags & NVRAM_FLAGS_BROADCOM) {
			device_printf(dev, "sig = %#x\n",  nv->sig);
			device_printf(dev, "size = %#x\n", nv->size);
		}

		if (!(sc->flags & NVRAM_FLAGS_NOCHECK)) {
			/* TODO: need checksum verification */
		}

		if (sc->flags & NVRAM_FLAGS_GENERIC)
			pair = (char*)nv+4;
		if (sc->flags & NVRAM_FLAGS_UBOOT)
			pair = (char*)nv+4;
		else if (sc->flags & NVRAM_FLAGS_BROADCOM)
			pair = (char*)nv+20;
		else
			pair = (char*)nv+4;

		for ( ; 
		    (u_int32_t)pair < ((u_int32_t)nv + size - 4); 
		    pair = pair + strlen(pair) + 1 + strlen(value) + 1 ) {

			if (pair && strlen(pair)) {

#if 0
				printf("ENV: %s\n", pair);
#endif
				/* hint.nvram.0. */
				assign = strchr(pair,'=');
				assign[0] = '\0';
				value = assign+1;
#if 1
				if (bootverbose)
					printf("ENV: %s=%s\n", pair, value);
#endif
				setenv(pair, value);

				if (strcasecmp(pair, "WAN_MAC_ADDR") == 0) {
					/* Alias for MAC address of eth0 */
					if (bootverbose)
						printf("ENV: aliasing "
						    "WAN_MAC_ADDR to ethaddr"
						    " = %s\n",  value);
					setenv("ethaddr", value);
				}
				else if (strcasecmp(pair, "LAN_MAC_ADDR") == 0){
					/* Alias for MAC address of eth1 */
					if (bootverbose)
						printf("ENV: aliasing "
						    "LAN_MAC_ADDR to eth1addr"
						    " = %s\n",  value);
					setenv("eth1addr", value);
				}

				if (strcmp(pair, "bootverbose") == 0)
					bootverbose = strtoul(value, 0, 0);
				if (strcmp(pair, "boothowto"  ) == 0)
					boothowto   = strtoul(value, 0, 0);
			}
			else
				break;
		}
//.........这里部分代码省略.........
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:101,代码来源:nvram2env.c


示例2: osd_setenv

int osd_setenv(const char *name, const char *value, int overwrite)
{
	return setenv(name, value, overwrite);
}
开发者ID:DarrenBranford,项目名称:MAME4iOS,代码行数:4,代码来源:sdlos_os2.c


示例3: android_misc_flash_check

int android_misc_flash_check(void) {

	u32   misc_offset = 0;
	char  buffer[2048];

	misc_offset = (u32)sunxi_partition_get_offset_byname("misc");
	if(misc_offset == (u32)(-1))
	{
		puts("no misc partition is found\n");
		return 0;
	}	
	memset(buffer, 0, 2048);
#ifdef DEBUG
	printf("misc_offset  : %x\n", (int )misc_offset);
#endif
	sunxi_flash_read(misc_offset, 2048/512, buffer);
	memcpy(&misc_message, buffer, sizeof(misc_message));
#ifdef DEBUG
//	printf("misc.command  : %s\n", misc_message.command);
//	printf("misc.status   : %s\n", misc_message.status);
//	printf("misc.recovery : %s\n", misc_message.recovery);
#endif
	if(storage_type)
	{
		if(!strcmp(misc_message.command, "boot-recovery")) {
			/* there is a recovery command */
			puts("find boot recovery\n");
			setenv("bootcmd", "run setargs_mmc boot_recovery");
			puts("Recovery detected, will boot recovery\n");
			/* android recovery will clean the misc */
		}
		else{
			printf("bootcmd set setargs_mmc\n");
			setenv("bootcmd", "run setargs_mmc boot_normal");
		}
		if(!strcmp(misc_message.command, "boot-fastboot")) {
			/* there is a fastboot command */
			setenv("bootcmd", "run setargs_mmc boot_fastboot");
			puts("Fastboot detected, will enter fastboot\n");
			/* clean the misc partition ourself */
			memset(buffer, 0, 2048);
			sunxi_flash_write(misc_offset, 2048/512, buffer);
		}
	}
	else
	{
		if(!strcmp(misc_message.command, "boot-recovery")) {
			/* there is a recovery command */
			puts("find boot recovery\n");
			setenv("bootcmd", "run setargs_nand boot_recovery");
			puts("Recovery detected, will boot recovery\n");
			/* android recovery will clean the misc */
		}
        else
        if (!strcmp(misc_message.command, "usb-recovery")) {
		/* there is a recovery command */
		puts("find usb recovery\n");
		setenv("bootcmd", "run setargs_nand boot_recovery");
		puts("Recovery detected, will usb recovery\n");
		/* android recovery will clean the misc */
		}
		else{
			printf("bootcmd set setargs_nand\n");
			setenv("bootcmd", "run setargs_nand boot_normal");
		}

		if(!strcmp(misc_message.command, "boot-fastboot")) {
			/* there is a fastboot command */
			setenv("bootcmd", "run setargs_nand boot_fastboot");
			puts("Fastboot detected, will enter fastboot\n");
			/* clean the misc partition ourself */
			memset(buffer, 0, 2048);
			sunxi_flash_write(misc_offset, 2048/512, buffer);
		}
	}

	return 0;
}
开发者ID:tempbottle,项目名称:InDashNet.Open.UN2000,代码行数:78,代码来源:sun7i-evb.c


示例4: external_run_cmd

/* Run the command with op as command line argument(s) and return the exit
 * status + the output */
static int 
external_run_cmd(struct pluginDevice *sd, const char *op, char **output)
{
	const int		BUFF_LEN=4096;
	char			buff[BUFF_LEN];
	int			read_len = 0;
	int			status, rc;
	char * 			data = NULL;
	FILE *			file;
	char			cmd[FILENAME_MAX+64];
	struct stat		buf;
	int			slen;
	char *path, *new_path, *logtag, *savevar = NULL;
	int new_path_len, logtag_len;
	gboolean		nodata;

	rc = snprintf(cmd, FILENAME_MAX, "%s/%s", 
		STONITH_EXT_PLUGINDIR, sd->subplugin);
	if (rc <= 0 || rc >= FILENAME_MAX) {
		LOG(PIL_CRIT, "%s: external command too long.", __FUNCTION__);
		return -1;
	}
	
	if (stat(cmd, &buf) != 0) {
		LOG(PIL_CRIT, "%s: stat(2) of %s failed: %s",
			__FUNCTION__, cmd, strerror(errno));
                return -1;
        }

        if (!S_ISREG(buf.st_mode) 
	    || (!(buf.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))) {
		LOG(PIL_CRIT, "%s: %s found NOT to be executable.",
			__FUNCTION__, cmd);
		return -1;
	}

	if (buf.st_mode & (S_IWGRP|S_IWOTH)) {
		LOG(PIL_CRIT, "%s: %s found to be writable by group/others, "
			"NOT executing for security purposes.",
			__FUNCTION__, cmd);
		return -1;
	}

	strcat(cmd, " ");
	strcat(cmd, op);

	/* We only have a global environment to use here. So we add our
	 * options to it, and then later remove them again. */
	if (sd->cmd_opts) {
		g_hash_table_foreach(sd->cmd_opts, ext_add_to_env, NULL);
	}

	/* external plugins need path to ha_log.sh */
	path = getenv("PATH");
	if (strncmp(GLUE_SHARED_DIR,path,strlen(GLUE_SHARED_DIR))) {
		new_path_len = strlen(path)+strlen(GLUE_SHARED_DIR)+2;
		new_path = (char *)g_malloc(new_path_len);
		snprintf(new_path, new_path_len, "%s:%s", GLUE_SHARED_DIR, path);
		setenv("PATH", new_path, 1);
		g_free(new_path);
	}

	/* set the logtag appropriately */
	logtag_len = strlen(PIL_PLUGIN_S)+strlen(sd->subplugin)+2;
	logtag = (char *)g_malloc(logtag_len);
	snprintf(logtag, logtag_len, "%s/%s", PIL_PLUGIN_S, sd->subplugin);
	if (getenv(LOGTAG_VAR)) {
		savevar = g_strdup(getenv(LOGTAG_VAR));
	}
	setenv(LOGTAG_VAR, logtag, 1);
	g_free(logtag);

	if (Debug) {
		LOG(PIL_DEBUG, "%s: Calling '%s'", __FUNCTION__, cmd );
	}
	file = popen(cmd, "r");
	if (NULL==file) {
		LOG(PIL_CRIT, "%s: Calling '%s' failed",
			__FUNCTION__, cmd);
		rc = -1;
		goto out;
	}

	if (output) {
		slen=0;
		data = MALLOC(1);
		data[slen] = EOS;
	}
	while (!feof(file)) {
		nodata = TRUE;
		if (output) {
			read_len = fread(buff, 1, BUFF_LEN, file);
			if (read_len > 0) {
				data = REALLOC(data, slen+read_len+1);
				if (data == NULL) {
					break;
				}
				memcpy(data + slen, buff, read_len);
//.........这里部分代码省略.........
开发者ID:ingted,项目名称:cluster-glue,代码行数:101,代码来源:external.c


示例5: iucvtty_worker

/**
 * iucvtty_worker() - Handle an incoming client connection
 * @client:	Client file descriptor
 * @master:	PTY master file descriptor
 * @slave:	PTY slave file descriptor
 * @cfg:	IUCV TTY configuration structure.
 */
static int iucvtty_worker(int client, int master, int slave,
                          const struct iucvterm_cfg *cfg)
{
    int rc;
    struct iucvtty_msg *msg;
    pid_t child;
    fd_set set;
    size_t chunk;
    char term_env[TERM_BUFSIZE];


    /* flush pending terminal data */
    tcflush(master, TCIOFLUSH);

    /* read terminal parameters from client */
    if (iucvtty_rx_termenv(client, term_env, TERM_BUFSIZE))
        sprintf(term_env, TERM_DEFAULT);

    /* start login program */
    child = fork();
    if (child == -1) {
        print_error("Creating a new process to run the "
                    "login program failed");
        iucvtty_tx_error(client, ERR_FORK);
        return 1;	/* return from worker */
    }
    if (child == 0) {	/* child process */
        closelog();	/* close syslog */

        /* setup terminal */
        if (login_tty(slave)) {
            print_error("Setting up a terminal for user login failed");
            iucvtty_tx_error(client, ERR_SETUP_LOGIN_TTY);
            exit(2);
        }
        setenv("TERM", term_env, 1);
        if (exec_login_prog(cfg->cmd_parms)) {
            print_error("Running the login program failed");
            iucvtty_tx_error(client, ERR_CANNOT_EXEC_LOGIN);
        }
        exit(3);	/* we only reach here if exec has failed */
    }

    /* setup buffers */
    msg = malloc(MSG_BUFFER_SIZE);
    if (msg == NULL) {
        print_error("Allocating memory for the data buffer failed");
        rc = 2;
        goto out_kill_login;
    }

    /* multiplex i/o between login program and socket. */
    rc = 0;
    chunk = 0;
    while (!sig_shutdown) {
        FD_ZERO(&set);
        FD_SET(client, &set);
        FD_SET(master, &set);

        if (select(max(master, client) + 1, &set,
                   NULL, NULL, NULL) == -1) {
            if (errno == EINTR)
                continue;
            break;
        }

        if (FD_ISSET(client, &set)) {
            if (iucvtty_read_msg(client, msg,
                                 MSG_BUFFER_SIZE, &chunk))
                break;
            switch (msg->type) {
            case MSG_TYPE_DATA:
                iucvtty_copy_data(master, msg);
                break;
            case MSG_TYPE_WINSIZE:
                if (msg->datalen != sizeof(struct winsize))
                    break;
                if (ioctl(master, TIOCSWINSZ,
                          (struct winsize *) msg->data))
                    print_error("Resizing the terminal "
                                "window failed");
                break;
            case MSG_TYPE_TERMIOS:	/* ignored */
                break;
            case MSG_TYPE_ERROR:
                iucvtty_error(msg);
                break;
            }
        }

        if (FD_ISSET(master, &set))
            if (iucvtty_tx_data(client, master,
                                msg, MSG_BUFFER_SIZE))
//.........这里部分代码省略.........
开发者ID:hreinecke,项目名称:s390-tools,代码行数:101,代码来源:iucvtty.c


示例6: fatfsQry

static int
fatfsQry(char *fatfspath, int verbose)
{
	DIRENT de;
	DIRINFO di;
	char *lastslash, *fname, *dir, pathcopy[80], matchname[80];
	int flen, flen1, fsize, pathlen, match, ftot;

	if (!fatfspath)
		return(-1);

	/* Prior to each 'ls', clear the content of the name and
	 * size shell variables...
	 */
	setenv(FATFS_FNAME_STR,0);
	setenv(FATFS_FSIZE_STR,0);
	setenv(FATFS_FTOT_STR,0);

	pathlen = strlen(fatfspath);
	if (pathlen > sizeof(pathcopy)) {
		printf("path too big\n");
		return(-1);
	}
	strcpy(pathcopy, fatfspath);
	lastslash = strrchr(pathcopy,DIR_SEPARATOR);

	if (lastslash == 0) {
		dir = "";
		fname = pathcopy;
	}
	else {
		*lastslash = 0;
		dir = pathcopy;
		fname = lastslash+1;
	}

	flen = strlen(fname);
	if (verbose > 1)
		printf("Qry opening dir <%s>, fname <%s>...\n",dir,fname);

	di.scratch = sector;
	if (DFS_OpenDir(&vi, (uint8_t *)dir, &di)) {
		printf("error opening subdirectory\n");
		return(CMD_FAILURE);
	}

	match = fsize = ftot = flen1 = 0;
	while (!DFS_GetNext(&vi, &di, &de)) {
		int i;
		char dosname[16];

		memset(dosname,0,sizeof(dosname));
		if (de.name[0] && ((de.attr & ATTR_LONG_NAME) != ATTR_LONG_NAME)) {
			if ((de.attr & ATTR_VOLUME_ID) || (de.attr & ATTR_DIRECTORY)) {
				for(i=0;i<8;i++) {
					if (de.name[i] != ' ') {
						dosname[i] = de.name[i];
					}
					else {
						dosname[i] = 0;
						break;
					}
				}
				dosname[8] = 0;
			}
			else
				DFS_DirToCanonical((uint8_t *)dosname,de.name);
	
			flen1 = strlen(dosname);

			if ((fname[0] == '*') && (fname[flen-1] == '*')) {
				fname[flen-1] = 0;
				if (strstr(dosname,fname+1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (fname[0] == '*') {
				if (!strcmp(dosname+(flen1-flen+1),fname+1))
					match = 1;
			}
			else if (fname[flen-1] == '*') {
				fname[flen-1] = 0;
				if (!strncmp(dosname,fname,flen-1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (!strcmp(dosname,fname)) {
				match = 1;
			}
			if (match) {
				strcpy(matchname,dosname);
				fsize = FILESIZE(de);
				ftot++;
				match = 0;
				if (verbose)
					printf("  %s (%d)\n",dosname,fsize);
			}
		}
	}
	shell_sprintf(FATFS_FTOT_STR,"%d",ftot);
//.........这里部分代码省略.........
开发者ID:Pedersen175,项目名称:DAN-uMon,代码行数:101,代码来源:fatfs.c


示例7: runPipeCommand

int runPipeCommand(Command c){
	int i, j;
  pid_t pid;
  int in, fd [2];
	pid_t *pidList = (pid_t *) malloc(sizeof(pid_t) * c.commandc);

	setenv("PATH", envPaths, 1);

	/* original file descriptor 0. (not pipe) */
  in = 0;

  for (i = 0; i < c.commandc; ++i)
    {
      pipe(fd);

			Argument a = c.commandv[i];

			glob_t globBuffer;
			int matchCount=0;

			for(j = 0; j < a.argc; j++){
				char *newArgv = a.argv[j];
				if(matchCount == 0)
					glob(newArgv, GLOB_NOCHECK, NULL , &globBuffer );
				else
					glob(newArgv, GLOB_NOCHECK|GLOB_APPEND, NULL , &globBuffer );
				matchCount = globBuffer.gl_pathc;
			}

			if(i < c.commandc - 1){
	      pidList[i] = executeCommand(in, fd[1], globBuffer.gl_pathv);

	      close(fd[1]);
	      in = fd[0];
			}
			else{
				 if ((pidList[i] = fork ()) == 0){
			       if (in != 0){
			           dup2 (in, 0);
			       }
						 setSignal(1);
			       execvp (*globBuffer.gl_pathv, globBuffer.gl_pathv);
						 handleErrno(errno, globBuffer.gl_pathv[0]);
			   }
				 else{
					 int status;
					 int isHandledSuspension = 0;

					 for(j=0; j< 2; j++)
					  	close(fd[j]);

					 for(j=0; j<c.commandc; j++){
	 					  waitpid(pidList[j], &status, WUNTRACED);
							//printf("status: %d\n", status);
						 if(WIFSTOPPED(status)){
							 	if(!isHandledSuspension){
							  	printf("\n");
									suspendProcesses(pidList, c.commandc);
						      jobsNewNode(pidList, c.command, c.commandc);
									isHandledSuspension = 1;
								}
								//printf("%d: WIFSTOPPED - suspended by signal\n", pid);

							}
							else if(WIFSIGNALED(status)){
								if(!isHandledSuspension){
									printf("\n");
									isHandledSuspension = 1;
								}
								//printf("%d: WIFSIGNALED - terminated by signals\n", pid);
							}
							else if(WIFEXITED(status)){
								isHandledSuspension = 1;
								//printf("%d: WIFEXITED - terminated normally\n", pid);
							}
						}
				 }
			}



			globfree(&globBuffer);
    }

}
开发者ID:hei1682004,项目名称:chris-come-to-hug-me,代码行数:85,代码来源:command.c


示例8: test_unit_printf

static int test_unit_printf(void) {
        Manager *m;
        Unit *u, *u2;
        int r;

        _cleanup_free_ char *mid, *bid, *host, *root_uid;
        struct passwd *root;

        assert_se((mid = specifier_machine_id('m', NULL, NULL)));
        assert_se((bid = specifier_boot_id('b', NULL, NULL)));
        assert_se((host = gethostname_malloc()));

        assert_se((root = getpwnam("root")));
        assert_se(asprintf(&root_uid, "%d", (int) root->pw_uid) > 0);

        r = manager_new(SYSTEMD_USER, false, &m);
        if (r == -EPERM || r == -EACCES) {
                puts("manager_new: Permission denied. Skipping test.");
                return EXIT_TEST_SKIP;
        }
        assert(r == 0);

#define expect(unit, pattern, expected)                                 \
        {                                                               \
                char *e;                                                \
                _cleanup_free_ char *t =                                \
                        unit_full_printf(unit, pattern);                \
                printf("result: %s\nexpect: %s\n", t, expected);        \
                if ((e = endswith(expected, "*")))                      \
                        assert(strncmp(t, e, e-expected));              \
                else                                                    \
                        assert(streq(t, expected));                     \
        }

        assert_se(setenv("USER", "root", 1) == 0);
        assert_se(setenv("HOME", "/root", 1) == 0);

        assert_se(u = unit_new(m, sizeof(Service)));
        assert_se(unit_add_name(u, "blah.service") == 0);
        assert_se(unit_add_name(u, "blah.service") == 0);

        /* general tests */
        expect(u, "%%", "%");
        expect(u, "%%s", "%s");
        expect(u, "%", "");    // REALLY?

        /* normal unit */
        expect(u, "%n", "blah.service");
        expect(u, "%N", "blah");
        expect(u, "%p", "blah");
        expect(u, "%P", "blah");
        expect(u, "%i", "");
        expect(u, "%I", "");
        expect(u, "%u", root->pw_name);
        expect(u, "%U", root_uid);
        expect(u, "%h", root->pw_dir);
        expect(u, "%s", "/bin/sh");
        expect(u, "%m", mid);
        expect(u, "%b", bid);
        expect(u, "%H", host);
        expect(u, "%t", "/run/user/*");

        /* templated */
        assert_se(u2 = unit_new(m, sizeof(Service)));
        assert_se(unit_add_name(u2, "[email protected]") == 0);
        assert_se(unit_add_name(u2, "[email protected]") == 0);

        expect(u2, "%n", "[email protected]");
        expect(u2, "%N", "[email protected]");
        expect(u2, "%p", "blah");
        expect(u2, "%P", "blah");
        expect(u2, "%i", "foo-foo");
        expect(u2, "%I", "foo/foo");
        expect(u2, "%u", root->pw_name);
        expect(u2, "%U", root_uid);
        expect(u2, "%h", root->pw_dir);
        expect(u2, "%s", "/bin/sh");
        expect(u2, "%m", mid);
        expect(u2, "%b", bid);
        expect(u2, "%H", host);
        expect(u2, "%t", "/run/user/*");

        manager_free(m);

        return 0;
}
开发者ID:ZeFeaR,项目名称:systemd,代码行数:86,代码来源:test-unit-name.c


示例9: main

int
main (void)
{
    unsigned int i;
    int fail = 0;
    char curr_year_str[30];
    struct tm *tm;
    time_t t_now;
    int err;
    size_t n_bytes;

    /* The above test data requires Universal Time, e.g., TZ="UTC0".  */
    err = setenv ("TZ", "UTC0", 1);
    ASSERT (err == 0);

    t_now = time (NULL);
    ASSERT (t_now != (time_t) -1);
    tm = localtime (&t_now);
    ASSERT (tm);
    n_bytes = strftime (curr_year_str, sizeof curr_year_str, "%Y", tm);
    ASSERT (0 < n_bytes);

    for (i = 0; T[i].in; i++)
    {
        time_t t_out;
        time_t t_exp = T[i].t_expected;
        bool ok;

        /* Some tests assume that time_t is signed.
           If it is unsigned and the result is negative, skip the test. */
        if (T[i].t_expected < 0 && ! TYPE_SIGNED (time_t))
        {
            printf ("skipping %s: result is negative, "
                    "but your time_t is unsigned\n", T[i].in);
            continue;
        }

        if (T[i].valid && t_exp != T[i].t_expected)
        {
            printf ("skipping %s: result is out of range of your time_t\n",
                    T[i].in);
            continue;
        }

        /* If an input string does not specify the year number, determine
           the expected output by calling posixtime with an otherwise
           equivalent string that starts with the current year.  */
        if (8 <= strlen (T[i].in)
                && (T[i].in[8] == '.' || T[i].in[8] == '\0'))
        {
            char tmp_buf[20];
            stpcpy (stpcpy (tmp_buf, curr_year_str), T[i].in);
            ASSERT (posixtime (&t_exp, tmp_buf, T[i].syntax_bits));
        }

        ok = posixtime (&t_out, T[i].in, T[i].syntax_bits);
        if (ok != !!T[i].valid)
        {
            printf ("%s return value mismatch: got %d, expected %d\n",
                    T[i].in, !!ok, T[i].valid);
            fail = 1;
            continue;
        }

        if (!ok)
            continue;

        if (t_out != t_exp)
        {
            printf ("%s mismatch (-: actual; +:expected)\n-%12ld\n+%12ld\n",
                    T[i].in, t_out, t_exp);
            fail = 1;
        }
    }

    return fail;
}
开发者ID:ystk,项目名称:debian-gnulib,代码行数:77,代码来源:test-posixtm.c


示例10: main

int main(int argc, char **argv)
{
        SaHpiSessionIdT sid = 0;
        char *config_file = NULL;
        oHpiHandlerIdT hid0, hid1, hid2, hid3;
        GHashTable *h0 = g_hash_table_new(g_str_hash, g_str_equal),
                   *h1 = g_hash_table_new(g_str_hash, g_str_equal),
                   *h2 = g_hash_table_new(g_str_hash, g_str_equal),
                   *h3 = g_hash_table_new(g_str_hash, g_str_equal);
        
        /* Save config file env variable and unset it */
        config_file = getenv("OPENHPI_CONF");
        setenv("OPENHPI_CONF","./noconfig", 1);
        
        if (saHpiSessionOpen(1, &sid, NULL))
                return -1;
                    
        /* Load plugins */
        if (oHpiPluginLoad("libdummy"))
                return -1;
                
        if (oHpiPluginLoad("libwatchdog"))
                return -1;
                
        /* Set configuration for handlers and create them. */
        g_hash_table_insert(h0, "plugin", "libdummy");
        g_hash_table_insert(h0, "entity_root", "{SYSTEM_CHASSIS,1}");
        g_hash_table_insert(h0, "name", "test0");
        g_hash_table_insert(h0, "addr", "0");
        
        g_hash_table_insert(h1, "plugin", "libdummy");
        g_hash_table_insert(h1, "entity_root", "{SYSTEM_CHASSIS,2}");
        g_hash_table_insert(h1, "name", "test1");
        g_hash_table_insert(h1, "addr", "1");
        
        /* Set configuration for two handlers and create them. */
        g_hash_table_insert(h2, "plugin", "libwatchdog");
        g_hash_table_insert(h2, "entity_root", "{SYSTEM_CHASSIS,3}");
        g_hash_table_insert(h2, "addr", "0");
        
        g_hash_table_insert(h3, "plugin", "libwatchdog");
        g_hash_table_insert(h3, "entity_root", "{SYSTEM_CHASSIS,4}");
        g_hash_table_insert(h3, "addr", "1");
        
        if (oHpiHandlerCreate(h0,&hid0) || oHpiHandlerCreate(h1,&hid1))
                return -1;
                
        if (oHpiHandlerCreate(h2,&hid2) || oHpiHandlerCreate(h3,&hid3))
                return -1;
                
        if (oHpiHandlerDestroy(hid0) || oHpiHandlerDestroy(hid1))
                return -1;
                
        if (oHpiHandlerDestroy(hid2) || oHpiHandlerDestroy(hid3))
                return -1;
                
        if (oHpiPluginUnload("libdummy") || oHpiPluginUnload("libwatchdog"))
                return -1;
                
        /* Restore config file env variable */
        setenv("OPENHPI_CONF",config_file,1);                           
        
        return 0;
}
开发者ID:openhpi1,项目名称:testrepo,代码行数:64,代码来源:ohpi_008.c


示例11: strdup

char *get_cgi_filename() /* and fixup environment */
{
	int buflen = 1, docrootlen;
	char *buf = NULL;
	char *docroot, *scriptname, *p;

	int rf_len;
	char *pathinfo = NULL;

	if ((p = getenv("SCRIPT_FILENAME"))) {
		return strdup(p);
	}

	if ((p = getenv("DOCUMENT_ROOT"))) {
		docroot = p;
		docrootlen = strlen(p);
		buflen += docrootlen;
	} else {
		goto err;
	}

	if ((p = getenv("SCRIPT_NAME"))) {
		buflen += strlen(p);
		scriptname = p;
	} else {
		goto err;
	}

	buf = malloc(buflen);
	if (!buf) goto err;

	strcpy(buf, docroot);
	strcpy(buf + docrootlen, scriptname);
	pathinfo = strdup(buf);
	if (!pathinfo) {
		goto err;
	}

	while(1) {
		switch(check_file_perms(buf)) {
			case -EACCES:
				goto err;
			case 0:
				rf_len = strlen(buf);
				if (rf_len < buflen - 1) {
					setenv("PATH_INFO", pathinfo + rf_len, 1);
					setenv("SCRIPT_NAME", buf + docrootlen, 1);
				} else {
					unsetenv("PATH_INFO");
				}
				free(pathinfo);
				return buf;
			default:
				p = strrchr(buf, '/');
				if (!p) goto err;
				*p = 0;
		}
	}

err:
	free(pathinfo);
	free(buf);
	return NULL;
}
开发者ID:acieroid,项目名称:fcgiwrap,代码行数:64,代码来源:fcgiwrap.c


示例12: InstallFiles


//.........这里部分代码省略.........
        ProggWindow.AddText("");
        ProggWindow.AddText(CreateText("</B/29>%s:<!29!B>", GetTranslation("Status")));
        ProggWindow.AddText(CreateText("%s (%d/%d)", GetTranslation((*it)->description.c_str()), step,
                            InstallInfo.command_entries.size()+1), true, BOTTOM, 24);

        ProgressBar.Draw();
        
        std::string command = (*it)->command + " " + GetParameters(*it);
        InstallOutput.AddText("");
        InstallOutput.AddText(CreateText("Execute: %s", command.c_str()));
        InstallOutput.AddText("");
        InstallOutput.AddText("");
        
        if (((*it)->need_root == NEED_ROOT) || alwaysroot)
        {
            SuHandler.SetPath((*it)->path.c_str());
            SuHandler.SetCommand(command);
            if (!SuHandler.ExecuteCommand(passwd))
            {
                if ((*it)->exit_on_failure)
                {
                    CleanPasswdString(passwd);
                    passwd = NULL;
                    throwerror(true, "%s\n('%s')", GetTranslation("Failed to execute install command"),
                               SuHandler.GetErrorMsgC());
                }
            }
        }
        else
        {
            // Redirect stderr to stdout, so that errors will be displayed too
            command += " 2>&1";
            
            setenv("PATH", (*it)->path.c_str(), 1);
            FILE *pipe = popen(command.c_str(), "r");
            char term[1024];
            if (pipe)
            {
                while (fgets(term, sizeof(term), pipe))
                {
                    InstallOutput.AddText(term);

                    chtype input = getch();
                    if (input == 'c') /*injectCDKSwindow(InstallOutput.GetSWin(), input);*/
                    {
                        if (YesNoBox(GetTranslation("Install commands are still running\n"
                                                    "If you abort now this may lead to a broken installation\n"
                                                    "Are you sure?")))
                        {
                            CleanPasswdString(passwd);
                            passwd = NULL;
                            EndProg();
                        }
                    }
                }
                
                // Check if command exitted normally and close pipe
                int state = pclose(pipe);
                if (!WIFEXITED(state) || (WEXITSTATUS(state) == 127)) // SH returns 127 if command execution failes
                {
                    if ((*it)->exit_on_failure)
                    {
                        CleanPasswdString(passwd);
                        passwd = NULL;
                        throwerror(true, "Failed to execute install command");
                    }
开发者ID:BackupTheBerlios,项目名称:nixstaller-svn,代码行数:67,代码来源:ncurs.cpp


示例13: graph_init_video

int graph_init_video(void)
{
  int 	rc = 0;
	int   screen_colours;
	vga_modeinfo *vminfo;
	
	if (tcgetpgrp(STDIN_FILENO) != getpid())
	{	fprintf(stderr, "Sorry, this application cannot start in background\n");
		return 0;
	}

	pltf = PLTF_SVGA;

  /*-----------------------------------------------------------*/     
	/* Checking libvga version, 1.4.0 and prior will return (-1) */
	/* Currently you need IOPERM for 1.9.x to run as a non-priv  */
	/* user, however set IOPERM upsets upsets previous versions  */
  /*-----------------------------------------------------------*/     
  if (vga_setmode(-1) >= 0x1900)	setenv("IOPERM", "1", 0);  

	rc = vga_init();
	if (rc != 0)
	{ fprintf(stderr, "Can't initialise SVGA library. \n"
     		    "Possible solution: log as root, and enter:\n"
		    "\tchown 0 ifrac\n"
		    "\tchmod 4755 ifrac\n");
	  return 0;
	}	

#ifdef SVGALIB_BACKGROUND_SUPPORT
  set_background_routines();
#else
	run_background = 0;
#endif

	if (!set_video_mode())
	{  fprintf(stderr, "Sorry, unable to set video mode. \n");
      	   return 0;		
	}

	vminfo = vga_getmodeinfo(vga_getcurrentmode());
	
	WndWidth = ScrWidth = vminfo->width;
	WndHeight = ScrHeight = vminfo->height;

	screen_colours = vminfo->colors;
	if (screen_colours < 16)
	{	fprintf (stderr,
		   "This application requires at least 16-colour mode\n");
		return 0;
	}	 

	ScrDepth = 0;
	while((screen_colours>>=1) != 0) ScrDepth++;

	if (ScrDepth <= 8)
	{  BytesPerPixel = 1;
	   stored_colours = 1;
	}
	else
	{  BytesPerPixel = vminfo->bytesperpixel;
	   stored_colours = 0;
	}
	
	scan_line_width = vminfo->linewidth;
	screen_size = scan_line_width * ScrHeight;

	if (ScrDepth < 8) 
		DirVideo = 0;
	else {
		vga_setpage(screen_page=0);

		if (DirVideo == 2 && (vminfo->flags & CAPABLE_LINEAR)) 
			lbuf_len = vga_setlinearaddressing();
	
		if (DirVideo > 0) 
			lbuf_addr = vga_getgraphmem();
	}
	
	return  1;
}
开发者ID:clemej,项目名称:ifrac,代码行数:81,代码来源:ifr_sgraph.c


示例14: execute

static int execute(struct sockaddr *addr)
{
	static char line[1000];
	int pktlen, len, i;

	if (addr) {
		char addrbuf[256] = "";
		int port = -1;

		if (addr->sa_family == AF_INET) {
			struct sockaddr_in *sin_addr = (void *) addr;
			inet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf));
			port = ntohs(sin_addr->sin_port);
#ifndef NO_IPV6
		} else if (addr && addr->sa_family == AF_INET6) {
			struct sockaddr_in6 *sin6_addr = (void *) addr;

			char *buf = addrbuf;
			*buf++ = '['; *buf = '\0'; /* stpcpy() is cool */
			inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1);
			strcat(buf, "]");

			port = ntohs(sin6_addr->sin6_port);
#endif
		}
		loginfo("Connection from %s:%d", addrbuf, port);
		setenv("REMOTE_ADDR", addrbuf, 1);
	}
	else {
		unsetenv("REMOTE_ADDR");
	}

	alarm(init_timeout ? init_timeout : timeout);
	pktlen = packet_read_line(0, line, sizeof(line));
	alarm(0);

	len = strlen(line);
	if (pktlen != len)
		loginfo("Extended attributes (%d bytes) exist <%.*s>",
			(int) pktlen - len,
			(int) pktlen - len, line + len + 1);
	if (len && line[len-1] == '\n') {
		line[--len] = 0;
		pktlen--;
	}

	free(hostname);
	free(canon_hostname);
	free(ip_address);
	free(tcp_port);
	hostname = canon_hostname = ip_address = tcp_port = NULL;

	if (len != pktlen)
		parse_extra_args(line + len + 1, pktlen - len - 1);

	for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
		struct daemon_service *s = &(daemon_service[i]);
		int namelen = strlen(s->name);
		if (!prefixcmp(line, "git-") &&
		    !strncmp(s->name, line + 4, namelen) &&
		    line[namelen + 4] == ' ') {
			/*
			 * Note: The directory here is probably context sensitive,
			 * and might depend on the actual service being performed.
			 */
			return run_service(line + namelen + 5, s);
		}
	}

	logerror("Protocol error: '%s'", line);
	return -1;
}
开发者ID:joeo,项目名称:fut,代码行数:72,代码来源:daemon.c


示例15: main

int main(int argc, char **argv)
{
        LsiConfig config = { 0 };
        bool is_x86_64;
        const char *n_argv[argc + 2];
        const char *exec_command = NULL;
        int i = 1;
        int8_t off = 0;
        int (*vfunc)(const char *, char *const argv[]) = NULL;

        /* Initialise config */
        if (!lsi_config_load(&config)) {
                lsi_config_load_defaults(&config);
        }

        is_x86_64 = lsi_system_is_64bit();

        if (!lsi_file_exists(STEAM_BINARY)) {
                lsi_report_failure("Steam isn't currently installed at %s", STEAM_BINARY);
                return EXIT_FAILURE;
        }

        /* Force STEAM_RUNTIME into the environment */
        if (config.use_native_runtime) {
                /* Explicitly disable the runtime */
                setenv("STEAM_RUNTIME", "0", 1);
        } else {
                /* Only preload when needed. */
                if (lsi_system_requires_preload()) {
                        setenv("LD_PRELOAD", lsi_preload_list(), 1);
                }
                setenv("STEAM_RUNTIME", "1", 1);
        }

        /* Vanilla dbus users suffer a segfault on Steam exit, due to incorrect
         * usage of dbus by Steam. Help them out */
        setenv("DBUS_FATAL_WARNINGS", "0", 1);

        memset(&n_argv, 0, sizeof(char *) * (argc + 2));

        /* If we're 64-bit and 32-bit is forced, proxy via linux32 */
        if (config.force_32 && is_x86_64) {
                exec_command = EMUL32BIN;
                n_argv[0] = EMUL32BIN;
                n_argv[1] = STEAM_BINARY;
                off = 1;
                /* Use linux32 in the path */
                vfunc = execvp;
        } else {
                /* Directly call STEAM_BINARY */
                exec_command = STEAM_BINARY;
                n_argv[0] = STEAM_BINARY;
                /* Full path here due to shadow nature */
                vfunc = execv;
        }

        /* Point arguments to arguments passed to us */
        for (i = 1; i < argc; i++) {
                n_argv[i + off] = argv[i];
        }
        n_argv[i + 1 + off] = NULL;

        /* Go execute steam. */
        if (vfunc(exec_command, (char **)n_argv) < 0) {
                lsi_report_failure("Failed to launch Steam: %s [%s]",
                                   strerror(errno),
                                   STEAM_BINARY);
                return EXIT_FAILURE;
        }
}
开发者ID:philipzae,项目名称:linux-steam-integration,代码行数:70,代码来源:shim.c


示例16: main

int main(int argc, char *argv[]) {
	int rc, i;

	pid_t pid  = -1;
	pid_t ppid = getpid();

	uid_t uid = -1;
	gid_t gid = -1;

	_free_ char *user   = NULL;
	_free_ char *dest   = NULL;
	_free_ char *change = NULL;
	_free_ char *env    = NULL;
	_free_ char *cgroup = NULL;

	_close_ int master_fd = -1;

	char *master_name;

	int detach  = 0;
	int keepenv = 0;

	siginfo_t status;

	while ((rc = getopt_long(argc, argv, short_opts, long_opts, &i)) !=-1) {
		switch (rc) {
			case 'm':
				validate_optlist("--mount", optarg);

				add_mount_from_spec(optarg);
				break;

			case 'n':
				clone_flags |= CLONE_NEWNET;

				if (optarg != NULL) {
					validate_optlist("--netif", optarg);

					add_netif_from_spec(optarg);
				}
				break;

			case 'u':
				clone_flags |= CLONE_NEWUSER;

				freep(&user);

				user = strdup(optarg);
				break;

			case 'r':
				freep(&dest);

				dest = realpath(optarg, NULL);
				if (dest == NULL) sysf_printf("realpath()");
				break;

			case 'c':
				freep(&change);

				change = strdup(optarg);
				break;

			case 'g':
				validate_optlist("--cgroup", optarg);
				validate_cgroup_spec(optarg);

				freep(&change);

				cgroup = strdup(optarg);
				break;

			case 'd':
				detach = 1;
				break;

			case 'a': {
				char *end = NULL;
				pid = strtol(optarg, &end, 10);
				if (*end != '\0')
					fail_printf("Invalid value '%s' for --attach", optarg);
				break;
			}

			case 's': {
				validate_optlist("--setenv", optarg);

				if (env != NULL) {
					char *tmp = env;

					rc = asprintf(&env, "%s,%s", env, optarg);
					if (rc < 0) fail_printf("OOM");

					freep(&tmp);
				} else {
					env = strdup(optarg);
				}

				break;
			}
//.........这里部分代码省略.........
开发者ID:stangelandcl,项目名称:pflask,代码行数:101,代码来源:pflask.c


示例17: switch_boot_mode


//.........这里部分代码省略.........
				memset(addr,0,sizeof(addr));
				sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
				printf("efuse mac is : %s \n", addr);
				//setenv ("ethaddr", addr);
				barg_addr = getenv ("bootargs");
				sprintf(bootargs,"set bootargs '%s mac=%s'",barg_addr,addr);
				run_command (bootargs, 0);
			}
		#endif
        run_command ("save", 0);
        
        upgrade_partition();
        return  1;
    }
#endif
	
		//add by steven for version info
		char verubt[64],verrec[64];
		char *r_verubt,*r_verrec;
		const char* pVer = 0x82000020;
		const unsigned int* pMark = 0x8200005c;
		
		r_verubt = getenv("verubt");
		r_verrec = getenv("verrec");
		sprintf(verubt,"%s(%s.%s)",U_BOOT_VERSION,U_BOOT_DATE,U_BOOT_TIME);
		
		run_command("sf probe 0;sf read 82000000 40000 1000;",0);
		if(*pMark==0xbc690000)
		{
			sprintf(verrec,"%s",pVer);
		}
				
		if(strcmp(r_verubt,verubt) || strcmp(r_verrec,verrec)){
			setenv("verubt",verubt);
			if(*pMark==0xbc690000){
				setenv("verrec",verrec);
			}
			run_command("sav",0);
		}
		//end: add by steven for version info
		
		
#ifdef CONFIG_EFUSE //add by steven for mac in efuse.
		char *barg_addr;
		char *r_efus,*r_emac;
		char addr[20];
		
		r_emac = getenv ("emac");		
		if((efuse_chk_written(2)) && (strcmp(r_emac,"efuse")==0)){
			r_efus = efuse_read_usr(2);
			memset(addr,0,sizeof(addr));
			sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
			printf("efuse mac is : %s \n", addr);
			setenv ("ethaddr", addr);
			run_command("sav",0);
		}
#endif
		
    saradc_enable();

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
开发者ID:Doxlon,项目名称:buildroot-uboot,代码行数:67,代码来源:stv_mbx_ref.c


示例18: misc_init_r


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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