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

C++ chdir函数代码示例

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

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



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

示例1: platform_setCurrentWorkingDir

void platform_setCurrentWorkingDir(const char *path)
{
    chdir(path);
}
开发者ID:JoshEngebretson,项目名称:TinyLS,代码行数:4,代码来源:platformFile.c


示例2: send_message

int send_message(char * msg, char * from, char ** recipients, int num_recipients)
{
    /*	...Adds Date:
    	...Adds Message-Id:*/
    int r;
    int wstat;
    int i;
    struct tm * dt;
    unsigned long msgwhen;
    FILE * fdm;
    FILE * fde;
    pid_t pid;
    int pim[2];				/*message pipe*/
    int pie[2];				/*envelope pipe*/
    FILE *mfp;
    char msg_buffer[256];

    /*open a pipe to qmail-queue*/
    if(pipe(pim)==-1 || pipe(pie)==-1) {
        return -1;
    }
    pid = vfork();
    if(pid == -1) {
        /*failure*/
        return -1;
    }
    if(pid == 0) {
        /*I am the child*/
        close(pim[1]);
        close(pie[1]);
        /*switch the pipes to fd 0 and 1
          pim[0] goes to 0 (stdin)...the message*/
        if(fcntl(pim[0],F_GETFL,0) == -1) {
            /*			fprintf(stderr,"Failure getting status flags.\n");*/
            _exit(120);
        }
        close(0);
        if(fcntl(pim[0],F_DUPFD,0)==-1) {
            /*			fprintf(stderr,"Failure duplicating file descriptor.\n");*/
            _exit(120);
        }
        close(pim[0]);
        /*pie[0] goes to 1 (stdout)*/
        if(fcntl(pie[0],F_GETFL,0) == -1) {
            /*			fprintf(stderr,"Failure getting status flags.\n");*/
            _exit(120);
        }
        close(1);
        if(fcntl(pie[0],F_DUPFD,1)==-1) {
            /*			fprintf(stderr,"Failure duplicating file descriptor.\n");*/
            _exit(120);
        }
        close(pie[0]);
        if(chdir(QMAIL_LOCATION) == -1) {
            _exit(120);
        }
        execv(*binqqargs,binqqargs);
        _exit(120);
    }

    /*I am the parent*/
    fdm = fdopen(pim[1],"wb");					/*updating*/
    fde = fdopen(pie[1],"wb");
    if(fdm==NULL || fde==NULL) {
        return -1;
    }
    close(pim[0]);
    close(pie[0]);

    /*prepare to add date and message-id*/
    msgwhen = time(NULL);
    dt = gmtime((long *)&msgwhen);
    /*start outputting to qmail-queue
      date is in 822 format
      message-id could be computed a little better*/
    fprintf(fdm,"Date: %u %s %u %02u:%02u:%02u -0000\nMessage-ID: <%lu.%u.blah>\n"
            ,dt->tm_mday,montab[dt->tm_mon],dt->tm_year+1900,dt->tm_hour,dt->tm_min,dt->tm_sec,msgwhen,getpid() );

    mfp = fopen( msg, "rb" );

    while ( fgets( msg_buffer, sizeof(msg_buffer), mfp ) != NULL )
    {
        fprintf(fdm,"%s",msg_buffer);
    }

    fclose(mfp);

    fclose(fdm);


    /*send the envelopes*/

    fprintf(fde,"F%s",from);
    fwrite("",1,1,fde);					/*write a null char*/
    for(i=0; i<num_recipients; i++) {
        fprintf(fde,"T%s",recipients[i]);
        fwrite("",1,1,fde);					/*write a null char*/
    }
    fwrite("",1,1,fde);					/*write a null char*/
    fclose(fde);
//.........这里部分代码省略.........
开发者ID:debdungeon,项目名称:qint,代码行数:101,代码来源:autorespond.c


示例3: rm_r

int
rm_r(const char *path)
{
	int ret = 0;
	DIR *dir;
	struct dirent *dent;

	if (path == NULL) {
		opkg_perror(ERROR, "Missing directory parameter");
		return -1;
	}

	dir = opendir(path);
	if (dir == NULL) {
		opkg_perror(ERROR, "Failed to open dir %s", path);
		return -1;
	}

	if (fchdir(dirfd(dir)) == -1) {
		opkg_perror(ERROR, "Failed to change to dir %s", path);
		closedir(dir);
		return -1;
	}

	while (1) {
		errno = 0;
		if ((dent = readdir(dir)) == NULL) {
			if (errno) {
				opkg_perror(ERROR, "Failed to read dir %s",
						path);
				ret = -1;
			}
			break;
		}

		if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
			continue;

#ifdef _BSD_SOURCE
		if (dent->d_type == DT_DIR) {
			if ((ret = rm_r(dent->d_name)) == -1)
				break;
			continue;
		} else if (dent->d_type == DT_UNKNOWN)
#endif
		{
			struct stat st;
			if ((ret = lstat(dent->d_name, &st)) == -1) {
				opkg_perror(ERROR, "Failed to lstat %s",
						dent->d_name);
				break;
			}
			if (S_ISDIR(st.st_mode)) {
				if ((ret = rm_r(dent->d_name)) == -1)
					break;
				continue;
			}
		}

		if ((ret = unlink(dent->d_name)) == -1) {
			opkg_perror(ERROR, "Failed to unlink %s", dent->d_name);
			break;
		}
	}

	if (chdir("..") == -1) {
		ret = -1;
		opkg_perror(ERROR, "Failed to change to dir %s/..", path);
	}

	if (rmdir(path) == -1 ) {
		ret = -1;
		opkg_perror(ERROR, "Failed to remove dir %s", path);
	}

	if (closedir(dir) == -1) {
		ret = -1;
		opkg_perror(ERROR, "Failed to close dir %s", path);
	}

	return ret;
}
开发者ID:23171580,项目名称:firmware-tools,代码行数:82,代码来源:file_util.c


示例4: InitNx

void InitNx()
{
    // Create the physics SDK
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &gErrorStream);
    if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);	
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_AXES, 1);

	gPhysicsSDK->setParameter(NX_VISUALIZE_CONTACT_POINT, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_CONTACT_NORMAL, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
	sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
 if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	NxU32 set = 0;

#ifdef WIN32
	set = SetCurrentDirectory(&fname[0]);
	if (!set) set = SetCurrentDirectory(&fname1[0]);
	if (!set)
	{
		char basePath[256];
		GetModuleFileName(NULL, basePath, 256);
		char* pTmp = strrchr(basePath, '\\');
		basePath[pTmp-basePath+1] = 0;
		SetCurrentDirectory(basePath);//for running from start menu

		set = SetCurrentDirectory(&fname2[0]);
	}
	if (!set) set = SetCurrentDirectory(&fname3[0]);
#elif LINUX
	set = chdir(&fname[0]);
	if (set != 0) set = chdir(&fname2[0]);
	if (set != 0) set = chdir(&fname3[0]);
#endif

	// Create the default material
	NxMaterialDesc defaultMaterial;
	defaultMaterial.restitution		= 0;
	defaultMaterial.staticFriction	= 0.5;
	defaultMaterial.dynamicFriction	= 0.5;
	NxMaterial* m = gScene->getMaterialFromIndex(0);
	m->loadFromDesc(defaultMaterial);

	// Load the ramp scene
	char buffer[512];
	FindMediaFile("Ramp.pml", buffer);
	nxmlLoadScene(buffer, gPhysicsSDK, gScene);

	// Switch from Max Coordinate System to
	// Training Program Coordinate System
	NxMat34 mat;
    NxMat33 orient;
	orient.setColumn(0, NxVec3(-1,0,0));
	orient.setColumn(1, NxVec3(0,0,1));
	orient.setColumn(2, NxVec3(0,1,0));
	mat.M = orient;
	SwitchCoordinateSystem(gScene, mat);

	// Reset wheel material
	wsm = NULL;

	// Create board actor
	board = CreateBoard(NxVec3(0,3,0));
	board->wakeUp(1e30);

    AddUserDataToActors(gScene);

	gSelectedActor = board;

	// Initialize HUD
	InitializeHUD();
	InitializeSpecialHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
开发者ID:daher-alfawares,项目名称:xr.desktop,代码行数:95,代码来源:Lesson702.cpp


示例5: main


//.........这里部分代码省略.........
		case 'v':
			version();
			break;
		case 'c':
			configtest = 1;
			break;
		case 's':
			singleprocess = 1;
			break;
		case 'h':
			usage();
#ifdef HAVE_GETOPT_LONG
		case ':':
			fprintf(stderr, "%s: option %s: parameter expected\n", pname,
				prog_opt[opt_idx].name);
			exit(1);
#endif
		case '?':
			exit(1);
		}
	}

	if (chrootdir) {
		if (!username) {
			fprintf(stderr, "Chroot as root is not safe, exiting\n");
			exit(1);
		}

		if (chroot(chrootdir) == -1) {
			perror("chroot");
			exit (1);
		}

		if (chdir("/") == -1) {
			perror("chdir");
			exit (1);
		}
		/* username will be switched later */
	}

	if (configtest) {
		log_method = L_STDERR;
	}

	if (log_open(log_method, pname, logfile, facility) < 0) {
		perror("log_open");
		exit(1);
	}

	if (!configtest) {
		flog(LOG_INFO, "version %s started", "1.8");
	}

	/* get a raw socket for sending and receiving ICMPv6 messages */
	sock = open_icmpv6_socket();
	if (sock < 0) {
		perror("open_icmpv6_socket");
		exit(1);
	}

#ifndef BRCM_CMS_BUILD //brcm
	/* check that 'other' cannot write the file
         * for non-root, also that self/own group can't either
         */
	if (check_conffile_perm(username, conf_file) < 0) {
		if (get_debuglevel() == 0) {
开发者ID:antonywcl,项目名称:AR-5315u_PLD,代码行数:67,代码来源:radvd.c


示例6: pmix_compress_bzip_decompress_nb

int pmix_compress_bzip_decompress_nb(char * cname, char **fname, pid_t *child_pid)
{
    char **argv = NULL;
    char * dir_cname = NULL;
    pid_t loc_pid = 0;
    int status;
    bool is_tar = false;

    if( 0 == strncmp(&(cname[strlen(cname)-8]), ".tar.bz2", strlen(".tar.bz2")) ) {
        is_tar = true;
    }

    *fname = strdup(cname);
    if( is_tar ) {
        (*fname)[strlen(cname)-8] = '\0';
    } else {
        (*fname)[strlen(cname)-4] = '\0';
    }

    pmix_output_verbose(10, mca_compress_bzip_component.super.output_handle,
                        "compress:bzip: decompress_nb(%s -> [%s])",
                        cname, *fname);

    *child_pid = fork();
    if( *child_pid == 0 ) { /* Child */
        dir_cname  = pmix_dirname(cname);

        chdir(dir_cname);

        /* Fork(bunzip) */
        loc_pid = fork();
        if( loc_pid == 0 ) { /* Child */
            char * cmd;
            pmix_asprintf(&cmd, "bunzip2 %s", cname);

            pmix_output_verbose(10, mca_compress_bzip_component.super.output_handle,
                                "compress:bzip: decompress_nb() command [%s]",
                                cmd);

            argv = pmix_argv_split(cmd, ' ');
            status = execvp(argv[0], argv);

            pmix_output(0, "compress:bzip: decompress_nb: Failed to exec child [%s] status = %d\n", cmd, status);
            exit(PMIX_ERROR);
        }
        else if( loc_pid > 0 ) { /* Parent */
            waitpid(loc_pid, &status, 0);
            if( !WIFEXITED(status) ) {
                pmix_output(0, "compress:bzip: decompress_nb: Failed to bunzip the file [%s] status = %d\n", cname, status);
                exit(PMIX_ERROR);
            }
        }
        else {
            exit(PMIX_ERROR);
        }

        /* tar_decompress */
        if( is_tar ) {
            /* Strip off '.bz2' leaving just '.tar' */
            cname[strlen(cname)-4] = '\0';
            pmix_compress_base_tar_extract(&cname);
        }

        /* Once this child is done, then directly exit */
        exit(PMIX_SUCCESS);
    }
    else if( *child_pid > 0 ) {
        ;
    }
    else {
        return PMIX_ERROR;
    }

    return PMIX_SUCCESS;
}
开发者ID:jjhursey,项目名称:pmix-master,代码行数:75,代码来源:compress_bzip_module.c


示例7: usrAppInit

void usrAppInit (void)
{
    int status;
    char srcPath[0xff+1];
    /*
     * Step 1: create ramdisk
     */
    status = addRamDisk(ASP_RAMDISK_SIZE, ASP_RAMDISK_DEVICE);
    if(status == ERROR)
    {
        printf("Unable to create ramdisk [%s] with [%d] blocks. Error [%s]\n", 
               ASP_RAMDISK_DEVICE, ASP_RAMDISK_SIZE, strerror(errno));
        return;
    }
    /*
     * Step 2: nfs mount
     */
    status = nfsMount(ASP_NFS_HOST, ASP_NFS_MOUNT_POINT, ASP_RUNTIME_DIR);
    if(status == ERROR)
    {
        printf("Unable to mount [%s] from nfs server [%s]. Error [%s]\n", 
               ASP_NFS_MOUNT_POINT, ASP_NFS_HOST, strerror(errno));
        return ;
    }
    /*
     * Step 3: copy asp loader to ramdisk and change directory to ramdisk. before spawning ASP loader
     */
    snprintf(srcPath, sizeof(srcPath), "%s/%s", ASP_RUNTIME_DIR, ASP_LOADER_IMAGE);
    if(cp(srcPath, ASP_RAMDISK_DEVICE) == ERROR)
    {
        printf("Unable to copy [%s] to [%s]. Error [%s]\n", 
               srcPath, ASP_RAMDISK_DEVICE, strerror(errno));
        return;
    }
    /*
     * Change directory to ramdisk. 
     */
    printf("Changing directory to %s\n\n", ASP_RAMDISK_DEVICE);
    if(chdir(ASP_RAMDISK_DEVICE) == ERROR)
    {
        printf("Unable to change directory to [%s]. Error [%s]\n\n", 
               ASP_RAMDISK_DEVICE, strerror(errno));
    }
    else
    {
        int rtpId = 0;
        char aspImage[0xff+1];
        const char *args[] = { 
            ASP_LOADER_IMAGE, "-c", "0", "-l", ASP_SLOT_ID, "-n", ASP_NODE_NAME, 
            "-s", ASP_RAMDISK_DEVICE, ASP_RUNTIME_DIR, NULL 
        };
        snprintf(aspImage, sizeof(aspImage), "%s/%s", ASP_RAMDISK_DEVICE, ASP_LOADER_IMAGE);
        printf("Starting ASP...\n\n");
        rtpId = rtpSpawn(aspImage, (const char **)args, NULL, 100, 256<<10, 0, VX_FP_TASK);
        if(rtpId == ERROR)
        {
            printf("Unable to spawn image [%s]. Error [%s]\n", aspImage, strerror(errno));
        }
        else
            printf("rtpSpawn for image [%s] success\n", aspImage);
    }
}
开发者ID:AlbertZheng,项目名称:SAFplus-Availability-Scalability-Platform,代码行数:62,代码来源:usrAppInit.c


示例8: ar_open

int
ar_open(const char *name)
{
	struct mtget mb;

	if (arfd != -1)
		(void)close(arfd);
	arfd = -1;
	can_unlnk = did_io = io_ok = invld_rec = 0;
	artyp = ISREG;
	flcnt = 0;

	/*
	 * open based on overall operation mode
	 */
	switch (act) {
	case LIST:
	case EXTRACT:
		if (name == NULL) {
			arfd = STDIN_FILENO;
			arcname = stdn;
		} else if ((arfd = open(name, EXT_MODE, DMOD)) < 0)
			syswarn(0, errno, "Failed open to read on %s", name);
		if (arfd != -1 && gzip_program != NULL)
			ar_start_gzip(arfd, gzip_program, 0);
		break;
	case ARCHIVE:
		if (name == NULL) {
			arfd = STDOUT_FILENO;
			arcname = stdo;
		} else if ((arfd = open(name, AR_MODE, DMOD)) < 0)
			syswarn(0, errno, "Failed open to write on %s", name);
		else
			can_unlnk = 1;
		if (arfd != -1 && gzip_program != NULL)
			ar_start_gzip(arfd, gzip_program, 1);
		break;
	case APPND:
		if (name == NULL) {
			arfd = STDOUT_FILENO;
			arcname = stdo;
		} else if ((arfd = open(name, APP_MODE, DMOD)) < 0)
			syswarn(0, errno, "Failed open to read/write on %s",
				name);
		break;
	case COPY:
		/*
		 * arfd not used in COPY mode
		 */
		arcname = none;
		lstrval = 1;
		return(0);
	}
	if (arfd < 0)
		return(-1);

	if (chdname != NULL)
		if (chdir(chdname) != 0) {
			syswarn(1, errno, "Failed chdir to %s", chdname);
			return(-1);
		}
	/*
	 * set up is based on device type
	 */
	if (fstat(arfd, &arsb) < 0) {
		syswarn(0, errno, "Failed stat on %s", arcname);
		(void)close(arfd);
		arfd = -1;
		can_unlnk = 0;
		return(-1);
	}
	if (S_ISDIR(arsb.st_mode)) {
		paxwarn(0, "Cannot write an archive on top of a directory %s",
		    arcname);
		(void)close(arfd);
		arfd = -1;
		can_unlnk = 0;
		return(-1);
	}

	if (S_ISCHR(arsb.st_mode))
		artyp = ioctl(arfd, MTIOCGET, &mb) ? ISCHR : ISTAPE;
	else if (S_ISBLK(arsb.st_mode))
		artyp = ISBLK;
	else if ((lseek(arfd, (off_t)0L, SEEK_CUR) == -1) && (errno == ESPIPE))
		artyp = ISPIPE;
	else
		artyp = ISREG;

	/*
	 * make sure we beyond any doubt that we only can unlink regular files
	 * we created
	 */
	if (artyp != ISREG)
		can_unlnk = 0;
	/*
	 * if we are writing, we are done
	 */
	if (act == ARCHIVE) {
		blksz = rdblksz = wrblksz;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:ramrodminix-svn,代码行数:101,代码来源:ar_io.c


示例9: trace_listen

void trace_listen(int argc, char **argv)
{
	char *logfile = NULL;
	char *port = NULL;
	char *iface;
	int daemon = 0;
	int c;

	if (argc < 2)
		usage(argv);

	if (strcmp(argv[1], "listen") != 0)
		usage(argv);

	for (;;) {
		int option_index = 0;
		static struct option long_options[] = {
			{"port", required_argument, NULL, 'p'},
			{"help", no_argument, NULL, '?'},
			{"debug", no_argument, NULL, OPT_debug},
			{NULL, 0, NULL, 0}
		};

		c = getopt_long (argc-1, argv+1, "+hp:o:d:i:l:D",
			long_options, &option_index);
		if (c == -1)
			break;
		switch (c) {
		case 'h':
			usage(argv);
			break;
		case 'p':
			port = optarg;
			break;
		case 'i':
			iface = optarg;
			break;
		case 'd':
			output_dir = optarg;
			break;
		case 'o':
			output_file = optarg;
			break;
		case 'l':
			logfile = optarg;
			break;
		case 'D':
			daemon = 1;
			break;
		case OPT_debug:
			debug = 1;
			break;
		default:
			usage(argv);
		}
	}

	if (!port)
		usage(argv);

	if ((argc - optind) >= 2)
		usage(argv);

	if (!output_file)
		output_file = default_output_file;

	if (!output_dir)
		output_dir = default_output_dir;

	if (logfile) {
		/* set the writes to a logfile instead */
		logfp = fopen(logfile, "w");
		if (!logfp)
			die("creating log file %s", logfile);
	}

	if (chdir(output_dir) < 0)
		die("Can't access directory %s", output_dir);

	if (daemon)
		start_daemon();

	signal_setup(SIGINT, finish);
	signal_setup(SIGTERM, finish);

	do_listen(port);

	return;
}
开发者ID:ericmiao,项目名称:trace-cmd,代码行数:89,代码来源:trace-listen.c


示例10: get_grid_info_and_install


//.........这里部分代码省略.........
    MYSQL_ROW row = NULL;
    int  ret = db_conn->select_first_row(&row, select_sql);
    if(ret < 0) {
        fprintf(stderr, "%sQuery db error.\nSQL:[%s] db error:[%s].%s\n",
                START_RED_TIP, select_sql, db_conn->get_last_errstr(), END_COLOR_TIP);
        return -1;
    }
    else if(ret == 0) {
        fprintf(stderr, "%sNo record satisfied the conditions.\nSQL:[%s]%s\n",
                START_RED_TIP, select_sql, END_COLOR_TIP);
        return -1;
    }

    int   exist = -1;
    char  ch  = 0;
    while(row != NULL) {
        if(!row[0]) {
            goto next;
        }

        strcat(install_path, "oa-head-");
        strcat(install_path, row[0]);

        if(check_dir(install_path, &exist) != 0) {
            fprintf(stderr, "OA_HEAD for grid %s%s %sinstall failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
            goto next;
        }

        if(exist) {
            fprintf(stderr, 
                    "The OA_HEAD for grid %s%s %salready exist%s.\n%sDo you want to overwrite it?[Y|N]", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP, START_GREEN_TIP);
            ch = get_yes_no_input(3);
            if(ch != 'Y' && ch != 'y') {
                goto next;
            }
        }

        chmod(install_path, 0755);
        chown(install_path, g_nobody_uid, g_nobody_gid);

        sprintf(cmd_str, "rm -rf %s/* ;cp -rf ./install-pkg/* %s", install_path, install_path);
        if(system(cmd_str) == -1) {
            fprintf(stderr, "Copy file to [%s] failed.\n", install_path);
            fprintf(stderr, "OA_HEAD for grid %s%s%s install failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
            goto next;
        }

        sprintf(file_path, "%s/start_oa_head.sh", install_path);
        fp = fopen(file_path, "a");
        if(fp == NULL) {
            fprintf(stderr, "Open file %s failed,sys error:%s.\n", file_path, strerror(errno));
            fprintf(stderr, "OA_HEAD for grid %s%s%s install failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
            goto next;
        }

        len = sprintf(cmd_str, "./oa_head -h%s -d%s -u%s -p%s -n%s \nexit 0\n", 
                g_db_host, g_db_name, g_db_user, g_db_pass, row[0]);
        if(fwrite(cmd_str, 1, strlen(cmd_str), fp) != strlen(cmd_str)) {
            fprintf(stderr, "Modify file %s failed.\n", file_path);
            fprintf(stderr, "OA_HEAD for grid %s%s%s install failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
            fclose(fp);
            goto next;
        }
        fclose(fp);

        sprintf(cmd_str, "chown nobody.nogroup -R %s/*", install_path);
        if(system(cmd_str) == -1) {
            fprintf(stderr, "Chown failed.\n");
            fprintf(stderr, "OA_HEAD for grid %s%s%s install failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
            goto next;
        }

        fprintf(stderr, "OA_HEAD for grid %s%s%s installed success.%s\nDo you want to start it[Y/N]?", 
                START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
        ch = 0;
        ch = get_yes_no_input(3);
        if(ch != 'Y' && ch != 'y')
            goto next;

        chdir(install_path);
        if(system("./start_oa_head.sh") == -1) {
            fprintf(stderr, "Start failed.\n");
            fprintf(stderr, "OA_HEAD for grid %s%s%s start failed.%s\n", 
                    START_RED_TIP, row[0], START_YELLOW_TIP, END_COLOR_TIP);
        }
        chdir(g_cur_path);
next:
        usleep(900000);
        fprintf(stderr, "\n");
        strncpy(install_path, g_install_prefix, sizeof(install_path));
        row = db_conn->select_next_row(false);
    }
    return 0;
}
开发者ID:Zhanyin,项目名称:taomee,代码行数:101,代码来源:main.cpp


示例11: control

pid_t
control(void)
{
	struct sockaddr_un	 sun;
	int			 fd;
	mode_t			 old_umask;
	pid_t			 pid;
	struct passwd		*pw;
	struct event		 ev_sigint;
	struct event		 ev_sigterm;

	switch (pid = fork()) {
	case -1:
		fatal("control: cannot fork");
	case 0:
		break;
	default:
		return (pid);
	}

	purge_config(PURGE_EVERYTHING);

	pw = env->sc_pw;

	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
		fatal("control: socket");

	bzero(&sun, sizeof(sun));
	sun.sun_family = AF_UNIX;
	if (strlcpy(sun.sun_path, SMTPD_SOCKET,
	    sizeof(sun.sun_path)) >= sizeof(sun.sun_path))
		fatal("control: socket name too long");

	if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0)
		fatalx("control socket already listening");

	if (unlink(SMTPD_SOCKET) == -1)
		if (errno != ENOENT)
			fatal("control: cannot unlink socket");

	old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
	if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
		(void)umask(old_umask);
		fatal("control: bind");
	}
	(void)umask(old_umask);

	if (chmod(SMTPD_SOCKET,
		S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) {
		(void)unlink(SMTPD_SOCKET);
		fatal("control: chmod");
	}

	session_socket_blockmode(fd, BM_NONBLOCK);
	control_state.fd = fd;

	stat_backend = env->sc_stat;
	stat_backend->init();

	if (chroot(PATH_CHROOT) == -1)
		fatal("control: chroot");
	if (chdir("/") == -1)
		fatal("control: chdir(\"/\")");

	config_process(PROC_CONTROL);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("control: cannot drop privileges");

	imsg_callback = control_imsg;
	event_init();

	signal_set(&ev_sigint, SIGINT, control_sig_handler, NULL);
	signal_set(&ev_sigterm, SIGTERM, control_sig_handler, NULL);
	signal_add(&ev_sigint, NULL);
	signal_add(&ev_sigterm, NULL);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);

	tree_init(&ctl_conns);

	bzero(&digest, sizeof digest);
	digest.startup = time(NULL);

	config_peer(PROC_SCHEDULER);
	config_peer(PROC_QUEUE);
	config_peer(PROC_SMTP);
	config_peer(PROC_MFA);
	config_peer(PROC_PARENT);
	config_peer(PROC_LKA);
	config_peer(PROC_MDA);
	config_peer(PROC_MTA);
	config_done();

	control_listen();

	if (event_dispatch() < 0)
		fatal("event_dispatch");
//.........这里部分代码省略.........
开发者ID:galdor,项目名称:OpenSMTPD,代码行数:101,代码来源:control.c


示例12: main

int
main(int argc, char *argv[]) 
{
  const char *base_uri = "http://example.org/bpath/cpath/d;p?querystr#frag";
  const char *base_uri_xmlbase = "http://example.org/bpath/cpath/d;p";
  const char *base_uri_retrievable = "http://example.org/bpath/cpath/d;p?querystr";
  const char* dirs[6] = { "/etc", "/bin", "/tmp", "/lib", "/var", NULL };
  unsigned char uri_buffer[16]; /* strlen("file:///DIR/foo")+1 */  
  int i;
  const char *dir;
  unsigned char *str;
  raptor_uri *uri1, *uri2, *uri3;

  int failures=0;
  
  fprintf(stderr, "raptor_uri_resolve_uri_reference: Testing with base URI %s\n", base_uri);
  

  failures += assert_resolve_uri (base_uri, "g:h", "g:h");
  failures += assert_resolve_uri (base_uri, "gpath", "http://example.org/bpath/cpath/gpath");
  failures += assert_resolve_uri (base_uri, "./gpath", "http://example.org/bpath/cpath/gpath");
  failures += assert_resolve_uri (base_uri, "gpath/", "http://example.org/bpath/cpath/gpath/");
  failures += assert_resolve_uri (base_uri, "/gpath", "http://example.org/gpath");
  failures += assert_resolve_uri (base_uri, "//gpath", "http://gpath");
  failures += assert_resolve_uri (base_uri, "?y", "http://example.org/bpath/cpath/?y");
  failures += assert_resolve_uri (base_uri, "gpath?y", "http://example.org/bpath/cpath/gpath?y");
  failures += assert_resolve_uri (base_uri, "#s", "http://example.org/bpath/cpath/d;p?querystr#s");
  failures += assert_resolve_uri (base_uri, "gpath#s", "http://example.org/bpath/cpath/gpath#s");
  failures += assert_resolve_uri (base_uri, "gpath?y#s", "http://example.org/bpath/cpath/gpath?y#s");
  failures += assert_resolve_uri (base_uri, ";x", "http://example.org/bpath/cpath/;x");
  failures += assert_resolve_uri (base_uri, "gpath;x", "http://example.org/bpath/cpath/gpath;x");
  failures += assert_resolve_uri (base_uri, "gpath;x?y#s", "http://example.org/bpath/cpath/gpath;x?y#s");
  failures += assert_resolve_uri (base_uri, ".", "http://example.org/bpath/cpath/");
  failures += assert_resolve_uri (base_uri, "./", "http://example.org/bpath/cpath/");
  failures += assert_resolve_uri (base_uri, "..", "http://example.org/bpath/");
  failures += assert_resolve_uri (base_uri, "../", "http://example.org/bpath/");
  failures += assert_resolve_uri (base_uri, "../gpath", "http://example.org/bpath/gpath");
  failures += assert_resolve_uri (base_uri, "../..", "http://example.org/");
  failures += assert_resolve_uri (base_uri, "../../", "http://example.org/");
  failures += assert_resolve_uri (base_uri, "../../gpath", "http://example.org/gpath");

  failures += assert_resolve_uri (base_uri, "", "http://example.org/bpath/cpath/d;p?querystr");

  failures += assert_resolve_uri (base_uri, "../../../gpath", "http://example.org/../gpath");
  failures += assert_resolve_uri (base_uri, "../../../../gpath", "http://example.org/../../gpath");

  failures += assert_resolve_uri (base_uri, "/./gpath", "http://example.org/./gpath");
  failures += assert_resolve_uri (base_uri, "/../gpath", "http://example.org/../gpath");
  failures += assert_resolve_uri (base_uri, "gpath.", "http://example.org/bpath/cpath/gpath.");
  failures += assert_resolve_uri (base_uri, ".gpath", "http://example.org/bpath/cpath/.gpath");
  failures += assert_resolve_uri (base_uri, "gpath..", "http://example.org/bpath/cpath/gpath..");
  failures += assert_resolve_uri (base_uri, "..gpath", "http://example.org/bpath/cpath/..gpath");

  failures += assert_resolve_uri (base_uri, "./../gpath", "http://example.org/bpath/gpath");
  failures += assert_resolve_uri (base_uri, "./gpath/.", "http://example.org/bpath/cpath/gpath/");
  failures += assert_resolve_uri (base_uri, "gpath/./hpath", "http://example.org/bpath/cpath/gpath/hpath");
  failures += assert_resolve_uri (base_uri, "gpath/../hpath", "http://example.org/bpath/cpath/hpath");
  failures += assert_resolve_uri (base_uri, "gpath;x=1/./y", "http://example.org/bpath/cpath/gpath;x=1/y");
  failures += assert_resolve_uri (base_uri, "gpath;x=1/../y", "http://example.org/bpath/cpath/y");

  failures += assert_resolve_uri (base_uri, "gpath?y/./x", "http://example.org/bpath/cpath/gpath?y/./x");
  failures += assert_resolve_uri (base_uri, "gpath?y/../x", "http://example.org/bpath/cpath/gpath?y/../x");
  failures += assert_resolve_uri (base_uri, "gpath#s/./x", "http://example.org/bpath/cpath/gpath#s/./x");
  failures += assert_resolve_uri (base_uri, "gpath#s/../x", "http://example.org/bpath/cpath/gpath#s/../x");

  failures += assert_resolve_uri (base_uri, "http:gauthority", "http:gauthority");

  failures += assert_resolve_uri (base_uri, "gpath/../../../hpath", "http://example.org/hpath");

  failures += assert_resolve_uri ("http://example.org/dir/file", "../../../absfile", "http://example.org/../../absfile");
  failures += assert_resolve_uri ("http://example.org/dir/file", "http://another.example.org/dir/file", "http://another.example.org/dir/file");


#ifdef WIN32
  failures += assert_filename_to_uri ("c:\\windows\\system", "file://c|/windows/system");
  failures += assert_filename_to_uri ("\\\\server\\share\\file.doc", "file://server/share/file.doc");
  failures += assert_filename_to_uri ("a:foo", "file://a|./foo");


  failures += assert_uri_to_filename ("file://c|/windows/system", "c:\\windows\\system");
  failures += assert_uri_to_filename ("file://c:/windows/system", "c:\\windows\\system");
  failures += assert_uri_to_filename ("file://server/share/file.doc", "\\\\server\\share\\file.doc");
  failures += assert_uri_to_filename ("file://a|./foo", "a:foo");
#else

  failures += assert_filename_to_uri ("/path/to/file", "file:///path/to/file");
  failures += assert_uri_to_filename ("file:///path/to/file", "/path/to/file");

#if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_STAT_H)
  /* Need to test this with a real dir (preferably not /)
   * This is just a test so pretty likely to work on all development systems
   * that are not WIN32
   */

  for(i=0; (dir=dirs[i]); i++) {
    struct stat buf;
    if(!lstat(dir, &buf) && S_ISDIR(buf.st_mode) && !S_ISLNK(buf.st_mode)) {
      if(!chdir(dir))
        break;
    }
//.........这里部分代码省略.........
开发者ID:stefanhusmann,项目名称:Amaya,代码行数:101,代码来源:raptor_uri.c


示例13: ngx_worker_process_init


//.........这里部分代码省略.........
            ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
                          "initgroups(%s, %d) failed",
                          ccf->username, ccf->group);
        }

        if (setuid(ccf->user) == -1) {
            ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
                          "setuid(%d) failed", ccf->user);
            /* fatal */
            exit(2);
        }
    }

    if (worker >= 0) {
        cpu_affinity = ngx_get_cpu_affinity(worker);

        if (cpu_affinity) {
            ngx_setaffinity(cpu_affinity, cycle->log);
        }
    }

#if (NGX_HAVE_PR_SET_DUMPABLE)

    /* allow coredump after setuid() in Linux 2.4.x */

    if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
                      "prctl(PR_SET_DUMPABLE) failed");
    }

#endif

    if (ccf->working_directory.len) {
        if (chdir((char *) ccf->working_directory.data) == -1) {
            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
                          "chdir(\"%s\") failed", ccf->working_directory.data);
            /* fatal */
            exit(2);
        }
    }

    sigemptyset(&set);

    if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
                      "sigprocmask() failed");
    }

    /*
     * disable deleting previous events for the listening sockets because
     * in the worker processes there are no events at all at this point
     */
    ls = cycle->listening.elts;
    for (i = 0; i < cycle->listening.nelts; i++) {
        ls[i].previous = NULL;
    }

    for (i = 0; ngx_modules[i]; i++) {
        if (ngx_modules[i]->init_process) {
            if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
                /* fatal */
                exit(2);
            }
        }
    }
开发者ID:RechardTheGrey,项目名称:nginx_noting,代码行数:66,代码来源:ngx_process_cycle.c


示例14: while


//.........这里部分代码省略.........
					/*cout << tempnode[i][edges[i][j].nodes.first].coordinate.first << " " << tempnode[i][edges[i][j].nodes.second].coordinate.first << endl;
					cout << tempnode[i][edges[i][j].nodes.first].coordinate.second << " " << tempnode[i][edges[i][j].nodes.second].coordinate.second << endl;
					cout << minp[0] << " " << maxp[0] << endl;
					cout << minp[1] << " " << maxp[1] << endl;*/
					//getchar();
				}
				else if(edges[i][j].HV == 'V'){
					minp[1] += 1;
					maxp[1] -= 1;
				}
				if(edges[i][j].HV != 'N'){
					edge_rtree[i]->Insert(minp, maxp, j);
				}
			}
		}
		//cout << "Rtree done !" << endl;
		/*int minp[2], maxp[2];
		minp[0] = 17;
		minp[1] = 0;
		maxp[0] = 17;
		maxp[1] = 4;
		vector <int> edge_list;
		for( int i=0;i<channel_layer;i++ ){
			edge_list.clear();
			edge_rtree[i]->Search(minp, maxp, &edge_list);
			for( int k=0;k<edge_list.size();k++ ){
				cout << tempnode[i][edges[i][edge_list[k]].nodes.first].coordinate.first << " " << tempnode[i][edges[i][edge_list[k]].nodes.first].coordinate.second << endl;
				cout << tempnode[i][edges[i][edge_list[k]].nodes.second].coordinate.first << " " << tempnode[i][edges[i][edge_list[k]].nodes.second].coordinate.second << endl;
			}
			cout << edge_list.size() << endl;
		}
		getchar();*/
		
		chdir("3d-ice/bin/");
		string simulator = "./3D-ICE-Emulator test_case_0";
		simulator += chip.case_num + 48;
		simulator += ".stk";
		for( int i=0;i<channel_layer;i++ ){
			simulator += " ../../network_";
			simulator += i+48;
			simulator += " ../../flowrate_";
			simulator += i+48;
			simulator += " ../../direction_";
			simulator += i+48;
		}
		//cout << simulator << endl;
		system(simulator.c_str());
		//getchar();
		
		chdir("../../");
		ifstream *fin = new ifstream[channel_layer+1];
		vector < vector < vector <double> > > T_map;
		double T_max = 0, T_min = 1<<30;
		pair<int, int> target;
		for( int i=0;i<channel_layer+1;i++ ){
			string file_location = "3d-ice/bin/testcase_0";
			vector < vector <double> > temp_T_map(101, vector <double>(101));
			file_location += chip.case_num+48;
			file_location += "/output_";
			file_location += i+48;
			file_location += ".txt";
			cout << file_location << endl;
			
			fin[i].open(file_location.c_str());
			if(fin[i].eof()){
				cout << "error tmap !" << endl;
开发者ID:ICCAD,项目名称:network,代码行数:67,代码来源:network_gen.cpp


示例15: command_change_directory

void command_change_directory(int fd, char * dir) {
    chdir(dir);
}
开发者ID:ashawnbandy,项目名称:cecs472,代码行数:3,代码来源:browserd_mod.c


示例16: main


//.........这里部分代码省略.........
				if (numthreads == -1) {
					usage(argv[0]);
					return (1);
				}
				break;
			case 'N':
				stalone = 1;
				break;
			default:
				usage(argv[0]);
				return (1);
		}
	}

	(void)strcpy(daemonname, "[email protected]");
	(void)strcat(daemonname, name);
	if ((pc = strchr(daemonname, (int)'.')) != NULL)
		*pc = '\0';

	if(set_msgdaemonname(daemonname)) {
		fprintf(stderr, "Out of memory\n");
		return 1;
	}



	(void) snprintf(path_log, sizeof(path_log), "%s/%s", pbs_conf.pbs_home_path, PBS_COMM_LOGDIR);
	(void) log_open(log_file, path_log);

	/* set tcp function pointers */
	set_tpp_funcs(log_tppmsg);

	(void) snprintf(svr_home, sizeof(svr_home), "%s/%s", pbs_conf.pbs_home_path, PBS_SVR_PRIVATE);
	if (chdir(svr_home) != 0) {
		(void) sprintf(log_buffer, msg_init_chdir, svr_home);
		log_err(-1, __func__, log_buffer);
		return (1);
	}

	(void) sprintf(lockfile, "%s/%s/comm.lock", pbs_conf.pbs_home_path, PBS_SVR_PRIVATE);
	if ((are_primary = are_we_primary()) == FAILOVER_SECONDARY) {
		strcat(lockfile, ".secondary");
	} else if (are_primary == FAILOVER_CONFIG_ERROR) {
		sprintf(log_buffer, "Failover configuration error");
		log_err(-1, __func__, log_buffer);
#ifdef WIN32
		g_dwCurrentState = SERVICE_STOPPED;
		ss.dwCurrentState = g_dwCurrentState;
		ss.dwWin32ExitCode = ERROR_SERVICE_NOT_ACTIVE;
		if (g_ssHandle != 0) SetServiceStatus(g_ssHandle, &ss);
#endif
		return (3);
	}

	if ((lockfds = open(lockfile, O_CREAT | O_WRONLY, 0600)) < 0) {
		(void) sprintf(log_buffer, "pbs_comm: unable to open lock file");
		log_err(errno, __func__, log_buffer);
		return (1);
	}

	if ((host = tpp_parse_hostname(name, &port)) == NULL) {
		sprintf(log_buffer, "Out of memory parsing leaf name");
		log_err(errno, __func__, log_buffer);
		return (1);
	}
开发者ID:A9-William,项目名称:pbspro,代码行数:66,代码来源:pbs_comm.c


示例17: main


//.........这里部分代码省略.........
#endif

#ifndef OS_IS_WIN32
        pa_close(0);
        pa_close(1);
        pa_close(2);

        pa_assert_se(open("/dev/null", O_RDONLY) == 0);
        pa_assert_se(open("/dev/null", O_WRONLY) == 1);
        pa_assert_se(open("/dev/null", O_WRONLY) == 2);
#else
        FreeConsole();
#endif

#ifdef SIGTTOU
        signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
        signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
        signal(SIGTSTP, SIG_IGN);
#endif

#ifdef TIOCNOTTY
        if ((tty_fd = open("/dev/tty", O_RDWR)) >= 0) {
            ioctl(tty_fd, TIOCNOTTY, (char*) 0);
            pa_assert_se(pa_close(tty_fd) == 0);
        }
#endif
    }

    pa_set_env_and_record("PULSE_INTERNAL", "1");
    pa_assert_se(chdir("/") == 0);
    umask(0022);

#ifdef HAVE_SYS_RESOURCE_H
    set_all_rlimits(conf);
#endif
    pa_rtclock_hrtimer_enable();

    pa_raise_priority(conf->nice_level);

    if (conf->system_instance)
        if (change_user() < 0)
            goto finish;

    pa_set_env_and_record("PULSE_SYSTEM", conf->system_instance ? "1" : "0");

    pa_log_info(_("This is PulseAudio %s"), PACKAGE_VERSION);
    pa_log_debug(_("Compilation host: %s"), CANONICAL_HOST);
    pa_log_debug(_("Compilation CFLAGS: %s"), PA_CFLAGS);

    s = pa_uname_string();
    pa_log_debug(_("Running on host: %s"), s);
    pa_xfree(s);

    pa_log_debug(_("Found %u CPUs."), pa_ncpus());

    pa_log_info(_("Page size is %lu bytes"), (unsigned long) PA_PAGE_SIZE);

#ifdef HAVE_VALGRIND_MEMCHECK_H
    pa_log_debug(_("Compiled with Valgrind support: yes"));
#else
    pa_log_debug(_("Compiled with Valgrind support: no"));
#endif
开发者ID:jctemkin,项目名称:xen-audio,代码行数:67,代码来源:main.c


示例18: comando_mudadir


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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