Exemplo n.º 1
0
Arquivo: vz.c Projeto: OpenVZ/libvzctl
static int validate_eid(struct vzctl_env_handle *h, struct stat *veconf,
		ctid_t ctid)
{
	char conf[PATH_MAX];
	struct stat st;
	ctid_t ctid_conf;
	const char *data;

	if (vzctl2_env_get_param(h, "VEID", &data) == 0 && data != NULL)
		vzctl2_parse_ctid(data, ctid_conf);
	/* Check if VE_PRIVATE/ve.conf already registered
	 * /etc/vz/conf/ctid_conf.conf -> VE_PRIVATE/ve.conf
	 */
	if (!EMPTY_CTID(ctid_conf)) {
		vzctl2_get_env_conf_path(ctid_conf, conf, sizeof(conf));
		if (stat(conf, &st) == 0) {
			if (cmp_stat(veconf, &st) == 0)
				return vzctl_err(-1, 0, "Container is already"
					" registered with id %s", ctid_conf);
		} else if (errno != ENOENT)
			return vzctl_err(-1, errno, "Failed to stat %s", conf);
	}

	/* Check if ctid alredy used */
	vzctl2_get_env_conf_path(ctid, conf, sizeof(conf));
	if (lstat(conf, &st)) {
		if (errno == ENOENT)
			return 0;
		return vzctl_err(-1, errno, "Failed lstat %s", conf);
	} else if (!S_ISLNK(st.st_mode))
		return vzctl_err(-1, 0, "Container configuration file %s"
				" is not a link", conf);

	if (stat(conf, &st)) {
		if (errno == ENOENT)
			return 0;
		return vzctl_err(-1, errno, "Failed to stat %s", conf);
	}

	/* /etc/vz/conf/ctid.conf already exists */
	if (cmp_stat(veconf, &st) != 0 )
		return vzctl_err(-1, 0, "Error: Container ID %s is used", ctid);

	return 0;
}
Exemplo n.º 2
0
Arquivo: clump.c Projeto: Sep102/Clump
/* If we see "int main(" then it's probably a main program. */
void scan_cfile(const char *cfile)
	{
	struct stat cstat;
	struct stat ostat;

	struct clist_entry *cdata = clist_push(&clist);

	cdata->need_compile = 0;
	bufd_put(&cdata->cfile, cfile);
	bufd_put(&cdata->ofile, opt_objdir.beg);
	bufd_dirslash(&cdata->ofile);
	bufd_put(&cdata->ofile, cfile);
	bufd_clip(&cdata->ofile, 1);
	bufd_putc(&cdata->ofile, 'o');

	statfile(cdata->cfile.beg, &cstat);
	statfile(cdata->ofile.beg, &ostat);

	if (opt_force || cmp_stat(&cstat, &ostat) > 0)
		cdata->need_compile = 1;

	fp = fopen(cfile,"r");

	while (getch() != EOF)
		{
		if (at("#""include"))
			{
			skipspace();
			if (ch == '"')
				{
				const char *hfile = upto('"');
				if (!cdata->need_compile)
					{
					struct stat hstat;
					statfile(hfile, &hstat);
					if (cmp_stat(&hstat, &ostat) > 0)
						cdata->need_compile = 1;
					}
				strq_push(&cdata->loc_include, hfile);
				}
			else if (ch == '<')
				{
				const char *hfile = upto('>');
				const char *lib = strq_assoc(&syshdr, hfile);
				if (lib)
					strq_push(&cdata->libs, lib);
				strq_push(&cdata->sys_include, hfile);
				}
			}
		else if (at("int") && isspace(ch) && skipspace() &&
			at("main") && skipspace() && ch == '(')
			{
			cdata->is_main = 1;
			}
		}

	if (fp)
		{
		fclose(fp);
		fp = 0;
		}

	if (opt_analyze)
		clist_entry_print(cdata);
	}