summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2018-10-07 14:47:26 +0200
committerKarolin Seeger <kseeger@samba.org>2018-10-10 18:57:59 +0200
commita1a4e54cf0ee5c753425fbf7c3b1f78e98ed78c0 (patch)
tree1fa2c458b6381009414c712d66ac62fa8d94be33 /lib/util
parent33515c39b316c5658cd23b7ed0d24c5a83bba15d (diff)
downloadsamba-a1a4e54cf0ee5c753425fbf7c3b1f78e98ed78c0.tar.gz
lib: Avoid the use of open_memstream in tevent_req_profile_string
Solaris does not have it. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13629 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> (cherry picked from commit e7d3678ddb5916416193d553f3cc562627e7d8ab) Autobuild-User(v4-9-test): Karolin Seeger <kseeger@samba.org> Autobuild-Date(v4-9-test): Wed Oct 10 18:57:59 CEST 2018 on sn-devel-144
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/tevent_req_profile.c85
-rw-r--r--lib/util/tevent_req_profile.h8
2 files changed, 38 insertions, 55 deletions
diff --git a/lib/util/tevent_req_profile.c b/lib/util/tevent_req_profile.c
index 522741c5ede..2d280f78f32 100644
--- a/lib/util/tevent_req_profile.c
+++ b/lib/util/tevent_req_profile.c
@@ -29,10 +29,11 @@
#include "lib/util/time_basic.h"
#include "lib/util/memory.h"
-int tevent_req_profile_print(const struct tevent_req_profile *profile,
- FILE *fp,
- unsigned indent,
- unsigned max_indent)
+static bool tevent_req_profile_string_internal(
+ const struct tevent_req_profile *profile,
+ unsigned indent,
+ unsigned max_indent,
+ char **string)
{
struct timeval start, stop, diff;
struct timeval_buf start_buf, stop_buf;
@@ -44,7 +45,7 @@ int tevent_req_profile_print(const struct tevent_req_profile *profile,
const char *state_buf = NULL;
uint64_t user_error;
const struct tevent_req_profile *sub = NULL;
- int ret;
+ char *result;
tevent_req_profile_get_name(profile, &req_name);
@@ -85,8 +86,8 @@ int tevent_req_profile_print(const struct tevent_req_profile *profile,
break;
}
- ret = fprintf(
- fp,
+ result = talloc_asprintf_append_buffer(
+ *string,
"%*s[%s] %s [%s] %s [%s] [%ju.%.6ju] -> %s (%d %"PRIu64"))\n",
indent,
"",
@@ -100,72 +101,58 @@ int tevent_req_profile_print(const struct tevent_req_profile *profile,
state_buf,
(int)state,
user_error);
-
- if (ret < 0) {
- return ret;
+ if (result == NULL) {
+ return false;
}
+ *string = result;
indent += 1;
if (indent >= max_indent) {
- return ret;
+ return true;
}
for (sub = tevent_req_profile_get_subprofiles(profile);
sub != NULL;
sub = tevent_req_profile_next(sub)) {
- int subret;
-
- subret = tevent_req_profile_print(sub, fp, indent, max_indent);
- if (subret < 0) {
- return subret;
- }
-
- ret += subret;
-
- if (ret < subret) {
- /* overflow */
- return -1;
+ bool ret;
+
+ ret = tevent_req_profile_string_internal(
+ sub,
+ indent,
+ max_indent,
+ string);
+ if (!ret) {
+ return false;
}
}
- return ret;
+ return true;
}
-char *tevent_req_profile_string(const struct tevent_req_profile *profile,
- TALLOC_CTX *mem_ctx,
+char *tevent_req_profile_string(TALLOC_CTX *mem_ctx,
+ const struct tevent_req_profile *profile,
unsigned indent,
unsigned max_indent)
{
- FILE *fp = NULL;
- char *buf = NULL;
- size_t buflen = 0;
- char *result = NULL;
- int ret;
+ char *result;
+ bool ret;
- fp = open_memstream(&buf, &buflen);
- if (fp == NULL) {
+ result = talloc_strdup(mem_ctx, "");
+ if (result == NULL) {
return NULL;
}
- ret = tevent_req_profile_print(profile, fp, 0, max_indent);
- if (ret < 0) {
- goto done;
- }
-
- ret = fclose(fp);
- if (ret != 0) {
- goto done;
+ ret = tevent_req_profile_string_internal(
+ profile,
+ indent,
+ max_indent,
+ &result);
+ if (!ret) {
+ TALLOC_FREE(result);
+ return NULL;
}
- /*
- * A FILE* from open_memstream maintains the 0-byte at the end
- * beyond the reported length.
- */
- result = talloc_memdup(mem_ctx, buf, buflen+1);
-
-done:
- SAFE_FREE(buf);
return result;
}
diff --git a/lib/util/tevent_req_profile.h b/lib/util/tevent_req_profile.h
index 00dbc5a9cc2..3bcdbc1a289 100644
--- a/lib/util/tevent_req_profile.h
+++ b/lib/util/tevent_req_profile.h
@@ -29,12 +29,8 @@
#include "replace.h"
#include <tevent.h>
-int tevent_req_profile_print(const struct tevent_req_profile *profile,
- FILE *fp,
- unsigned indent,
- unsigned max_indent);
-char *tevent_req_profile_string(const struct tevent_req_profile *profile,
- TALLOC_CTX *mem_ctx,
+char *tevent_req_profile_string(TALLOC_CTX *mem_ctx,
+ const struct tevent_req_profile *profile,
unsigned indent,
unsigned max_indent);
ssize_t tevent_req_profile_pack(