diff options
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/authenticate.c | 12 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.c | 60 | ||||
-rw-r--r-- | libglusterfs/src/dict.c | 71 | ||||
-rw-r--r-- | libglusterfs/src/inode.c | 8 | ||||
-rw-r--r-- | libglusterfs/src/logging.c | 25 | ||||
-rw-r--r-- | libglusterfs/src/scheduler.c | 9 | ||||
-rw-r--r-- | libglusterfs/src/transport.c | 6 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 7 |
8 files changed, 145 insertions, 53 deletions
diff --git a/libglusterfs/src/authenticate.c b/libglusterfs/src/authenticate.c index 3587a41d75f..24c840b5e06 100644 --- a/libglusterfs/src/authenticate.c +++ b/libglusterfs/src/authenticate.c @@ -42,7 +42,8 @@ init (dict_t *this, auth_handle_t *auth_handle = NULL; auth_fn_t authenticate = NULL; int *error = NULL; - + int ret = 0; + /* It gets over written */ error = data; @@ -57,7 +58,14 @@ init (dict_t *this, key = "addr"; } - asprintf (&auth_file, "%s/%s.so", LIBDIR, key); + ret = asprintf (&auth_file, "%s/%s.so", LIBDIR, key); + if (-1 == ret) { + gf_log ("authenticate", GF_LOG_ERROR, "asprintf failed"); + dict_set (this, key, data_from_dynptr (NULL, 0)); + *error = -1; + return; + } + handle = dlopen (auth_file, RTLD_LAZY); if (!handle) { gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n", diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 2650e8fb55a..c68fd306660 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -96,7 +96,11 @@ gf_resolve_ip6 (const char *hostname, hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG; - asprintf (&port_str, "%d", port); + ret = asprintf (&port_str, "%d", port); + if (-1 == ret) { + gf_log ("resolver", GF_LOG_ERROR, "asprintf failed"); + return -1; + } if ((ret = getaddrinfo(hostname, port_str, &hints, &cache->first)) != 0) { gf_log ("resolver", GF_LOG_ERROR, "getaddrinfo failed (%s)", gai_strerror (ret)); @@ -269,82 +273,84 @@ gf_log_volume_file (FILE *specfp) static void gf_dump_config_flags (int fd) { + int ret = 0; + /* TODO: 'ret' is not checked properly, add this later */ - write (fd, "configuration details:\n", 22); + ret = write (fd, "configuration details:\n", 22); /* have argp */ #ifdef HAVE_ARGP - write (fd, "argp 1\n", 7); + ret = write (fd, "argp 1\n", 7); #endif /* ifdef if found backtrace */ #ifdef HAVE_BACKTRACE - write (fd, "backtrace 1\n", 12); + ret = write (fd, "backtrace 1\n", 12); #endif /* Berkeley-DB version has cursor->get() */ #ifdef HAVE_BDB_CURSOR_GET - write (fd, "bdb->cursor->get 1\n", 19); + ret = write (fd, "bdb->cursor->get 1\n", 19); #endif /* Define to 1 if you have the <db.h> header file. */ #ifdef HAVE_DB_H - write (fd, "db.h 1\n", 7); + ret = write (fd, "db.h 1\n", 7); #endif /* Define to 1 if you have the <dlfcn.h> header file. */ #ifdef HAVE_DLFCN_H - write (fd, "dlfcn 1\n", 8); + ret = write (fd, "dlfcn 1\n", 8); #endif /* define if fdatasync exists */ #ifdef HAVE_FDATASYNC - write (fd, "fdatasync 1\n", 12); + ret = write (fd, "fdatasync 1\n", 12); #endif /* Define to 1 if you have the `pthread' library (-lpthread). */ #ifdef HAVE_LIBPTHREAD - write (fd, "libpthread 1\n", 13); + ret = write (fd, "libpthread 1\n", 13); #endif /* define if llistxattr exists */ #ifdef HAVE_LLISTXATTR - write (fd, "llistxattr 1\n", 13); + ret = write (fd, "llistxattr 1\n", 13); #endif /* define if found setfsuid setfsgid */ #ifdef HAVE_SET_FSID - write (fd, "setfsid 1\n", 10); + ret = write (fd, "setfsid 1\n", 10); #endif /* define if found spinlock */ #ifdef HAVE_SPINLOCK - write (fd, "spinlock 1\n", 11); + ret = write (fd, "spinlock 1\n", 11); #endif /* Define to 1 if you have the <sys/epoll.h> header file. */ #ifdef HAVE_SYS_EPOLL_H - write (fd, "epoll.h 1\n", 10); + ret = write (fd, "epoll.h 1\n", 10); #endif /* Define to 1 if you have the <sys/extattr.h> header file. */ #ifdef HAVE_SYS_EXTATTR_H - write (fd, "extattr.h 1\n", 12); + ret = write (fd, "extattr.h 1\n", 12); #endif /* Define to 1 if you have the <sys/xattr.h> header file. */ #ifdef HAVE_SYS_XATTR_H - write (fd, "xattr.h 1\n", 10); + ret = write (fd, "xattr.h 1\n", 10); #endif /* define if found st_atim.tv_nsec */ #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - write (fd, "st_atim.tv_nsec 1\n", 18); + ret = write (fd, "st_atim.tv_nsec 1\n", 18); #endif /* define if found st_atimespec.tv_nsec */ #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC - write (fd, "st_atimespec.tv_nsec 1\n",23); + ret = write (fd, "st_atimespec.tv_nsec 1\n",23); #endif /* Define to the full name and version of this package. */ @@ -352,7 +358,7 @@ gf_dump_config_flags (int fd) { char msg[128]; sprintf (msg, "package-string: %s\n", PACKAGE_STRING); - write (fd, msg, strlen (msg)); + ret = write (fd, msg, strlen (msg)); } #endif @@ -366,12 +372,12 @@ void gf_print_trace (int32_t signum) { extern FILE *gf_log_logfile; - int fd = fileno (gf_log_logfile); - char msg[1024]; - + char msg[1024] = {0,}; + int fd = fileno (gf_log_logfile); + int ret = 0; /* Pending frames, (if any), list them in order */ - write (fd, "pending frames:\n", 16); + ret = write (fd, "pending frames:\n", 16); { extern glusterfs_ctx_t *gf_global_ctx; glusterfs_ctx_t *ctx = gf_global_ctx; @@ -394,17 +400,17 @@ gf_print_trace (int32_t signum) tmp->root->type, gf_cbk_list[tmp->root->op]); - write (fd, msg, strlen (msg)); + ret = write (fd, msg, strlen (msg)); trav = trav->next; } - write (fd, "\n", 1); + ret = write (fd, "\n", 1); } sprintf (msg, "patchset: %s\n", GLUSTERFS_REPOSITORY_REVISION); - write (fd, msg, strlen (msg)); + ret = write (fd, msg, strlen (msg)); sprintf (msg, "signal received: %d\n", signum); - write (fd, msg, strlen (msg)); + ret = write (fd, msg, strlen (msg)); gf_dump_config_flags (fd); #if HAVE_BACKTRACE @@ -416,7 +422,7 @@ gf_print_trace (int32_t signum) size = backtrace (array, 200); backtrace_symbols_fd (&array[1], size-1, fd); sprintf (msg, "---------\n"); - write (fd, msg, strlen (msg)); + ret = write (fd, msg, strlen (msg)); } #endif /* HAVE_BACKTRACE */ diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 2162c97952c..fd1be7318a3 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -213,9 +213,14 @@ _dict_set (dict_t *this, data_pair_t *pair; char key_free = 0; int tmp = 0; + int ret = 0; if (!key) { - asprintf (&key, "ref:%p", value); + ret = asprintf (&key, "ref:%p", value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return -1; + } key_free = 1; } @@ -715,6 +720,7 @@ dict_to_iovec (dict_t *this, data_t * int_to_data (int64_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -723,7 +729,11 @@ int_to_data (int64_t value) return NULL; } - asprintf (&data->data, "%"PRId64, value); + ret = asprintf (&data->data, "%"PRId64, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } data->len = strlen (data->data) + 1; return data; @@ -732,6 +742,7 @@ int_to_data (int64_t value) data_t * data_from_int64 (int64_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -739,7 +750,11 @@ data_from_int64 (int64_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRId64, value); + ret = asprintf (&data->data, "%"PRId64, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } data->len = strlen (data->data) + 1; return data; @@ -748,6 +763,7 @@ data_from_int64 (int64_t value) data_t * data_from_int32 (int32_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -755,7 +771,12 @@ data_from_int32 (int32_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRId32, value); + ret = asprintf (&data->data, "%"PRId32, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; @@ -764,7 +785,7 @@ data_from_int32 (int32_t value) data_t * data_from_int16 (int16_t value) { - + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -772,7 +793,12 @@ data_from_int16 (int16_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRId16, value); + ret = asprintf (&data->data, "%"PRId16, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; @@ -781,7 +807,7 @@ data_from_int16 (int16_t value) data_t * data_from_int8 (int8_t value) { - + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -789,7 +815,12 @@ data_from_int8 (int8_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%d", value); + ret = asprintf (&data->data, "%d", value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; @@ -798,6 +829,7 @@ data_from_int8 (int8_t value) data_t * data_from_uint64 (uint64_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -805,7 +837,12 @@ data_from_uint64 (uint64_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRIu64, value); + ret = asprintf (&data->data, "%"PRIu64, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; @@ -840,6 +877,7 @@ data_from_double (double value) data_t * data_from_uint32 (uint32_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -847,7 +885,12 @@ data_from_uint32 (uint32_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRIu32, value); + ret = asprintf (&data->data, "%"PRIu32, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; @@ -857,6 +900,7 @@ data_from_uint32 (uint32_t value) data_t * data_from_uint16 (uint16_t value) { + int ret = 0; data_t *data = get_new_data (); if (!data) { @@ -864,7 +908,12 @@ data_from_uint16 (uint16_t value) "@data - NULL returned by CALLOC"); return NULL; } - asprintf (&data->data, "%"PRIu16, value); + ret = asprintf (&data->data, "%"PRIu16, value); + if (-1 == ret) { + gf_log ("dict", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } + data->len = strlen (data->data) + 1; return data; diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index 858f7e14d93..9796071d87e 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -968,9 +968,9 @@ inode_table_t * inode_table_new (size_t lru_limit, xlator_t *xl) { inode_table_t *new = NULL; + int ret = 0; int i = 0; - new = (void *)calloc (1, sizeof (*new)); if (!new) return NULL; @@ -1009,7 +1009,11 @@ inode_table_new (size_t lru_limit, xlator_t *xl) INIT_LIST_HEAD (&new->lru); INIT_LIST_HEAD (&new->purge); - asprintf (&new->name, "%s/inode", xl->name); + ret = asprintf (&new->name, "%s/inode", xl->name); + if (-1 == ret) { + /* TODO: This should be ok to continue, check with avati */ + ; + } __inode_table_init_root (new); diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index c345faf03d3..7e1e56f875f 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -430,7 +430,8 @@ _gf_log (const char *domain, const char *file, const char *function, int line, char timestr[256]; char *str1, *str2, *msg; - size_t len = 0; + size_t len = 0; + int ret = 0; static char *level_strings[] = {"", /* NONE */ "C", /* CRITICAL */ @@ -488,12 +489,18 @@ log: else basename = file; - asprintf (&str1, "[%s] %s [%s:%d:%s] %s: ", - timestr, level_strings[level], - basename, line, function, - domain); + ret = asprintf (&str1, "[%s] %s [%s:%d:%s] %s: ", + timestr, level_strings[level], + basename, line, function, + domain); + if (-1 == ret) { + goto out; + } - vasprintf (&str2, fmt, ap); + ret = vasprintf (&str2, fmt, ap); + if (-1 == ret) { + goto out; + } va_end (ap); @@ -540,11 +547,15 @@ struct _client_log *client_logs = NULL; static void client_log_init (struct _client_log *cl, char *identifier) { + int ret = 0; char *path = NULL; cl->identifier = identifier; - asprintf (&path, "%s.client-%s", filename, identifier); + ret = asprintf (&path, "%s.client-%s", filename, identifier); + if (-1 == ret) { + return; + } cl->file = fopen (path, "a"); FREE (path); diff --git a/libglusterfs/src/scheduler.c b/libglusterfs/src/scheduler.c index 0b5df51b3ed..f799b52fcf6 100644 --- a/libglusterfs/src/scheduler.c +++ b/libglusterfs/src/scheduler.c @@ -35,14 +35,19 @@ get_scheduler (xlator_t *xl, const char *name) volume_opt_list_t *vol_opt = NULL; char *sched_file = NULL; void *handle = NULL; - + int ret = 0; + if (name == NULL) { gf_log ("scheduler", GF_LOG_ERROR, "'name' not specified, EINVAL"); return NULL; } - asprintf (&sched_file, "%s/%s.so", SCHEDULERDIR, name); + ret = asprintf (&sched_file, "%s/%s.so", SCHEDULERDIR, name); + if (-1 == ret) { + gf_log ("scheduler", GF_LOG_ERROR, "asprintf failed"); + return NULL; + } gf_log ("scheduler", GF_LOG_DEBUG, "attempt to load file %s.so", name); diff --git a/libglusterfs/src/transport.c b/libglusterfs/src/transport.c index 244aa960b78..7464ffd664f 100644 --- a/libglusterfs/src/transport.c +++ b/libglusterfs/src/transport.c @@ -136,7 +136,11 @@ transport_load (dict_t *options, goto fail; } - asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); + ret = asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); + if (-1 == ret) { + gf_log ("transport", GF_LOG_ERROR, "asprintf failed"); + goto fail; + } gf_log ("transport", GF_LOG_DEBUG, "attempt to load file %s", name); diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 351e2434467..a3f8ea8fc2e 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -679,6 +679,7 @@ int32_t xlator_set_type (xlator_t *xl, const char *type) { + int ret = 0; char *name = NULL; void *handle = NULL; volume_opt_list_t *vol_opt = NULL; @@ -690,7 +691,11 @@ xlator_set_type (xlator_t *xl, xl->type = strdup (type); - asprintf (&name, "%s/%s.so", XLATORDIR, type); + ret = asprintf (&name, "%s/%s.so", XLATORDIR, type); + if (-1 == ret) { + gf_log ("xlator", GF_LOG_ERROR, "asprintf failed"); + return -1; + } gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name); |