1/* Capture output from a subprocess.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef SUPPORT_CAPTURE_SUBPROCESS_H
20#define SUPPORT_CAPTURE_SUBPROCESS_H
21
22#include <support/xmemstream.h>
23
24struct support_capture_subprocess
25{
26 struct xmemstream out;
27 struct xmemstream err;
28 int status;
29};
30
31/* Invoke CALLBACK (CLOSURE) in a subprocess and capture standard
32 output, standard error, and the exit status. The out.buffer and
33 err.buffer members in the result are null-terminated strings which
34 can be examined by the caller (out.out and err.out are NULL). */
35struct support_capture_subprocess support_capture_subprocess
36 (void (*callback) (void *), void *closure);
37
38/* Deallocate the subprocess data captured by
39 support_capture_subprocess. */
40void support_capture_subprocess_free (struct support_capture_subprocess *);
41
42enum support_capture_allow
43{
44 /* No output is allowed. */
45 sc_allow_none = 0x01,
46 /* Output to stdout is permitted. */
47 sc_allow_stdout = 0x02,
48 /* Output to standard error is permitted. */
49 sc_allow_stderr = 0x04,
50};
51
52/* Check that the subprocess exited with STATUS and that only the
53 allowed outputs happened. ALLOWED is a combination of
54 support_capture_allow flags. Report errors under the CONTEXT
55 message. */
56void support_capture_subprocess_check (struct support_capture_subprocess *,
57 const char *context, int status,
58 int allowed)
59 __attribute__ ((nonnull (1, 2)));
60
61#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */
62