Esempio n. 1
0
int main(int argc, char *argv[])
{
	struct wrapper_data data;

	memset(&data, 0, sizeof(data));

	if (getenv("PATH"))
		data.path = xstrdup(getenv("PATH"));

	/* What should we find ? */
	data.name = basename(argv[0]);

	/* Allow for common compiler names like cc->gcc */
	size_t i;
	for (i = 0; i < ARRAY_SIZE(wrapper_aliases); ++i)
		if (!strcmp(data.name, wrapper_aliases[i].alias))
			data.name = wrapper_aliases[i].target;

	/* What is the full name of our wrapper? */
	data.fullname = xmalloc(strlen(data.name) + sizeof("@GENTOO_PORTAGE_EPREFIX@/usr/bin/") + 1);
	sprintf(data.fullname, "@GENTOO_PORTAGE_EPREFIX@/usr/bin/%s", data.name);

	find_wrapper_target(&data);

	modify_path(&data);

	free(data.path);
	data.path = NULL;

	/* Set argv[0] to the correct binary, else gcc can't find internal headers
	 * http://bugs.gentoo.org/8132
	 */
	argv[0] = data.bin;

	/* If $ABI is in env, add appropriate env flags */
	char **newargv = argv;
	if (getenv("ABI")) {
		char envvar[50];

		/* We use CFLAGS_${ABI} for gcc, g++, g77, etc as the flags that would
		 * be in there are the same no matter which compiler we are using.
		 */
		snprintf(envvar, sizeof(envvar), "CFLAGS_%s", getenv("ABI"));
		envvar[sizeof(envvar)-1] = '\0';

		if (getenv(envvar))
			newargv = build_new_argv(argv, getenv(envvar));
	}

	/* Ok, lets do it one more time ... */
	execv(data.bin, newargv);

	/* shouldn't have made it here if things worked ... */
	wrapper_err("could not run/locate '%s'", data.name);

	return 123;
}
int main(int argc, char *argv[])
{
	struct wrapper_data *data;
	size_t size;
	int i;
	char **newargv = argv;

	data = alloca(sizeof(*data));
	if (data == NULL)
		wrapper_exit("%s wrapper: out of memory\n", argv[0]);
	memset(data, 0, sizeof(*data));

	if (getenv("PATH")) {
		data->path = strdup(getenv("PATH"));
		if (data->path == NULL)
			wrapper_exit("%s wrapper: out of memory\n", argv[0]);
	}

	/* What should we find ? */
	strcpy(data->name, basename(argv[0]));

	/* Allow for common compiler names like cc->gcc */
	for (i = 0; wrapper_aliases[i].alias; ++i)
		if (!strcmp(data->name, wrapper_aliases[i].alias))
			strcpy(data->name, wrapper_aliases[i].target);

	/* What is the full name of our wrapper? */
	size = sizeof(data->fullname);
	i = snprintf(data->fullname, size, "/usr/bin/%s", data->name);
	if ((i == -1) || (i > (int)size))
		wrapper_exit("invalid wrapper name: \"%s\"\n", data->name);

	find_wrapper_target(data);

	modify_path(data);

	if (data->path)
		free(data->path);
	data->path = NULL;

	/* Set argv[0] to the correct binary, else gcc can't find internal headers
	 * http://bugs.gentoo.org/show_bug.cgi?id=8132 */
	argv[0] = data->bin;

	/* If this is g{cc,++}{32,64}, we need to add -m{32,64}
	 * otherwise  we need to add ${CFLAGS_${ABI}}
	 */
	size = strlen(data->bin) - 2;
	if(!strcmp(data->bin + size, "32") ) {
		*(data->bin + size) = '\0';
		newargv = build_new_argv(argv, "-m32");
	} else if (!strcmp(data->bin + size, "64") ) {
		*(data->bin + size) = '\0';
		newargv = build_new_argv(argv, "-m64");
	} else if(getenv("ABI")) {
		char envvar[50];

		/* We use CFLAGS_${ABI} for gcc, g++, g77, etc as they are
		 * the same no matter which compiler we are using.
		 */
		snprintf(envvar, sizeof(envvar), "CFLAGS_%s", getenv("ABI"));

		if (getenv(envvar)) {
			newargv = build_new_argv(argv, getenv(envvar));
			if(!newargv)
				wrapper_exit("%s wrapper: out of memory\n", argv[0]);
		}
	}

	/* Ok, lets do it one more time ... */
	if (execv(data->bin, newargv) < 0)
		wrapper_exit("Could not run/locate \"%s\"\n", data->name);

	return 0;
}
int main(int argc, char *argv[])
{
	struct wrapper_data data;
	size_t size;
	int i;
	char **newargv = argv;

	memset(&data, 0, sizeof(data));

	if (getenv("PATH")) {
		data.path = strdup(getenv("PATH"));
		if (data.path == NULL)
			wrapper_exit("%s wrapper: out of memory\n", argv[0]);
	}

	/* What should we find ? */
	strcpy(data.name, basename(argv[0]));

	/* Allow for common compiler names like cc->gcc */
	for (i = 0; wrapper_aliases[i].alias; ++i)
		if (!strcmp(data.name, wrapper_aliases[i].alias))
			strcpy(data.name, wrapper_aliases[i].target);

	/* What is the full name of our wrapper? */
	size = sizeof(data.fullname);
	i = snprintf(data.fullname, size, "/usr/bin/%s", data.name);
	if ((i == -1) || (i > (int)size))
		wrapper_exit("invalid wrapper name: \"%s\"\n", data.name);

	find_wrapper_target(&data);

	modify_path(&data);

	if (data.path)
		free(data.path);
	data.path = NULL;

	/* Set argv[0] to the correct binary, else gcc can't find internal headers
	 * http://bugs.gentoo.org/8132
	 */
	argv[0] = data.bin;

	/* If $ABI is in env, add appropriate env flags */
	if (getenv("ABI")) {
		char envvar[50];

		/* We use CFLAGS_${ABI} for gcc, g++, g77, etc as they are
		 * the same no matter which compiler we are using.
		 */
		snprintf(envvar, sizeof(envvar), "CFLAGS_%s", getenv("ABI"));

		if (getenv(envvar)) {
			newargv = build_new_argv(argv, getenv(envvar));
			if (!newargv)
				wrapper_exit("%s wrapper: out of memory\n", argv[0]);
		}
	}

	/* Ok, lets do it one more time ... */
	if (execv(data.bin, newargv) < 0)
		wrapper_exit("Could not run/locate \"%s\"\n", data.name);

	return 123;
}