Blame support/capture_subprocess.h

Packit 6c4009
/* Capture output from a subprocess.
Packit 6c4009
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef SUPPORT_CAPTURE_SUBPROCESS_H
Packit 6c4009
#define SUPPORT_CAPTURE_SUBPROCESS_H
Packit 6c4009
Packit 6c4009
#include <support/xmemstream.h>
Packit 6c4009
Packit 6c4009
struct support_capture_subprocess
Packit 6c4009
{
Packit 6c4009
  struct xmemstream out;
Packit 6c4009
  struct xmemstream err;
Packit 6c4009
  int status;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Invoke CALLBACK (CLOSURE) in a subprocess and capture standard
Packit 6c4009
   output, standard error, and the exit status.  The out.buffer and
Packit 6c4009
   err.buffer members in the result are null-terminated strings which
Packit 6c4009
   can be examined by the caller (out.out and err.out are NULL).  */
Packit 6c4009
struct support_capture_subprocess support_capture_subprocess
Packit 6c4009
  (void (*callback) (void *), void *closure);
Packit 6c4009
Packit Service 41f5ad
/* Issue FILE with ARGV arguments by using posix_spawn and capture standard
Packit Service 41f5ad
   output, standard error, and the exit status.  The out.buffer and err.buffer
Packit Service 41f5ad
   are handle as support_capture_subprocess.  */
Packit Service 41f5ad
struct support_capture_subprocess support_capture_subprogram
Packit Service 41f5ad
  (const char *file, char *const argv[]);
Packit Service 41f5ad
Packit 6c4009
/* Deallocate the subprocess data captured by
Packit 6c4009
   support_capture_subprocess.  */
Packit 6c4009
void support_capture_subprocess_free (struct support_capture_subprocess *);
Packit 6c4009
Packit 6c4009
enum support_capture_allow
Packit 6c4009
{
Packit 6c4009
  /* No output is allowed.  */
Packit 6c4009
  sc_allow_none = 0x01,
Packit 6c4009
  /* Output to stdout is permitted.  */
Packit 6c4009
  sc_allow_stdout = 0x02,
Packit 6c4009
  /* Output to standard error is permitted.  */
Packit 6c4009
  sc_allow_stderr = 0x04,
Packit 6c4009
};
Packit 6c4009
Packit Service 8bbac7
/* Check that the subprocess exited with STATUS and that only the
Packit Service 8bbac7
   allowed outputs happened.  ALLOWED is a combination of
Packit Service 8bbac7
   support_capture_allow flags.  Report errors under the CONTEXT
Packit Service 8bbac7
   message.  */
Packit 6c4009
void support_capture_subprocess_check (struct support_capture_subprocess *,
Packit Service 8bbac7
                                       const char *context, int status,
Packit Service 8bbac7
                                       int allowed)
Packit 6c4009
  __attribute__ ((nonnull (1, 2)));
Packit 6c4009
Packit 6c4009
#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */