View | Details | Raw Unified | Return to bug 18433 | Differences between
and this patch

Collapse All | Expand All

(-)a/ChangeLog (+5 lines)
Lines 1-3 Link Here
1
2015-09-13  Navid Rahimi  <rahimi.nv@gmail.com>
2
3
	[BZ #18433]
4
	* sysdeps/posix/spawni.c (__spawni): Check child status.
5
1
2015-09-12  Rasmus Villemoes  <rv@rasmusvillemoes.dk>
6
2015-09-12  Rasmus Villemoes  <rv@rasmusvillemoes.dk>
2
7
(-)a/sysdeps/posix/spawni.c (-16 / +44 lines)
Lines 89-94 __spawni (pid_t *pid, const char *file, Link Here
89
  char *path, *p, *name;
89
  char *path, *p, *name;
90
  size_t len;
90
  size_t len;
91
  size_t pathlen;
91
  size_t pathlen;
92
  int pipefd[2];
93
94
  errno = 0;
95
  /* Open Read/Write pipe for parent/child communication.  */
96
#ifdef __ASSUME_PIPE2
97
  if (__pipe2 (pipefd, O_CLOEXEC))
98
    return errno;
99
#else
100
  if (__pipe (pipefd))
101
    return errno;
102
  if (__fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1
103
      || __fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1)
104
    {
105
      close(pipefd[0]);
106
      close(pipefd[1]);
107
      return errno;
108
    }
109
#endif
92
110
93
  /* Do this once.  */
111
  /* Do this once.  */
94
  short int flags = attrp == NULL ? 0 : attrp->__flags;
112
  short int flags = attrp == NULL ? 0 : attrp->__flags;
Lines 109-128 __spawni (pid_t *pid, const char *file, Link Here
109
127
110
  if (new_pid != 0)
128
  if (new_pid != 0)
111
    {
129
    {
112
      if (new_pid < 0)
130
      __close (pipefd[1]);
131
      if (new_pid < 0){
132
	__close (pipefd[0]);
113
	return errno;
133
	return errno;
114
134
      }
115
      /* The call was successful.  Store the PID if necessary.  */
135
      /* The call was successful.  Store the PID if necessary.  */
116
      if (pid != NULL)
136
      if (pid != NULL)
117
	*pid = new_pid;
137
	*pid = new_pid;
118
138
119
      return 0;
139
      __read (pipefd[0], &errno, sizeof errno);
140
      __close (pipefd[0]);
141
      return errno;
120
    }
142
    }
143
  else
144
    __close (pipefd[0]);
121
145
122
  /* Set signal mask.  */
146
  /* Set signal mask.  */
123
  if ((flags & POSIX_SPAWN_SETSIGMASK) != 0
147
  if ((flags & POSIX_SPAWN_SETSIGMASK) != 0
124
      && __sigprocmask (SIG_SETMASK, &attrp->__ss, NULL) != 0)
148
      && __sigprocmask (SIG_SETMASK, &attrp->__ss, NULL) != 0)
125
    _exit (SPAWN_ERROR);
149
    goto fail;
126
150
127
  /* Set signal default action.  */
151
  /* Set signal default action.  */
128
  if ((flags & POSIX_SPAWN_SETSIGDEF) != 0)
152
  if ((flags & POSIX_SPAWN_SETSIGDEF) != 0)
Lines 140-146 __spawni (pid_t *pid, const char *file, Link Here
140
      for (sig = 1; sig <= _NSIG; ++sig)
164
      for (sig = 1; sig <= _NSIG; ++sig)
141
	if (__sigismember (&attrp->__sd, sig) != 0
165
	if (__sigismember (&attrp->__sd, sig) != 0
142
	    && __sigaction (sig, &sa, NULL) != 0)
166
	    && __sigaction (sig, &sa, NULL) != 0)
143
	  _exit (SPAWN_ERROR);
167
	  goto fail;
144
168
145
    }
169
    }
146
170
Lines 150-174 __spawni (pid_t *pid, const char *file, Link Here
150
      == POSIX_SPAWN_SETSCHEDPARAM)
174
      == POSIX_SPAWN_SETSCHEDPARAM)
151
    {
175
    {
152
      if (__sched_setparam (0, &attrp->__sp) == -1)
176
      if (__sched_setparam (0, &attrp->__sp) == -1)
153
	_exit (SPAWN_ERROR);
177
	goto fail;
154
    }
178
    }
155
  else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0)
179
  else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0)
156
    {
180
    {
157
      if (__sched_setscheduler (0, attrp->__policy, &attrp->__sp) == -1)
181
      if (__sched_setscheduler (0, attrp->__policy, &attrp->__sp) == -1)
158
	_exit (SPAWN_ERROR);
182
	goto fail;
159
    }
183
    }
160
#endif
184
#endif
161
185
162
  /* Set the process group ID.  */
186
  /* Set the process group ID.  */
163
  if ((flags & POSIX_SPAWN_SETPGROUP) != 0
187
  if ((flags & POSIX_SPAWN_SETPGROUP) != 0
164
      && __setpgid (0, attrp->__pgrp) != 0)
188
      && __setpgid (0, attrp->__pgrp) != 0)
165
    _exit (SPAWN_ERROR);
189
    goto fail;
166
190
167
  /* Set the effective user and group IDs.  */
191
  /* Set the effective user and group IDs.  */
168
  if ((flags & POSIX_SPAWN_RESETIDS) != 0
192
  if ((flags & POSIX_SPAWN_RESETIDS) != 0
169
      && (local_seteuid (__getuid ()) != 0
193
      && (local_seteuid (__getuid ()) != 0
170
	  || local_setegid (__getgid ()) != 0))
194
	  || local_setegid (__getgid ()) != 0))
171
    _exit (SPAWN_ERROR);
195
    goto fail;
172
196
173
  /* Execute the file actions.  */
197
  /* Execute the file actions.  */
174
  if (file_actions != NULL)
198
  if (file_actions != NULL)
Lines 196-202 __spawni (pid_t *pid, const char *file, Link Here
196
		  if (action->action.close_action.fd < 0
220
		  if (action->action.close_action.fd < 0
197
		      || action->action.close_action.fd >= fdlimit.rlim_cur)
221
		      || action->action.close_action.fd >= fdlimit.rlim_cur)
198
		    /* Signal the error.  */
222
		    /* Signal the error.  */
199
		    _exit (SPAWN_ERROR);
223
		    goto fail;
200
		}
224
		}
201
	      break;
225
	      break;
202
226
Lines 209-215 __spawni (pid_t *pid, const char *file, Link Here
209
233
210
		if (new_fd == -1)
234
		if (new_fd == -1)
211
		  /* The `open' call failed.  */
235
		  /* The `open' call failed.  */
212
		  _exit (SPAWN_ERROR);
236
		  goto fail;
213
237
214
		/* Make sure the desired file descriptor is used.  */
238
		/* Make sure the desired file descriptor is used.  */
215
		if (new_fd != action->action.open_action.fd)
239
		if (new_fd != action->action.open_action.fd)
Lines 217-227 __spawni (pid_t *pid, const char *file, Link Here
217
		    if (__dup2 (new_fd, action->action.open_action.fd)
241
		    if (__dup2 (new_fd, action->action.open_action.fd)
218
			!= action->action.open_action.fd)
242
			!= action->action.open_action.fd)
219
		      /* The `dup2' call failed.  */
243
		      /* The `dup2' call failed.  */
220
		      _exit (SPAWN_ERROR);
244
		      goto fail;
221
245
222
		    if (close_not_cancel (new_fd) != 0)
246
		    if (close_not_cancel (new_fd) != 0)
223
		      /* The `close' call failed.  */
247
		      /* The `close' call failed.  */
224
		      _exit (SPAWN_ERROR);
248
		      goto fail;
225
		  }
249
		  }
226
	      }
250
	      }
227
	      break;
251
	      break;
Lines 231-237 __spawni (pid_t *pid, const char *file, Link Here
231
			  action->action.dup2_action.newfd)
255
			  action->action.dup2_action.newfd)
232
		  != action->action.dup2_action.newfd)
256
		  != action->action.dup2_action.newfd)
233
		/* The `dup2' call failed.  */
257
		/* The `dup2' call failed.  */
234
		_exit (SPAWN_ERROR);
258
		goto fail;
235
	      break;
259
	      break;
236
	    }
260
	    }
237
	}
261
	}
Lines 245-251 __spawni (pid_t *pid, const char *file, Link Here
245
      maybe_script_execute (file, argv, envp, xflags);
269
      maybe_script_execute (file, argv, envp, xflags);
246
270
247
      /* Oh, oh.  `execve' returns.  This is bad.  */
271
      /* Oh, oh.  `execve' returns.  This is bad.  */
248
      _exit (SPAWN_ERROR);
272
      goto fail;
249
    }
273
    }
250
274
251
  /* We have to search for FILE on the path.  */
275
  /* We have to search for FILE on the path.  */
Lines 304-314 __spawni (pid_t *pid, const char *file, Link Here
304
	  /* Some other error means we found an executable file, but
328
	  /* Some other error means we found an executable file, but
305
	     something went wrong executing it; return the error to our
329
	     something went wrong executing it; return the error to our
306
	     caller.  */
330
	     caller.  */
307
	  _exit (SPAWN_ERROR);
331
	  goto fail;
308
	    }
332
	    }
309
    }
333
    }
310
  while (*p++ != '\0');
334
  while (*p++ != '\0');
311
335
336
 fail:
337
  /* Send parent what was the reason of failure.  */
338
  __write (pipefd[1], &errno, sizeof errno);
339
  __close (pipefd[1]);
312
  /* Return with an error.  */
340
  /* Return with an error.  */
313
  _exit (SPAWN_ERROR);
341
  _exit (SPAWN_ERROR);
314
}
342
}

Return to bug 18433