Esempio n. 1
0
int gs_init(PSERVER_DATA server, const char *keyDirectory) {
  mkdirtree(keyDirectory);
  if (load_unique_id(keyDirectory) != GS_OK)
    return GS_FAILED;

  if (load_cert(keyDirectory))
    return GS_FAILED;

  http_init(keyDirectory);
  return load_server_status(server);
}
Esempio n. 2
0
File: init.c Progetto: Rendaw/tup
int init_command(int argc, char **argv)
{
	int x;
	int db_sync = 1;
	int force_init = 0;
	int fd;
	const char *dirname = NULL;

	for(x=1; x<argc; x++) {
		if(strcmp(argv[x], "--no-sync") == 0) {
			db_sync = 0;
		} else if(strcmp(argv[x], "--force") == 0) {
			/* force should only be used for tup/test */
			force_init = 1;
		} else {
			if(dirname) {
				fprintf(stderr, "tup error: Expected only one directory name for 'tup init', but got '%s' and '%s'\n", dirname, argv[x]);
				return -1;
			}
			dirname = argv[x];
		}
	}

	if(dirname) {
		if(mkdirtree(dirname) < 0)
			return -1;
	} else {
		dirname = ".";
	}

	fd = open(dirname, O_RDONLY);
	if(fd < 0) {
		perror(dirname);
		return -1;
	}

	if(!force_init && find_tup_dir() == 0) {
		char wd[PATH_MAX];
		if(getcwd(wd, sizeof(wd)) == NULL) {
			perror("getcwd");
			fprintf(stderr, "tup warning: database already exists somewhere up the tree.\n");
		} else {
			fprintf(stderr, "tup warning: database already exists in directory: %s\n", wd);
		}
		close(fd);
		return 0;
	}

	if(fchdir(fd) < 0) {
		perror("fchdir");
		close(fd);
		return -1;
	}
	if(close(fd) < 0) {
		perror("close(fd)");
		return -1;
	}

	if(mkdir(TUP_DIR, 0777) != 0) {
		perror(TUP_DIR);
		return -1;
	}

	if(tup_db_create(db_sync) != 0) {
		return -1;
	}

	if(creat(TUP_OBJECT_LOCK, 0666) < 0) {
		perror(TUP_OBJECT_LOCK);
		return -1;
	}
	if(creat(TUP_SHARED_LOCK, 0666) < 0) {
		perror(TUP_SHARED_LOCK);
		return -1;
	}
	if(creat(TUP_TRI_LOCK, 0666) < 0) {
		perror(TUP_TRI_LOCK);
		return -1;
	}
	if(!db_sync) {
		FILE *f = fopen(TUP_OPTIONS_FILE, "w");
		if(!f) {
			perror(TUP_OPTIONS_FILE);
			return -1;
		}
		fprintf(f, "[db]\n");
		fprintf(f, "\tsync = false\n");
		fclose(f);
	}
	return 0;
}