1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
3 
4    GNU Mailutils is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8 
9    GNU Mailutils is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
16 
17 #ifndef _MAILUTILS_PROG_H
18 #define _MAILUTILS_PROG_H
19 
20 #include <sys/time.h>
21 #include <sys/resource.h>
22 #include <mailutils/types.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define MU_PROG_LIMIT_AS      0
29 #define MU_PROG_LIMIT_CPU     1
30 #define MU_PROG_LIMIT_DATA    2
31 #define MU_PROG_LIMIT_FSIZE   3
32 #define MU_PROG_LIMIT_NPROC   4
33 #define MU_PROG_LIMIT_CORE    5
34 #define MU_PROG_LIMIT_MEMLOCK 6
35 #define MU_PROG_LIMIT_NOFILE  7
36 #define MU_PROG_LIMIT_RSS     8
37 #define MU_PROG_LIMIT_STACK   9
38 
39 #define _MU_PROG_LIMIT_MAX   10
40 
41 #define MU_PROG_HINT_WORKDIR     0x0001  /* Workdir is set */
42 #define MU_PROG_HINT_PRIO        0x0002  /* Prio is set */
43 #define MU_PROG_HINT_INPUT       0x0004  /* Input stream is set */
44 #define MU_PROG_HINT_UID         0x0008  /* Uid is set */
45 #define MU_PROG_HINT_GID         0x0010  /* Supplementary gids are set */
46 #define MU_PROG_HINT_ERRTOOUT    0x0020  /* Redirect stderr to stdout */
47 #define MU_PROG_HINT_ERRTOSTREAM 0x0040  /* Redirect stderr to errstream */
48 #define MU_PROG_HINT_IGNOREFAIL  0x0080  /* Ignore hint setup failures */
49 #define _MU_PROG_HINT_MASK       0x00ff
50 #define MU_PROG_HINT_LIMIT(n) (0x100 << (n)) /* MU_PROG_LIMIT_n is set */
51 
52 struct mu_prog_hints
53 {
54   char *mu_prog_workdir;                    /* Working directory */
55   uid_t mu_prog_uid;                        /* Run as this user */
56   gid_t *mu_prog_gidv;                      /* Array of supplementary gids */
57   size_t mu_prog_gidc;                      /* Number of elements in gidv */
58   rlim_t mu_prog_limit[_MU_PROG_LIMIT_MAX]; /* Limits */
59   int mu_prog_prio;                         /* Scheduling priority */
60   mu_stream_t mu_prog_input;                /* Input stream */
61   mu_stream_t mu_prog_error;                /* Error stream */
62 };
63 
64 int mu_prog_stream_create (mu_stream_t *pstream,
65 			   const char *progname,
66 			   size_t argc, char **argv,
67 			   int hflags,
68 			   struct mu_prog_hints *hints,
69 			   int flags);
70 int mu_command_stream_create (mu_stream_t *pstream, const char *command,
71 			      int flags);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif
78 
79