Exemple #1
0
Fichier : ui.c Projet : bcl/parted
/* Signal handler for SIGINT using 'sigaction'. */
static void
sa_sigint_handler (int signum, siginfo_t* info, void *ucontext)
{
        if (info)
                sigaction (SIGINT, &sig_int, NULL);

        got_ctrl_c = 1;
        reset_env (0);
}
Exemple #2
0
int main(int argc, char **argv) {

	unsigned i;
	int ch;
	const char *path;
	const char *search_path = 0;
	static unsigned zero = 0;


#ifdef __STACK_CHECK__
	_beginStackCheck();
	atexit(stackResults);
#endif


	// work around GNO/ME environment bug.
	PushVariablesGS(&zero);

	if (_toolErr) {
		errx(1, "PushVariablesGS: $%04x", _toolErr);
	}


	while ((ch = getopt(argc, argv, "-ivP:S:u:x:")) != -1) {
		switch(ch) {
			case 'v':
				_v++;
				break;

			case 'i':
			case '-':
				reset_env();
				break;

			case 'u':
				unset_env(optarg);
				break;

			case 'x':
				/* GNO-specific: set prefix */
				set_prefix(optarg);
				break;

			case 'P':
				search_path = optarg;
				break;

			case 'S':
				// not a posix flag.
				errx(1, "-S is not supported");
				break;

			case '?':
			default:
				usage();
		}
	}

	argc -= optind;
	argv += optind;

	for( ; argc; ++argv, --argc) {
		if (!set_env(*argv)) break;
	}

	if (!argc) {
		print_env();
		exit(0);
	}

	path = find_path(argv[0], search_path);
	if (_v) {
		fprintf(stderr, "#env executing:\t%s\n", path);
		for (i = 0; i < argc; ++i) 
			fprintf(stderr, "#env    arg[%d]= '%s'\n", i, argv[i]);
	}
	execv(path, argv);

	exit(errno == ENOENT ? 127 : 126);
	return 0;
}
Exemple #3
0
char *setup_testbed(const char *fkt_name)
{
#ifndef _WIN32	
	setuid(65534);
#endif
	char *testbed = g_strdup_printf("%s/testbed.XXXXXX", g_get_tmp_dir());
	char *command = NULL, *dirname = NULL;
#ifdef _WIN32
	if(g_file_test(testbed, G_FILE_TEST_IS_DIR))
		destroy_testbed(g_strdup(testbed));

	if(g_mkdir(testbed,0777) < 0){
			osync_trace(TRACE_INTERNAL, "%s: Cannot create testbed directory %s", __func__, testbed);
			abort();
	}
#else /* WIN32 */
	if (!mkdtemp(testbed))
		abort();
#endif /* WIN32 */
	
	if (fkt_name) {
		dirname = g_strdup_printf(OPENSYNC_TESTDATA"/%s", fkt_name);
		if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
			osync_trace(TRACE_INTERNAL, "%s: Path %s not exist.", __func__, dirname);
			abort();
		}
		command = g_strdup_printf("cp -R %s/* %s", dirname, testbed);
		if (osync_system(command))
			abort();
		g_free(command);

		/* special handling for the git repo, since git does not
		 * support empty directories, check for a file named
		 * "empty_dirs" and create every subdirectory listed
		 * there that does not begin with a slash (relative dirs only)
		 */
		{
			char *empty_name = NULL;
			FILE *fh = NULL;

			empty_name = g_strdup_printf("%s/empty_dirs", dirname);
			if ((fh = fopen(empty_name, "r"))) {
				char line[100], *s;
				while ((s = fgets(line, sizeof(line), fh))) {
					int len = strlen(s);
					/* trim newline */
					if (len && s[len-1] == '\n')
						s[len-1] = 0;
					/* only create relative paths */
					if (len && s[0] != '/' && s[0] != '\\' && s[0] != '#') {
						char *newdir = g_strdup_printf("%s/%s", testbed, s);
						if (newdir) {
							g_mkdir_with_parents(newdir, 0755);
							g_free(newdir);
						}
					}
				}
				fclose(fh);
			}
			g_free(empty_name);
		}

		g_free(dirname);
	}
	
	dirname = g_strdup_printf("%s/formats",  testbed);
	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
		if (g_mkdir(dirname,0777) < 0) {
			osync_trace(TRACE_ERROR, "Could not create format direcotry %s", dirname);
			abort();
		}
	}
	g_free(dirname);

	dirname = g_strdup_printf("%s/plugins",  testbed);
	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
		if (g_mkdir(dirname,0777) < 0) {
			osync_trace(TRACE_ERROR, "Could not create plugin direcotry %s", dirname);
			abort();
		}
	}
	g_free(dirname);
	
	command = g_strdup_printf("cp ./mock-plugin/mock-sync.%s %s/plugins", G_MODULE_SUFFIX, testbed);
	if (osync_system(command))
		abort();
	g_free(command);
	
	command = g_strdup_printf("cp ./mock-plugin/mock-format.%s %s/formats", G_MODULE_SUFFIX, testbed);
	if (osync_system(command))
		abort();
	g_free(command);

	command = g_strdup_printf("cp -R %s/../../misc/schemas/*.xsd %s", OPENSYNC_TESTDATA, testbed);
	if (osync_system(command))
		abort();
	g_free(command);

#ifndef _WIN32	/* chmod is useless on windows system */
	command = g_strdup_printf("chmod -R 700 %s", testbed);
	if (osync_system(command))
		abort();
	g_free(command);
#endif
		
	olddir = g_get_current_dir();
	if (g_chdir(testbed) < 0){
		osync_trace(TRACE_ERROR, "Could not chdir to testbed");
		abort();
	}
	
	reset_counters();

	osync_trace(TRACE_INTERNAL, "Seting up %s at %s", fkt_name, testbed);
/*	printf(".");
	fflush(NULL);*/
	reset_env();
	return testbed;
}