From ea0a0937a0524b8a449e470fbaea772a349d40fb Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Mon, 16 Jul 2012 14:03:06 -0700 Subject: common-utils: implement generate_glusterfs_ctx_id() This patch creates a common and shared version of the often copy/ pasted generate_uuid() function, which is used to create an ID string to uniquely identify an instance of a glusterfs process/glusterfs_ctx_t. Change-Id: Ie4e697ae28b6e954c5c261c69e37738f289d77e4 BUG: 839950 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.com/3677 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi --- libglusterfs/src/common-utils.c | 33 +++++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 2 ++ 2 files changed, 35 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index d09cafc68..cd7045277 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -2150,3 +2150,36 @@ _gf_timestuff (gf_timefmts *fmt, const char ***fmts, const char ***zeros) *zeros = __gf_zerotimes; } + +char * +generate_glusterfs_ctx_id (void) +{ + char tmp_str[1024] = {0,}; + char hostname[256] = {0,}; + struct timeval tv = {0,}; + char now_str[32]; + + if (gettimeofday (&tv, NULL) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "gettimeofday: failed %s", + strerror (errno)); + } + + if (gethostname (hostname, 256) == -1) { + gf_log ("glusterfsd", GF_LOG_ERROR, + "gethostname: failed %s", + strerror (errno)); + } + + gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_Ymd_T); + snprintf (tmp_str, sizeof tmp_str, "%s-%d-%s:%" +#ifdef GF_DARWIN_HOST_OS + PRId32, +#else + "ld", +#endif + hostname, getpid(), now_str, tv.tv_usec); + + return gf_strdup (tmp_str); +} + diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 26af45fcc..f21ade40b 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -552,4 +552,6 @@ void gf_path_strip_trailing_slashes (char *path); uint64_t get_mem_size (); int gf_strip_whitespace (char *str, int len); int gf_canonicalize_path (char *path); +char *generate_glusterfs_ctx_id (void); + #endif /* _COMMON_UTILS_H */ -- cgit