1 /* gspawn.c - Process launching
2 *
3 * Copyright 2000 Red Hat, Inc.
4 * g_execvpe implementation based on GNU libc execvp:
5 * Copyright 1991, 92, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
6 *
7 * SPDX-License-Identifier: LGPL-2.1-or-later
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "config.h"
24
25 #include <errno.h>
26
27 #include "glibintl.h"
28 #include "gspawn.h"
29
30 static inline gint
31 _g_spawn_exec_err_to_g_error (gint en)
32 {
33 switch (en)
34 {
35 #ifdef EACCES
36 case EACCES:
37 return G_SPAWN_ERROR_ACCES;
38 #endif
39
40 #ifdef EPERM
41 case EPERM:
42 return G_SPAWN_ERROR_PERM;
43 #endif
44
45 #ifdef E2BIG
46 case E2BIG:
47 return G_SPAWN_ERROR_TOO_BIG;
48 #endif
49
50 #ifdef ENOEXEC
51 case ENOEXEC:
52 return G_SPAWN_ERROR_NOEXEC;
53 #endif
54
55 #ifdef ENAMETOOLONG
56 case ENAMETOOLONG:
57 return G_SPAWN_ERROR_NAMETOOLONG;
58 #endif
59
60 #ifdef ENOENT
61 case ENOENT:
62 return G_SPAWN_ERROR_NOENT;
63 #endif
64
65 #ifdef ENOMEM
66 case ENOMEM:
67 return G_SPAWN_ERROR_NOMEM;
68 #endif
69
70 #ifdef ENOTDIR
71 case ENOTDIR:
72 return G_SPAWN_ERROR_NOTDIR;
73 #endif
74
75 #ifdef ELOOP
76 case ELOOP:
77 return G_SPAWN_ERROR_LOOP;
78 #endif
79
80 #ifdef ETXTBUSY
81 case ETXTBUSY:
82 return G_SPAWN_ERROR_TXTBUSY;
83 #endif
84
85 #ifdef EIO
86 case EIO:
87 return G_SPAWN_ERROR_IO;
88 #endif
89
90 #ifdef ENFILE
91 case ENFILE:
92 return G_SPAWN_ERROR_NFILE;
93 #endif
94
95 #ifdef EMFILE
96 case EMFILE:
97 return G_SPAWN_ERROR_MFILE;
98 #endif
99
100 #ifdef EINVAL
101 case EINVAL:
102 return G_SPAWN_ERROR_INVAL;
103 #endif
104
105 #ifdef EISDIR
106 case EISDIR:
107 return G_SPAWN_ERROR_ISDIR;
108 #endif
109
110 #ifdef ELIBBAD
111 case ELIBBAD:
112 return G_SPAWN_ERROR_LIBBAD;
113 #endif
114
115 default:
116 return G_SPAWN_ERROR_FAILED;
117 }
118 }
119
120 static inline gboolean
121 _g_spawn_invalid_source_fd (gint fd,
122 const gint *source_fds,
123 gsize n_fds,
124 GError **error)
125 {
126 gsize i;
127
128 for (i = 0; i < n_fds; i++)
129 if (fd == source_fds[i])
130 {
131 g_set_error (error,
132 G_SPAWN_ERROR,
133 G_SPAWN_ERROR_INVAL,
134 _("Invalid source FDs argument"));
135 return TRUE;
136 }
137
138 return FALSE;
139 }