summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-05-03 13:25:41 -0700
committerAnand Avati <avati@redhat.com>2014-05-05 17:29:59 -0700
commita05c579f1c3695c4ddead0a5cfc2c92422bd4f8f (patch)
tree769ad843f263d354bcf6ed544093ac562cc8b2f4 /libglusterfs
parentf01626d5bad8eb0298897e90a124301008cdd0da (diff)
meta: print in json for stack/frames, cmdline and version
- Follow formatting rules based on RFC4627 - http://www.ietf.org/rfc/rfc4627.txt - Add checks for json in regression test meta.t Change-Id: I480d32ce042b202d3ed8939623c629a03b458551 BUG: 1089216 Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Reviewed-on: http://review.gluster.org/7653 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/strfd.c107
-rw-r--r--libglusterfs/src/strfd.h10
2 files changed, 56 insertions, 61 deletions
diff --git a/libglusterfs/src/strfd.c b/libglusterfs/src/strfd.c
index f5b7b94bfa1..3eda05c2dbc 100644
--- a/libglusterfs/src/strfd.c
+++ b/libglusterfs/src/strfd.c
@@ -20,83 +20,78 @@
#include "strfd.h"
#include "common-utils.h"
-
strfd_t *
strfd_open ()
{
- strfd_t *strfd = NULL;
+ strfd_t *strfd = NULL;
- strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t);
+ strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t);
- return strfd;
+ return strfd;
}
-
int
strvprintf (strfd_t *strfd, const char *fmt, va_list ap)
{
- char *str = NULL;
- int size = 0;
-
- size = vasprintf (&str, fmt, ap);
-
- if (size < 0)
- return size;
-
- if (!strfd->alloc_size) {
- strfd->data = GF_CALLOC (max(size + 1, 4096), 1,
- gf_common_mt_strfd_data_t);
- if (!strfd->data) {
- free (str); /* NOT GF_FREE */
- return -1;
- }
- strfd->alloc_size = max(size + 1, 4096);
- }
-
- if (strfd->alloc_size <= (strfd->size + size)) {
- char *tmp_ptr = NULL;
- int new_size = max ((strfd->alloc_size * 2),
- gf_roundup_next_power_of_two (strfd->size + size + 1));
- tmp_ptr = GF_REALLOC (strfd->data, new_size);
- if (!tmp_ptr) {
- free (str); /* NOT GF_FREE */
- return -1;
- }
- strfd->alloc_size = new_size;
- strfd->data = tmp_ptr;
- }
-
- // Copy the trailing '\0', but do not account for it in ->size.
- // This allows safe use of strfd->data as a string.
- memcpy (strfd->data + strfd->size, str, size + 1);
- strfd->size += size;
-
- free (str); /* NOT GF_FREE */
-
- return size;
+ char *str = NULL;
+ int size = 0;
+
+ size = vasprintf (&str, fmt, ap);
+
+ if (size < 0)
+ return size;
+
+ if (!strfd->alloc_size) {
+ strfd->data = GF_CALLOC (max(size + 1, 4096), 1,
+ gf_common_mt_strfd_data_t);
+ if (!strfd->data) {
+ free (str); /* NOT GF_FREE */
+ return -1;
+ }
+ strfd->alloc_size = max(size + 1, 4096);
+ }
+
+ if (strfd->alloc_size <= (strfd->size + size)) {
+ char *tmp_ptr = NULL;
+ int new_size = max ((strfd->alloc_size * 2),
+ gf_roundup_next_power_of_two (strfd->size + size + 1));
+ tmp_ptr = GF_REALLOC (strfd->data, new_size);
+ if (!tmp_ptr) {
+ free (str); /* NOT GF_FREE */
+ return -1;
+ }
+ strfd->alloc_size = new_size;
+ strfd->data = tmp_ptr;
+ }
+
+ /* Copy the trailing '\0', but do not account for it in ->size.
+ This allows safe use of strfd->data as a string. */
+ memcpy (strfd->data + strfd->size, str, size + 1);
+ strfd->size += size;
+
+ free (str); /* NOT GF_FREE */
+
+ return size;
}
-
int
strprintf (strfd_t *strfd, const char *fmt, ...)
{
- int ret = 0;
- va_list ap;
+ int ret = 0;
+ va_list ap;
- va_start (ap, fmt);
- ret = strvprintf (strfd, fmt, ap);
- va_end (ap);
+ va_start (ap, fmt);
+ ret = strvprintf (strfd, fmt, ap);
+ va_end (ap);
- return ret;
+ return ret;
}
-
int
strfd_close (strfd_t *strfd)
{
- GF_FREE (strfd->data);
- GF_FREE (strfd);
+ GF_FREE (strfd->data);
+ GF_FREE (strfd);
- return 0;
+ return 0;
}
-
diff --git a/libglusterfs/src/strfd.h b/libglusterfs/src/strfd.h
index a9e6eaa87bc..9084e235eef 100644
--- a/libglusterfs/src/strfd.h
+++ b/libglusterfs/src/strfd.h
@@ -12,16 +12,16 @@
#define _STRFD_H
typedef struct {
- void *data;
- size_t alloc_size;
- size_t size;
- off_t pos;
+ void *data;
+ size_t alloc_size;
+ size_t size;
+ off_t pos;
} strfd_t;
strfd_t *strfd_open();
int strprintf(strfd_t *strfd, const char *fmt, ...)
- __attribute__ ((__format__ (__printf__, 2, 3)));
+ __attribute__ ((__format__ (__printf__, 2, 3)));
int strvprintf(strfd_t *strfd, const char *fmt, va_list ap);