GUAC-1452: Append .timing to end of basename for timing file.

This commit is contained in:
Michael Jumper 2016-01-27 12:13:25 -08:00
parent d421bbc075
commit 7c7a68975b
2 changed files with 35 additions and 18 deletions

View File

@ -69,7 +69,7 @@ static int guac_terminal_typescript_open_data_file(const char* path,
/* Concatenate path and name (separated by a single slash) */ /* Concatenate path and name (separated by a single slash) */
int basename_length = snprintf(basename, int basename_length = snprintf(basename,
basename_size - GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH , basename_size - GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH,
"%s/%s", path, name); "%s/%s", path, name);
/* Abort if maximum length reached */ /* Abort if maximum length reached */
@ -84,9 +84,12 @@ static int guac_terminal_typescript_open_data_file(const char* path,
O_CREAT | O_EXCL | O_WRONLY, O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
/* Continuously retry with alternate names on failure */
if (data_fd == -1) {
/* Prepare basename for additional suffix */ /* Prepare basename for additional suffix */
basename[basename_length] = '.'; basename[basename_length] = '.';
char* suffix = basename + basename_length + 1; char* suffix = &(basename[basename_length + 1]);
/* Continue retrying alternative suffixes if file already exists */ /* Continue retrying alternative suffixes if file already exists */
for (i = 1; data_fd == -1 && errno == EEXIST for (i = 1; data_fd == -1 && errno == EEXIST
@ -102,6 +105,8 @@ static int guac_terminal_typescript_open_data_file(const char* path,
} }
}
return data_fd; return data_fd;
} }
@ -110,6 +115,7 @@ guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
const char* name, int create_path) { const char* name, int create_path) {
char basename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH]; char basename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
char timing_name[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
guac_terminal_typescript* typescript; guac_terminal_typescript* typescript;
int data_fd, timing_fd; int data_fd, timing_fd;
@ -119,13 +125,17 @@ guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
return NULL; return NULL;
/* Attempt to open typescript data file */ /* Attempt to open typescript data file */
data_fd = guac_terminal_typescript_open_data_file(path, name, data_fd = guac_terminal_typescript_open_data_file(path, name, basename,
basename, sizeof(basename)); sizeof(basename) - sizeof(GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX));
if (data_fd == -1) if (data_fd == -1)
return NULL; return NULL;
/* Append suffix to basename */
sprintf(timing_name, "%s.%s", basename,
GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX);
/* Attempt to open typescript timing file */ /* Attempt to open typescript timing file */
timing_fd = open("/tmp/typescript-timing", timing_fd = open(timing_name,
O_CREAT | O_EXCL | O_WRONLY, O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
if (timing_fd == -1) { if (timing_fd == -1) {

View File

@ -56,16 +56,23 @@
/** /**
* The maximum length of the string containing a sequential numeric suffix * The maximum length of the string containing a sequential numeric suffix
* between 1 and GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX inclusive, in bytes. * between 1 and GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX inclusive, in bytes,
* including NULL terminator.
*/ */
#define GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH 4 #define GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH 4
/** /**
* The maximum overall length of the full path to the typescript file, * The maximum overall length of the full path to the typescript file,
* including any additional suffix, in bytes. * including any additional suffix and NULL terminator, in bytes.
*/ */
#define GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH 2048 #define GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH 2048
/**
* The suffix which will be appended to the typescript data file's name to
* produce the name of the timing file.
*/
#define GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX "timing"
/** /**
* An active typescript, consisting of a data file (raw terminal output) and * An active typescript, consisting of a data file (raw terminal output) and
* timing file (related timestamps and byte counts). * timing file (related timestamps and byte counts).