int create_empty_dir_as_user(const char *dir, mode_t mode) {
	assert(dir);
	mode &= 07777;

	if (access(dir, F_OK) == 0)
		return 0;

	pid_t child = fork();
	if (child < 0)
		errExit("fork");
	if (child == 0) {
		// drop privileges
		drop_privs(0);

		if (arg_debug)
			printf("Creating empty %s directory\n", dir);
		if (mkdir(dir, mode) == 0) {
			int err = chmod(dir, mode);
			(void) err;
		}
		else if (arg_debug)
			printf("Directory %s not created: %s\n", dir, strerror(errno));

		__gcov_flush();

		_exit(0);
	}
	waitpid(child, NULL, 0);

	if (access(dir, F_OK) == 0)
		return 1;
	return 0;
}
int create_empty_dir_as_user(const char *dir, mode_t mode) {
	assert(dir);
	mode &= 07777;

	if (access(dir, F_OK) == 0)
		return 0;

	pid_t child = fork();
	if (child < 0)
		errExit("fork");
	if (child == 0) {
		 
		drop_privs(0);

		if (arg_debug)
			printf("Creating empty %s directory\n", dir);
		if (mkdir(dir, mode) == 0) {
			int err = chmod(dir, mode);
			(void) err;
		}
		else if (arg_debug)
			printf("Directory %s not created: %s\n", dir, strerror(errno));

		__gcov_flush();

		_exit(0);
	}
	waitpid(child, NULL, 0);

	if (access(dir, F_OK) == 0)
		return 1;
	return 0;
}