Example #1
0
void debug_file_write (INT64_T flags, const char *str)
{
	int rc;
	if (file_size_max > 0) {
		struct stat info;
		rc = fstat(file_fd, &info);
		if (rc == 0) {
			if (info.st_size >= file_size_max) {
				close(file_fd);
				if(stat(file_path, &info) == 0 && info.st_size >= file_size_max) {
					char old[PATH_MAX] = "";
					snprintf(old, sizeof(old)-1, "%s.old", file_path);
					rename(file_path, old);
				}
				debug_file_reopen();
			}
		} else {
			fprintf(stderr, "couldn't stat debug file: %s\n", strerror(errno));
			abort();
		}
	}

	rc = full_write(file_fd, str, strlen(str));
	if (rc == -1) {
		fprintf(stderr, "couldn't write to debug file: %s\n", strerror(errno));
		abort();
	}
}
Example #2
0
void debug_file_rename (const char *suffix)
{
	if (strlen(file_path)) {
		char old[PATH_MAX] = "";

		close(file_fd);
		snprintf(old, sizeof(old)-1, "%s.%s", file_path, suffix);
		rename(file_path, old);
		debug_file_reopen();
	}
}
Example #3
0
void debug_file_path (const char *path)
{
	path_absolute(path, file_path, 0);
	close(file_fd);
	debug_file_reopen();
}
Example #4
0
void debug_reopen(void)
{
	if (debug_file_reopen() == -1)
		fatal("could not reopen debug log: %s", strerror(errno));
}