From 686d28a1f03641107d6da48d8960a7caa4215c18 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 29 Sep 2014 13:21:26 +0300 Subject: [PATCH] Fix to bug #506, http://bugs.skysql.com/show_bug.cgi?id=506 If debug and/or trace log is stored to shared memory, the absolute path to file is now /dev/shm//skygw_[trace1|debug1].log --- log_manager/log_manager.cc | 30 +++++++++++++++++++++++++++--- utils/skygw_utils.cc | 14 +++++++++++++- utils/skygw_utils.h | 1 + 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 2b274a610..8e33aed16 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -75,7 +75,7 @@ int lm_enabled_logfiles_bitmask = 0; * Path to directory in which all files are stored to shared memory * by the OS. */ -const char* shm_pathname = "/dev/shm"; +const char* shm_pathname_prefix = "/dev/shm/"; /** Logfile ids from call argument '-s' */ char* shmem_id_str = NULL; @@ -2064,7 +2064,31 @@ static bool logfile_init( * directory. */ if (store_shmem) { +#if 1 + char* c; + pid_t pid = getpid(); + int len = strlen(shm_pathname_prefix)+ + get_decimal_len((size_t)pid); + + c = (char *)calloc(len, sizeof(char)); + + if (c == NULL) + { + succp = false; + goto file_create_fail; + } + sprintf(c, "%s%d", shm_pathname_prefix, pid); + logfile->lf_filepath = c; + + if (mkdir(c, S_IRWXU | S_IRWXG) != 0 && + errno != EEXIST) + { + succp = false; + goto file_create_fail; + } +#else logfile->lf_filepath = strdup(shm_pathname); +#endif logfile->lf_linkpath = strdup(fn->fn_logpath); logfile->lf_linkpath = add_slash(logfile->lf_linkpath); } else { @@ -2146,7 +2170,7 @@ static bool logfile_init( } } } - file_create_fail: +file_create_fail: if (namecreatefail || nameconflicts) { logfile->lf_name_seqno += 1; @@ -2161,7 +2185,7 @@ static bool logfile_init( free(logfile->lf_full_link_name); logfile->lf_full_link_name = NULL; } - + goto return_with_succp; } } while (namecreatefail || nameconflicts); /** diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 4845c73a2..23cac20d9 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -1955,7 +1955,19 @@ retblock: return newstr; } - +/** + * Calculate the number of decimal numbers from a size_t value. + * + * @param value value + * + * @return number of decimal numbers of which the value consists of + * value==123 returns 3, for example. + */ +size_t get_decimal_len( + size_t value) +{ + return value > 0 ? (size_t) log10 ((double) value) + 1 : 1; +} diff --git a/utils/skygw_utils.h b/utils/skygw_utils.h index a54859392..80793fbca 100644 --- a/utils/skygw_utils.h +++ b/utils/skygw_utils.h @@ -192,6 +192,7 @@ int skygw_rwlock_unlock(skygw_rwlock_t* rwlock); int skygw_rwlock_init(skygw_rwlock_t** rwlock); int atomic_add(int *variable, int value); +size_t get_decimal_len(size_t s); EXTERN_C_BLOCK_BEGIN