Esempio n. 1
0
int
dochdir(const char *name)
{
	if (chdir(name) == -1)
		syswarn(1, errno, "Cannot chdir to `%s'", name);
	return updatepath();
}
Esempio n. 2
0
int
fdochdir(int fcwd)
{
	if (fchdir(fcwd) == -1) {
		syswarn(1, errno, "Cannot chdir to `.'");
		return -1;
	}
	return updatepath();
}
Esempio n. 3
0
static int
fdochroot(int fcwd)
{
	if (fchroot(fcwd) != 0) {
		syswarn(1, errno, "Can't fchroot to \".\"");
		return -1;
	}
	return updatepath();
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
	char *tmpdir;
	size_t tdlen;

	listf = stderr;
	/*
	 * Keep a reference to cwd, so we can always come back home.
	 */
	cwdfd = open(".", O_RDONLY);
	if (cwdfd < 0) {
		syswarn(1, errno, "Can't open current working directory.");
		return(exit_val);
	}

	if (updatepath() == -1)
		return exit_val;
	/*
	 * Where should we put temporary files?
	 */
	if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
		tmpdir = _PATH_TMP;
	tdlen = strlen(tmpdir);
	while (tdlen > 0 && tmpdir[tdlen - 1] == '/')
		tdlen--;
	tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE));
	if (tempfile == NULL) {
		paxwarn(1, "Cannot allocate memory for temp file name.");
		return(exit_val);
	}
	if (tdlen)
		memcpy(tempfile, tmpdir, tdlen);
	tempbase = tempfile + tdlen;
	*tempbase++ = '/';

	/*
	 * parse options, determine operational mode, general init
	 */
	options(argc, argv);
	if ((gen_init() < 0) || (tty_init() < 0))
		return(exit_val);

	/*
	 * select a primary operation mode
	 */
	switch (act) {
	case EXTRACT:
		extract();
		break;
	case ARCHIVE:
		archive();
		break;
	case APPND:
		if (gzip_program != NULL)
			errx(1, "can not gzip while appending");
		append();
		break;
	case COPY:
		copy();
		break;
	default:
	case LIST:
		list();
		break;
	}
	return(exit_val);
}
Esempio n. 5
0
int
main(int argc, char **argv)
{
	const char *tmpdir;
	size_t tdlen;
	int rval;

	setprogname(argv[0]);

	listf = stderr;

	/*
	 * parse options, determine operational mode
	 */
	options(argc, argv);

	/*
	 * general init
	 */
	if ((gen_init() < 0) || (tty_init() < 0))
		return exit_val;

	/*
	 * Keep a reference to cwd, so we can always come back home.
	 */
	cwdfd = open(".", O_RDONLY);
	if (cwdfd < 0) {
		syswarn(1, errno, "Can't open current working directory.");
		return exit_val;
	}
	if (updatepath() == -1)
		return exit_val;

	/*
	 * Where should we put temporary files?
	 */
	if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
		tmpdir = _PATH_TMP;
	tdlen = strlen(tmpdir);
	while(tdlen > 0 && tmpdir[tdlen - 1] == '/')
		tdlen--;
	tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE));
	if (tempfile == NULL) {
		tty_warn(1, "Cannot allocate memory for temp file name.");
		return exit_val;
	}
	if (tdlen)
		memcpy(tempfile, tmpdir, tdlen);
	tempbase = tempfile + tdlen;
	*tempbase++ = '/';

	(void)time(&starttime);
#ifdef SIGINFO
	(void)signal(SIGINFO, ar_summary);
#endif
	/*
	 * select a primary operation mode
	 */
	switch (act) {
	case EXTRACT:
		rval = extract();
		break;
	case ARCHIVE:
		rval = archive();
		break;
	case APPND:
		if (gzip_program != NULL)
			err(1, "cannot gzip while appending");
		rval = append();
		/* 
		 * Check if we tried to append on an empty file and
		 * turned into ARCHIVE mode.
		 */
		if (act == -ARCHIVE) {
			act = ARCHIVE;
			rval = archive();
		}
		break;
	case COPY:
		rval = copy();
		break;
	default:
	case LIST:
		rval = list();
		break;
	}
	if (rval != 0)
		exit_val = 1;
	return exit_val;
}
Esempio n. 6
0
File: search.cpp Progetto: ombt/ombt
int
DepthFirstHillClimbSearch(List<NodeType> &startstatelist, 
		BinaryTree_AVL<DataType> &startlist, 
		BinaryTree_AVL<DataType> &otherlist)
{
	int status;

	// track all states created
	BinaryTree_AVL<String> allstates;

	// create open stack for traversal
	List<Proxy<NodeType> > openstack;

	// keep track of current path here instead of 
	// using parent pointers. parent pointers cause
	// cycles and reference-counted pointers cannot
	// deal with cyclic data structures. they cause
	// major memory leaks.
	//
	int nodedepth = 1;
	List<Proxy<NodeType> > currentpath;

	// copy list of start states
	ListIterator<NodeType> startstateIter(startstatelist);
	for ( ; !startstateIter.done(); startstateIter++)
	{
		// copy start state
		Proxy<NodeType> pstart(startstateIter());

		// calculate the heuristic value for this node
		if ((status = pstart->heuristic(startlist, otherlist)) != OK)
		{
			ERRORD("heuristic() failed.", status, errno);
			return(status);
		}

		// set start node depth
		pstart->setDepth(nodedepth);

		// insert start state into open queue
		if ((status = openstack.insertOrdered(pstart)) != OK)
		{
			ERRORD("insertOrdered() failed.", status, errno);
			return(status);
		}
	}

	// children priority queue
	List<Proxy<NodeType> > childpq;
	
	// start search loop
	int olddepth = nodedepth;
	Proxy<NodeType> pchild;
	for (Proxy<NodeType> pnode; ! openstack.isEmpty(); )
	{
		// remove next node from priority open queue
		if ((status = openstack.removeAtFront(pnode)) != OK)
		{
			ERRORD("removeAtFront() failed.", status, errno);
			return(status);
		}

		// check if we have a goal node or not
		status = pnode->isGoal(startlist, otherlist);
		switch (status)
		{
		case OK:
			// update current path
			if ((status = updatepath(nodedepth, 
				olddepth, pnode, currentpath)) != OK)
				return(status);
			break;

		case NOMATCH:
		case MAXDEPTHEXCEEDED:
			// no clauses were generated. skip further
			// processing of this node.
			continue;

		case VALID:
			// update current path
			if ((status = updatepath(nodedepth, 
				olddepth, pnode, currentpath)) != OK)
				return(status);

			// goal node, print solution
			PrintSolution(pnode);
			PrintSolution(currentpath);
			PrintRenameVariables(pnode);

			// check if more than one solutions is required
			solutionsfound += 1;
			statistics[SolutionsFound] += 1;
			totalstatistics[TotalSolutionsFound] += 1;
			if (solutionsfound >= solutionsrequired)
				return(VALID);
			continue;

		case MAXCLAUSEEXCEEDED:
			// check if any solutions were found
			if (solutionsfound > 0)
				return(VALID);
			else
				return(NOTPROVEN);

		default:
			// some type of error
			ERRORD("isGoal() failed.", status, errno);
			return(status);
		}

		// generate the children of the current node
		if ((status = pnode->expand(startlist, otherlist)) != OK)
		{
			ERRORD("expand() failed.", status, errno);
			return(status);
		}

		// clear children priority queue
		childpq.clear();

		// set up links to parent and calculate the heuristic value
		ListIterator<Proxy<NodeType> > 
			childrenIter(*pnode->getChildren());
		for ( ; !childrenIter.done(); childrenIter++)
		{
			// pointer to child
			pchild = childrenIter();

			// set up link to parent
			if (reporttype == ReportParent ||
			    reporttype == ReportBoth)
				pchild->setParent(pnode);

			// calculate the heuristic value
			if ((status = pchild->heuristic(
				startlist, otherlist)) != OK)
			{
				ERRORD("heuristic() failed.", status, errno);
				return(status);
			}

			// insert child into a priority queue to order
			pchild->setDepth(nodedepth+1);
			if ((status = childpq.insertOrdered(pchild)) != OK)
			{
				ERRORD("insertOrdered() failed.", 
					status, errno);
				return(status);
			}
		}

		// insert nodes into stack ordered by heuristic value
		while (!childpq.isEmpty())
		{
			// remove next node from priority open queue
			if ((status = childpq.removeAtEnd(pchild)) != OK)
			{
				ERRORD("removeAtEnd() failed.", 
					status, errno);
				return(status);
			}

			// insert node into a stack
			if (!bfswithchecks)
			{
				if ((status = openstack.insertAtFront(
					pchild)) != OK)
				{
					ERRORD("insertAtFront() failed.", 
						status, errno);
					return(status);
				}
			}
			else
			{
				statistics[RedundantClauseTestsAttempted] += 1;
				totalstatistics[TotalRedundantClauseTestsAttempted] += 1;
				String newnode(pchild->getNormalizedClauses());
				if (allstates.retrieve(newnode) == NOMATCH)
				{
					if ((status = openstack.insertAtFront(
							pchild)) != OK)
					{
						ERRORD("insertAtFront() failed.", 
							status, errno);
						return(status);
					}
				}
				else
				{
					statistics[RedundantClausesRejected] += 1;
					totalstatistics[TotalRedundantClausesRejected] += 1;
				}
			}
		}

		// children are now in the queue. release pointers to
		// children stored in node.
		//
		pnode->getChildren()->clear();
		if (bfswithchecks)
		{
			if (allstates.insert(pnode->getNormalizedClauses()) != OK)
			{
				ERRORD("insert() failed.", status, errno);
				return(status);
			}
		}
	}

	// check if any solutions were found
	if (solutionsfound > 0)
		return(VALID);
	else
		return(NOTPROVEN);
}
Esempio n. 7
0
int prtvalue(xmlNodePtr cur,char *xmltype)
{
	xmlChar	*szKey;
	int	pathloop=0;
	xmlNodePtr curNode ;
	curNode = cur;
	char	path[256];
	memset(path,0,sizeof(path));
	_xmlcfg *tmpcfg=xmlcfg;

	while(curNode!=NULL)
	{
		if(curNode->type == XML_ELEMENT_NODE)
		{
			SysLog(LOG_APP_DEBUG,"ELement name [%s] \n",curNode->name);
		}else if(curNode->type == XML_TEXT_NODE)
		{
			szKey = xmlNodeGetContent(curNode);
			getNodePath(path,curNode);
			while(strcmp(tmpcfg->xmlname,""))
			{
				//SysLog(LOG_APP_ERR,"LILEI FILE [%s] LINE[%d]配置路径[%s]当前路径[%s]变量名[%s]变量值[%s]属性[%d]\n",__FILE__,__LINE__,tmpcfg->fullpath,path,tmpcfg->varname,szKey,tmpcfg->depth);
				if(!strcmp(tmpcfg->fullpath,path)&&!strcmp(tmpcfg->xmlname,xmltype))
				{
					/**每次更新循环登记表,入变量维度时以循环登记表为准 **/
					updatepath(path);
					SysLog(LOG_APP_DEBUG,"FILE [%s] LINE[%d]curname[%s]\n",__FILE__,__LINE__,curNode->parent->name);
					SysLog(LOG_APP_DEBUG,"FILE [%s] LINE[%d]curname[%s]\n",__FILE__,__LINE__,curNode->name);
					if(!strcmp(curNode->parent->name,"Ustrd"))
					{
						//SysLog(LOG_APP_ERR,"FILE [%s] LINE[%d]路径[%s]变量名[%s]变量值[%s]属性[%d]\n",__FILE__,__LINE__,(tmpcfg+loop)->fullpath,(tmpcfg+loop)->varname,szKey,(tmpcfg+loop)->depth);
						if(put_var_value((tmpcfg+loop)->varname,strlen(szKey)+1,1,szKey)!=0)
						{
							xmlFree(szKey);
							SysLog(LOG_APP_ERR,"放置变量[%s]失败\n",(tmpcfg+loop)->varname);
							return -1;
						}
						xmlFree(szKey);
						loop++;
						break;
					}else
					{
						//SysLog(LOG_APP_ERR,"FILE [%s] LINE[%d]路径[%s]变量名[%s]变量值[%s]属性[%d]\n",__FILE__,__LINE__,tmpcfg->fullpath,tmpcfg->varname,szKey,tmpcfg->depth);
						//if(put_var_value(tmpcfg->varname,strlen(szKey)+1,1,szKey)!=0)
						if(put_var_value(tmpcfg->varname,strlen(szKey)+1,getpathloop(path),szKey)!=0)
						{
							xmlFree(szKey);
							SysLog(LOG_APP_ERR,"放置变量[%s]失败\n",(tmpcfg+loop)->varname);
							return -1;
						}
						xmlFree(szKey);
						/** 防止多与的循环,找到后直接跳出循环 **/
						break;
					}
				}
				tmpcfg++;
			}
		}
		prtvalue(curNode->xmlChildrenNode,xmltype);
		curNode = curNode->next;
	}
	return  0;
}