summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2019-03-25 19:07:16 +0200
committerAmar Tumballi <amarts@redhat.com>2019-04-15 02:25:26 +0000
commita67929e18a39d5c79a4a7e2b78015523626a367e (patch)
treecee5cbfb669df65699d932b2f8944ff28f0a7e7c /libglusterfs
parentc56f102da21c5b69e656a055aaf736281596284d (diff)
graph.c: remove extra gettimeofday() - reuse the graph dob.
It was written just before fill_void() call. Note that there was a possible overflow if the hostname was too long (unrelated to this patch), but it is now also fixed, as we use a smaller buffer for the hostname. This, in turn, forces us to check if gethostname() failed and add explicitly the terminating null to it. Change-Id: I45fbc0a8e105f1247f3cbf61befac06fabbaea06 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/glusterfs/glusterfs.h4
-rw-r--r--libglusterfs/src/graph.c25
2 files changed, 10 insertions, 19 deletions
diff --git a/libglusterfs/src/glusterfs/glusterfs.h b/libglusterfs/src/glusterfs/glusterfs.h
index 209bb41307d..cdb6d97eec1 100644
--- a/libglusterfs/src/glusterfs/glusterfs.h
+++ b/libglusterfs/src/glusterfs/glusterfs.h
@@ -586,20 +586,20 @@ typedef struct _cmd_args cmd_args_t;
struct _glusterfs_graph {
struct list_head list;
- char graph_uuid[128];
struct timeval dob;
void *first;
void *top; /* selected by -n */
- uint32_t leaf_count;
int xl_count;
int id; /* Used in logging */
int used; /* Should be set when fuse gets
first CHILD_UP */
uint32_t volfile_checksum;
+ uint32_t leaf_count;
void *last_xl; /* Stores the last xl of the graph, as of now only populated
in client multiplexed code path */
pthread_mutex_t mutex;
pthread_cond_t child_down_cond; /* for broadcasting CHILD_DOWN */
+ char graph_uuid[128];
};
typedef struct _glusterfs_graph glusterfs_graph_t;
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
index a492dd891fd..74b568441af 100644
--- a/libglusterfs/src/graph.c
+++ b/libglusterfs/src/graph.c
@@ -460,27 +460,18 @@ glusterfs_graph_unknown_options(glusterfs_graph_t *graph)
return 0;
}
-void
-fill_uuid(char *uuid, int size)
+static void
+fill_uuid(char *uuid, int size, struct timeval tv)
{
- char hostname[256] = {
- 0,
- };
- struct timeval tv = {
+ char hostname[50] = {
0,
};
char now_str[64];
- if (gettimeofday(&tv, NULL) == -1) {
- gf_msg("graph", GF_LOG_ERROR, errno, LG_MSG_GETTIMEOFDAY_FAILED,
- "gettimeofday: "
- "failed");
- }
-
- if (gethostname(hostname, 256) == -1) {
+ if (gethostname(hostname, sizeof(hostname) - 1) != 0) {
gf_msg("graph", GF_LOG_ERROR, errno, LG_MSG_GETHOSTNAME_FAILED,
- "gethostname: "
- "failed");
+ "gethostname failed");
+ hostname[sizeof(hostname) - 1] = '\0';
}
gf_time_fmt(now_str, sizeof now_str, tv.tv_sec, gf_timefmt_dirent);
@@ -616,7 +607,7 @@ ok:
/* XXX: DOB setting */
gettimeofday(&graph->dob, NULL);
- fill_uuid(graph->graph_uuid, 128);
+ fill_uuid(graph->graph_uuid, sizeof(graph->graph_uuid), graph->dob);
graph->id = ctx->graph_id++;
@@ -1440,7 +1431,7 @@ glusterfs_muxsvc_setup_parent_graph(glusterfs_ctx_t *ctx, char *name,
ixl = NULL;
gettimeofday(&parent_graph->dob, NULL);
- fill_uuid(parent_graph->graph_uuid, 128);
+ fill_uuid(parent_graph->graph_uuid, 128, parent_graph->dob);
parent_graph->id = ctx->graph_id++;
ret = 0;
out: