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 Bot 40fc07
/* Issue FILE with ARGV arguments by using posix_spawn and capture standard
Packit Bot 40fc07
   output, standard error, and the exit status.  The out.buffer and err.buffer
Packit Bot 40fc07
   are handle as support_capture_subprocess.  */
Packit Bot 40fc07
struct support_capture_subprocess support_capture_subprogram
Packit Bot 40fc07
  (const char *file, char *const argv[]);
Packit Bot 40fc07
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 Bot 2f1cd5
/* Check that the subprocess exited and that only the allowed outputs
Packit Bot 2f1cd5
   happened.  If STATUS_OR_SIGNAL is nonnegative, it is the expected
Packit Bot 2f1cd5
   (decoded) exit status of the process, as returned by WEXITSTATUS.
Packit Bot 2f1cd5
   If STATUS_OR_SIGNAL is negative, -STATUS_OR_SIGNAL is the expected
Packit Bot 2f1cd5
   termination signal, as returned by WTERMSIG.  ALLOWED is a
Packit Bot 2f1cd5
   combination of support_capture_allow flags.  Report errors under
Packit Bot 2f1cd5
   the CONTEXT message.  */
Packit 6c4009
void support_capture_subprocess_check (struct support_capture_subprocess *,
Packit Bot 2f1cd5
                                       const char *context,
Packit Bot 2f1cd5
                                       int status_or_signal, int allowed)
Packit 6c4009
  __attribute__ ((nonnull (1, 2)));
Packit 6c4009
Packit 6c4009
#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */