+static int read_pipe(void *ctx, int fd, char **bufp, int *lenp)
+{
+ int rc, len, alloc_len;
+ char *buf;
+
+ alloc_len = 4096;
+ len = 0;
+
+ buf = talloc_array(ctx, char, alloc_len);
+
+ for (;;) {
+ rc = read(fd, buf, alloc_len - len - 1);
+ if (rc <= 0)
+ break;
+
+ len += rc;
+ if (len == alloc_len - 1) {
+ alloc_len *= 2;
+ buf = talloc_realloc(ctx, buf, char, alloc_len);
+ }
+ }
+
+ if (rc < 0) {
+ talloc_free(buf);
+ return rc;
+ }
+
+ buf[len] = '\0';
+ *bufp = buf;
+ *lenp = len;
+
+ return 0;
+}
+