Exemple #1
0
int tup_lock_init(void)
{
	sh_lock = openat(tup_top_fd(), TUP_SHARED_LOCK, O_RDWR);
	if(sh_lock < 0) {
		perror(TUP_SHARED_LOCK);
		return -1;
	}
	if(tup_flock(sh_lock) < 0) {
		return -1;
	}

	obj_lock = openat(tup_top_fd(), TUP_OBJECT_LOCK, O_RDWR);
	if(obj_lock < 0) {
		perror(TUP_OBJECT_LOCK);
		return -1;
	}
	if(tup_flock(obj_lock) < 0) {
		return -1;
	}

	tri_lock = openat(tup_top_fd(), TUP_TRI_LOCK, O_RDWR);
	if(tri_lock < 0) {
		perror(TUP_TRI_LOCK);
		return -1;
	}
	return 0;
}
Exemple #2
0
Fichier : udp.c Projet : Meai1/tup
int server_parser_start(struct server *s)
{
	s->root_fd = tup_top_fd();
	if(open_notify_push(&s->finfo) < 0)
		return -1;
	return 0;
}
Exemple #3
0
FILE *__wrap_tmpfile(void)
{
	static int num = 0;
	int fd;
	char filename[64];
	FILE *f = NULL;
	HANDLE h;

	dir_mutex_lock(tup_top_fd());

	snprintf(filename, sizeof(filename), ".tup/tmp/tmpfile-%i", num);
	filename[sizeof(filename)-1] = 0;
	num++;

	/* Need to use CreateFile to be able to set it delete-on-close */
	h = CreateFile(filename, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
	if(h == INVALID_HANDLE_VALUE)
		goto err_out;

	/* Convert from HANDLE to FILE* */
	fd = _open_osfhandle((intptr_t)h, 0);
	if(fd < 0)
		goto err_out;
	f = fdopen(fd, "w+");
	if(!f) {
		if(!close(fd)) {
			perror("close(fd) in tmpfile()");
			goto err_out;
		}
	}
err_out:
	dir_mutex_unlock();

	return f;
}
Exemple #4
0
int tup_cleanup(void)
{
	tup_db_close();
	tup_option_exit();
	tup_lock_exit();
	if(close(tup_top_fd()) < 0)
		perror("close(tup_top_fd())");
	if(server_post_exit() < 0)
		return -1;
	return 0;
}
Exemple #5
0
int tup_vardict_open(void)
{
	vardict_fd = openat(tup_top_fd(), TUP_VARDICT_FILE, O_RDONLY);
	if(vardict_fd < 0) {
		/* Create vardict if it doesn't exist, since I forgot to add
		 * that to the database update part whenever I added this file.
		 * Not sure if this is the best approach, but it at least
		 * prevents a useless error message from coming up.
		 */
		if(errno == ENOENT) {
			vardict_fd = openat(tup_top_fd(), TUP_VARDICT_FILE, O_CREAT|O_RDONLY, 0666);
			if(vardict_fd < 0) {
				perror(TUP_VARDICT_FILE);
				return -1;
			}
		} else {
			perror(TUP_VARDICT_FILE);
			return -1;
		}
	}
	return 0;
}
Exemple #6
0
void logging_enable(int argc, char **argv)
{
	int x;
	char timedata[64];
	struct tm tm;
	time_t t;

	time(&t);
#ifdef _WIN32
	localtime_s(&tm, &t);
#else
	localtime_r(&t, &tm);
#endif
	if(strftime(timedata, sizeof(timedata), "%c", &tm) <= 0) {
		timedata[0] = 0;
	}

	if(rotate("debug.log") < 0) {
		return;
	}
	if(rotate("create.dot") < 0) {
		return;
	}
	if(rotate("update.dot") < 0) {
		return;
	}
	if(mkdirat(tup_top_fd(), LOG_DIR, 0777) < 0) {
		if(errno != EEXIST) {
			perror(LOG_DIR);
			fprintf(stderr, "tup error: Unable to create debug log directory.\n");
			enabled = 0;
			return;
		}
	}
	logfile = fopen(LOG_NAME, "w+");
	if(!logfile) {
		perror(LOG_NAME);
		fprintf(stderr, "tup error: Unable to create debug log.\n");
		enabled = 0;
		return;
	}
	enabled = 1;
	log_debug("Tup update at %s:", timedata);
	for(x=0; x<argc; x++) {
		log_debug(" '%s'", argv[x]);
	}
	log_debug("\n");
}