Merge of VFS by Balasz Gerofi with Minix trunk.
[minix3.git] / servers / vfs / exec.c
blob10ca92d900b775c1f3fba0271f66a58bb8d4eb51
1 /* This file handles the EXEC system call. It performs the work as follows:
2 * - see if the permissions allow the file to be executed
3 * - read the header and extract the sizes
4 * - fetch the initial args and environment from the user space
5 * - allocate the memory for the new process
6 * - copy the initial stack from PM to the process
7 * - read in the text and data segments and copy to the process
8 * - take care of setuid and setgid bits
9 * - fix up 'mproc' table
10 * - tell kernel about EXEC
11 * - save offset to initial argc (for ps)
13 * The entry points into this file are:
14 * pm_exec: perform the EXEC system call
16 * Changes for VFS:
17 * Aug 2006 (Balazs Gerofi)
20 #include "fs.h"
21 #include <sys/stat.h>
22 #include <minix/callnr.h>
23 #include <minix/endpoint.h>
24 #include <minix/com.h>
25 #include <a.out.h>
26 #include <signal.h>
27 #include <string.h>
28 #include <dirent.h>
29 #include "fproc.h"
30 #include "param.h"
32 #include "vnode.h"
33 #include "vmnt.h"
34 #include <minix/vfsif.h>
36 FORWARD _PROTOTYPE( int exec_newmem, (int proc_e, vir_bytes text_bytes,
37 vir_bytes data_bytes, vir_bytes bss_bytes, vir_bytes tot_bytes,
38 vir_bytes frame_len, int sep_id,
39 Dev_t st_dev, ino_t st_ino, time_t st_ctime, char *progname,
40 int new_uid, int new_gid,
41 vir_bytes *stack_topp, int *load_textp, int *allow_setuidp) );
42 FORWARD _PROTOTYPE( int read_header, (struct vnode *vp, int *sep_id,
43 vir_bytes *text_bytes, vir_bytes *data_bytes,
44 vir_bytes *bss_bytes, phys_bytes *tot_bytes, vir_bytes *pc,
45 int *hdrlenp) );
46 FORWARD _PROTOTYPE( int patch_stack, (struct vnode *vp,
47 char stack[ARG_MAX], vir_bytes *stk_bytes) );
48 FORWARD _PROTOTYPE( int insert_arg, (char stack[ARG_MAX],
49 vir_bytes *stk_bytes, char *arg, int replace) );
50 FORWARD _PROTOTYPE( void patch_ptr, (char stack[ARG_MAX],
51 vir_bytes base) );
52 FORWARD _PROTOTYPE( int read_seg, (struct vnode *vp, off_t off,
53 int proc_e, int seg, phys_bytes seg_bytes) );
54 FORWARD _PROTOTYPE( void clo_exec, (struct fproc *rfp) );
56 #define ESCRIPT (-2000) /* Returned by read_header for a #! script. */
57 #define PTRSIZE sizeof(char *) /* Size of pointers in argv[] and envp[]. */
59 /*===========================================================================*
60 * pm_exec *
61 *===========================================================================*/
62 PUBLIC int pm_exec(proc_e, path, path_len, frame, frame_len)
63 int proc_e;
64 char *path;
65 vir_bytes path_len;
66 char *frame;
67 vir_bytes frame_len;
69 /* Perform the execve(name, argv, envp) call. The user library builds a
70 * complete stack image, including pointers, args, environ, etc. The stack
71 * is copied to a buffer inside FS, and then to the new core image.
73 int r, sep_id, round, proc_s, hdrlen, load_text, allow_setuid;
74 vir_bytes text_bytes, data_bytes, bss_bytes, pc;
75 phys_bytes tot_bytes; /* total space for program, including gap */
76 vir_bytes stack_top, vsp;
77 off_t off;
78 uid_t new_uid;
79 gid_t new_gid;
80 struct fproc *rfp;
81 struct vnode vn;
82 struct vmnt *vmp;
83 time_t v_ctime;
84 uid_t v_uid;
85 gid_t v_gid;
86 char *cp;
87 char progname[PROC_NAME_LEN];
88 static char mbuf[ARG_MAX]; /* buffer for stack and zeroes */
90 /* Request and response structures */
91 struct lookup_req lookup_req;
92 struct access_req access_req;
93 struct open_req open_req;
94 struct node_details res;
96 okendpt(proc_e, &proc_s);
97 rfp= fp= &fproc[proc_s];
98 who_e= proc_e;
99 who_p= proc_s;
100 super_user = (fp->fp_effuid == SU_UID ? TRUE : FALSE); /* su? */
102 /* Get the exec file name. */
103 r= fetch_name(path, path_len, 0);
104 if (r != OK)
106 printf("pm_exec: fetch_name failed\n");
107 return(r); /* file name not in user data segment */
110 /* Fetch the stack from the user before destroying the old core image. */
111 if (frame_len > ARG_MAX)
113 printf("pm_exec: bad frame_len\n");
114 return(ENOMEM); /* stack too big */
116 r = sys_datacopy(proc_e, (vir_bytes) frame,
117 SELF, (vir_bytes) mbuf, (phys_bytes)frame_len);
118 /* can't fetch stack (e.g. bad virtual addr) */
119 if (r != OK)
121 printf("pm_exec: sys_datacopy failed\n");
122 return(r);
125 /* The default is the keep the original user and group IDs */
126 new_uid= rfp->fp_effuid;
127 new_gid= rfp->fp_effgid;
129 for (round= 0; round < 2; round++)
130 /* round = 0 (first attempt), or 1 (interpreted script) */
132 /* Save the name of the program */
133 (cp= strrchr(user_fullpath, '/')) ? cp++ : (cp= user_fullpath);
135 strncpy(progname, cp, PROC_NAME_LEN-1);
136 progname[PROC_NAME_LEN-1] = '\0';
138 /* Fill in lookup request fields */
139 lookup_req.path = user_fullpath;
140 lookup_req.lastc = NULL;
141 lookup_req.flags = EAT_PATH;
143 /* Request lookup */
144 if ((r = lookup(&lookup_req, &res)) != OK) return r;
146 if ((res.fmode & I_TYPE) != I_REGULAR) {
147 return ENOEXEC;
149 else {
150 /* Fill in request fields */
151 access_req.fs_e = res.fs_e;
152 access_req.amode = X_BIT;
153 access_req.inode_nr = res.inode_nr;
154 access_req.uid = fp->fp_effuid;
155 access_req.gid = fp->fp_effgid;
158 /* Issue request */
159 if ((r = req_access(&access_req)) != OK) {
160 printf("VFSexec: access failed\n");
161 return r;
165 /* Open request. */
166 open_req.inode_nr = res.inode_nr;
167 open_req.fs_e = res.fs_e;
168 open_req.oflags = 0;
169 open_req.omode = 0;
170 open_req.lastc = NULL;
171 open_req.uid = 0;
172 open_req.gid = 0;
174 /* Issue request */
175 if ((r = req_open(&open_req, &res)) != OK) {
176 printf("VFSexec: open failed\n");
177 return r;
180 /* Use the vnode to store file details */
181 vn.v_inode_nr = res.inode_nr;
182 vn.v_mode = res.fmode;
183 vn.v_index = res.inode_index;
184 vn.v_size = res.fsize;
185 vn.v_fs_e = res.fs_e;
186 vn.v_count = 1;
187 if ( (vmp = find_vmnt(vn.v_fs_e)) == NIL_VMNT)
188 printf("VFS: vmnt not found by exec()");
190 vn.v_dev = vmp->m_dev;
191 vn.v_vmnt = vmp;
193 v_ctime = res.ctime;
194 v_uid = res.uid;
195 v_gid = res.gid;
197 if (round == 0)
199 /* Deal with setuid/setgid executables */
200 if (vn.v_mode & I_SET_UID_BIT)
201 new_uid = v_uid;
202 if (vn.v_mode & I_SET_GID_BIT)
203 new_gid = v_gid;
206 /* Read the file header and extract the segment sizes. */
207 r = read_header(&vn, &sep_id, &text_bytes, &data_bytes, &bss_bytes,
208 &tot_bytes, &pc, &hdrlen);
209 if (r != ESCRIPT || round != 0)
210 break;
212 /* Get fresh copy of the file name. */
213 r= fetch_name(path, path_len, 0);
214 if (r != OK)
216 printf("pm_exec: 2nd fetch_name failed\n");
217 put_vnode(&vn);
218 return(r); /* strange */
220 r= patch_stack(&vn, mbuf, &frame_len);
221 put_vnode(&vn);
222 if (r != OK)
224 printf("pm_exec: patch stack\n");
225 return r;
229 if (r != OK)
231 printf("pm_exec: returning ENOEXEC, r = %d\n", r);
232 return ENOEXEC;
235 r= exec_newmem(proc_e, text_bytes, data_bytes, bss_bytes, tot_bytes,
236 frame_len, sep_id, vn.v_dev, vn.v_inode_nr, v_ctime,
237 progname, new_uid, new_gid, &stack_top, &load_text, &allow_setuid);
238 if (r != OK)
240 printf("pm_exec: exec_newmap failed: %d\n", r);
241 put_vnode(&vn);
242 return r;
245 /* Patch up stack and copy it from FS to new core image. */
246 vsp = stack_top;
247 vsp -= frame_len;
248 patch_ptr(mbuf, vsp);
249 r = sys_datacopy(SELF, (vir_bytes) mbuf,
250 proc_e, (vir_bytes) vsp, (phys_bytes)frame_len);
251 if (r != OK) panic(__FILE__,"pm_exec stack copy err on", proc_e);
253 off = hdrlen;
255 /* Read in text and data segments. */
256 if (load_text) {
257 r= read_seg(&vn, off, proc_e, T, text_bytes);
259 off += text_bytes;
260 if (r == OK)
261 r= read_seg(&vn, off, proc_e, D, data_bytes);
263 put_vnode(&vn);
265 if (r != OK) return r;
267 clo_exec(rfp);
269 if (allow_setuid)
271 rfp->fp_effuid= new_uid;
272 rfp->fp_effgid= new_gid;
275 /* This child has now exec()ced. */
276 rfp->fp_execced = 1;
278 /* Check if this is a driver that can now be useful. */
279 dmap_endpt_up(rfp->fp_endpoint);
281 /*printf("VFSpm_exec: %s OK\n", user_fullpath);*/
282 return OK;
285 /*===========================================================================*
286 * exec_newmem *
287 *===========================================================================*/
288 PRIVATE int exec_newmem(proc_e, text_bytes, data_bytes, bss_bytes, tot_bytes,
289 frame_len, sep_id, st_dev, st_ino, st_ctime, progname,
290 new_uid, new_gid, stack_topp, load_textp, allow_setuidp)
291 int proc_e;
292 vir_bytes text_bytes;
293 vir_bytes data_bytes;
294 vir_bytes bss_bytes;
295 vir_bytes tot_bytes;
296 vir_bytes frame_len;
297 int sep_id;
298 dev_t st_dev;
299 ino_t st_ino;
300 time_t st_ctime;
301 int new_uid;
302 int new_gid;
303 char *progname;
304 vir_bytes *stack_topp;
305 int *load_textp;
306 int *allow_setuidp;
308 int r;
309 struct exec_newmem e;
310 message m;
312 e.text_bytes= text_bytes;
313 e.data_bytes= data_bytes;
314 e.bss_bytes= bss_bytes;
315 e.tot_bytes= tot_bytes;
316 e.args_bytes= frame_len;
317 e.sep_id= sep_id;
318 e.st_dev= st_dev;
319 e.st_ino= st_ino;
320 e.st_ctime= st_ctime;
321 e.new_uid= new_uid;
322 e.new_gid= new_gid;
323 strncpy(e.progname, progname, sizeof(e.progname)-1);
324 e.progname[sizeof(e.progname)-1]= '\0';
326 m.m_type= EXEC_NEWMEM;
327 m.EXC_NM_PROC= proc_e;
328 m.EXC_NM_PTR= (char *)&e;
329 r= sendrec(PM_PROC_NR, &m);
330 if (r != OK)
331 return r;
332 #if 0
333 printf("exec_newmem: r = %d, m_type = %d\n", r, m.m_type);
334 #endif
335 *stack_topp= m.m1_i1;
336 *load_textp= !!(m.m1_i2 & EXC_NM_RF_LOAD_TEXT);
337 *allow_setuidp= !!(m.m1_i2 & EXC_NM_RF_ALLOW_SETUID);
338 #if 0
339 printf("exec_newmem: stack_top = 0x%x\n", *stack_topp);
340 printf("exec_newmem: load_text = %d\n", *load_textp);
341 #endif
342 return m.m_type;
346 /*===========================================================================*
347 * read_header *
348 *===========================================================================*/
349 PRIVATE int read_header(vp, sep_id, text_bytes, data_bytes, bss_bytes,
350 tot_bytes, pc, hdrlenp)
351 struct vnode *vp; /* inode for reading exec file */
352 int *sep_id; /* true iff sep I&D */
353 vir_bytes *text_bytes; /* place to return text size */
354 vir_bytes *data_bytes; /* place to return initialized data size */
355 vir_bytes *bss_bytes; /* place to return bss size */
356 phys_bytes *tot_bytes; /* place to return total size */
357 vir_bytes *pc; /* program entry point (initial PC) */
358 int *hdrlenp;
360 /* Read the header and extract the text, data, bss and total sizes from it. */
361 off_t pos;
362 struct exec hdr; /* a.out header is read in here */
364 /* Read the header and check the magic number. The standard MINIX header
365 * is defined in <a.out.h>. It consists of 8 chars followed by 6 longs.
366 * Then come 4 more longs that are not used here.
367 * Byte 0: magic number 0x01
368 * Byte 1: magic number 0x03
369 * Byte 2: normal = 0x10 (not checked, 0 is OK), separate I/D = 0x20
370 * Byte 3: CPU type, Intel 16 bit = 0x04, Intel 32 bit = 0x10,
371 * Motorola = 0x0B, Sun SPARC = 0x17
372 * Byte 4: Header length = 0x20
373 * Bytes 5-7 are not used.
375 * Now come the 6 longs
376 * Bytes 8-11: size of text segments in bytes
377 * Bytes 12-15: size of initialized data segment in bytes
378 * Bytes 16-19: size of bss in bytes
379 * Bytes 20-23: program entry point
380 * Bytes 24-27: total memory allocated to program (text, data + stack)
381 * Bytes 28-31: size of symbol table in bytes
382 * The longs are represented in a machine dependent order,
383 * little-endian on the 8088, big-endian on the 68000.
384 * The header is followed directly by the text and data segments, and the
385 * symbol table (if any). The sizes are given in the header. Only the
386 * text and data segments are copied into memory by exec. The header is
387 * used here only. The symbol table is for the benefit of a debugger and
388 * is ignored here.
391 struct readwrite_req req;
392 struct readwrite_res res;
393 int r;
395 pos= 0; /* Read from the start of the file */
397 /* Fill in request structure */
398 req.fs_e = vp->v_fs_e;
399 req.rw_flag = READING;
400 req.inode_nr = vp->v_inode_nr;
401 req.user_e = FS_PROC_NR;
402 req.seg = D;
403 req.pos = pos;
404 req.num_of_bytes = sizeof(hdr);
405 req.user_addr = (char*)&hdr;
406 req.inode_index = vp->v_index;
408 /* Issue request */
409 if ((r = req_readwrite(&req, &res)) != OK) return r;
411 /* Interpreted script? */
412 if (((char*)&hdr)[0] == '#' && ((char*)&hdr)[1] == '!' && vp->v_size >= 2)
413 return ESCRIPT;
415 if (vp->v_size < A_MINHDR) return(ENOEXEC);
417 /* Check magic number, cpu type, and flags. */
418 if (BADMAG(hdr)) return(ENOEXEC);
419 #if (CHIP == INTEL && _WORD_SIZE == 2)
420 if (hdr.a_cpu != A_I8086) return(ENOEXEC);
421 #endif
422 #if (CHIP == INTEL && _WORD_SIZE == 4)
423 if (hdr.a_cpu != A_I80386) return(ENOEXEC);
424 #endif
425 if ((hdr.a_flags & ~(A_NSYM | A_EXEC | A_SEP)) != 0) return(ENOEXEC);
427 *sep_id = !!(hdr.a_flags & A_SEP); /* separate I & D or not */
429 /* Get text and data sizes. */
430 *text_bytes = (vir_bytes) hdr.a_text; /* text size in bytes */
431 *data_bytes = (vir_bytes) hdr.a_data; /* data size in bytes */
432 *bss_bytes = (vir_bytes) hdr.a_bss; /* bss size in bytes */
433 *tot_bytes = hdr.a_total; /* total bytes to allocate for prog */
434 if (*tot_bytes == 0) return(ENOEXEC);
436 if (!*sep_id) {
437 /* If I & D space is not separated, it is all considered data. Text=0*/
438 *data_bytes += *text_bytes;
439 *text_bytes = 0;
441 *pc = hdr.a_entry; /* initial address to start execution */
442 *hdrlenp = hdr.a_hdrlen & BYTE; /* header length */
444 return(OK);
447 /*===========================================================================*
448 * patch_stack *
449 *===========================================================================*/
450 PRIVATE int patch_stack(vp, stack, stk_bytes)
451 struct vnode *vp; /* pointer for open script file */
452 char stack[ARG_MAX]; /* pointer to stack image within FS */
453 vir_bytes *stk_bytes; /* size of initial stack */
455 /* Patch the argument vector to include the path name of the script to be
456 * interpreted, and all strings on the #! line. Returns the path name of
457 * the interpreter.
459 enum { INSERT=FALSE, REPLACE=TRUE };
460 int n, r;
461 off_t pos;
462 char *sp, *interp = NULL;
463 char buf[_MAX_BLOCK_SIZE];
464 struct readwrite_req req;
465 struct readwrite_res res;
467 /* Make user_path the new argv[0]. */
468 if (!insert_arg(stack, stk_bytes, user_fullpath, REPLACE)) return(ENOMEM);
470 pos = 0; /* Read from the start of the file */
472 /* Fill in request structure */
473 req.fs_e = vp->v_fs_e;
474 req.rw_flag = READING;
475 req.inode_nr = vp->v_inode_nr;
476 req.user_e = FS_PROC_NR;
477 req.seg = D;
478 req.pos = pos;
479 req.num_of_bytes = _MAX_BLOCK_SIZE;
480 req.user_addr = buf;
481 req.inode_index = vp->v_index;
483 /* Issue request */
484 if ((r = req_readwrite(&req, &res)) != OK) return r;
486 n = vp->v_size;
487 if (n > vp->v_vmnt->m_block_size)
488 n = vp->v_vmnt->m_block_size;
489 if (n < 2) return ENOEXEC;
491 sp = &(buf[2]); /* just behind the #! */
492 n -= 2;
493 if (n > PATH_MAX) n = PATH_MAX;
495 /* Use the user_path variable for temporary storage */
496 memcpy(user_fullpath, sp, n);
498 if ((sp = memchr(user_fullpath, '\n', n)) == NULL) /* must be a proper line */
499 return(ENOEXEC);
501 /* Move sp backwards through script[], prepending each string to stack. */
502 for (;;) {
503 /* skip spaces behind argument. */
504 while (sp > user_fullpath && (*--sp == ' ' || *sp == '\t')) {}
505 if (sp == user_fullpath) break;
507 sp[1] = 0;
508 /* Move to the start of the argument. */
509 while (sp > user_fullpath && sp[-1] != ' ' && sp[-1] != '\t') --sp;
511 interp = sp;
512 if (!insert_arg(stack, stk_bytes, sp, INSERT)) return(ENOMEM);
515 /* Round *stk_bytes up to the size of a pointer for alignment contraints. */
516 *stk_bytes= ((*stk_bytes + PTRSIZE - 1) / PTRSIZE) * PTRSIZE;
518 if (interp != user_fullpath)
519 memmove(user_fullpath, interp, strlen(interp)+1);
520 return(OK);
523 /*===========================================================================*
524 * insert_arg *
525 *===========================================================================*/
526 PRIVATE int insert_arg(stack, stk_bytes, arg, replace)
527 char stack[ARG_MAX]; /* pointer to stack image within PM */
528 vir_bytes *stk_bytes; /* size of initial stack */
529 char *arg; /* argument to prepend/replace as new argv[0] */
530 int replace;
532 /* Patch the stack so that arg will become argv[0]. Be careful, the stack may
533 * be filled with garbage, although it normally looks like this:
534 * nargs argv[0] ... argv[nargs-1] NULL envp[0] ... NULL
535 * followed by the strings "pointed" to by the argv[i] and the envp[i]. The
536 * pointers are really offsets from the start of stack.
537 * Return true iff the operation succeeded.
539 int offset, a0, a1, old_bytes = *stk_bytes;
541 /* Prepending arg adds at least one string and a zero byte. */
542 offset = strlen(arg) + 1;
544 a0 = (int) ((char **) stack)[1]; /* argv[0] */
545 if (a0 < 4 * PTRSIZE || a0 >= old_bytes) return(FALSE);
547 a1 = a0; /* a1 will point to the strings to be moved */
548 if (replace) {
549 /* Move a1 to the end of argv[0][] (argv[1] if nargs > 1). */
550 do {
551 if (a1 == old_bytes) return(FALSE);
552 --offset;
553 } while (stack[a1++] != 0);
554 } else {
555 offset += PTRSIZE; /* new argv[0] needs new pointer in argv[] */
556 a0 += PTRSIZE; /* location of new argv[0][]. */
559 /* stack will grow by offset bytes (or shrink by -offset bytes) */
560 if ((*stk_bytes += offset) > ARG_MAX) return(FALSE);
562 /* Reposition the strings by offset bytes */
563 memmove(stack + a1 + offset, stack + a1, old_bytes - a1);
565 strcpy(stack + a0, arg); /* Put arg in the new space. */
567 if (!replace) {
568 /* Make space for a new argv[0]. */
569 memmove(stack + 2 * PTRSIZE, stack + 1 * PTRSIZE, a0 - 2 * PTRSIZE);
571 ((char **) stack)[0]++; /* nargs++; */
573 /* Now patch up argv[] and envp[] by offset. */
574 patch_ptr(stack, (vir_bytes) offset);
575 ((char **) stack)[1] = (char *) a0; /* set argv[0] correctly */
576 return(TRUE);
579 /*===========================================================================*
580 * patch_ptr *
581 *===========================================================================*/
582 PRIVATE void patch_ptr(stack, base)
583 char stack[ARG_MAX]; /* pointer to stack image within PM */
584 vir_bytes base; /* virtual address of stack base inside user */
586 /* When doing an exec(name, argv, envp) call, the user builds up a stack
587 * image with arg and env pointers relative to the start of the stack. Now
588 * these pointers must be relocated, since the stack is not positioned at
589 * address 0 in the user's address space.
592 char **ap, flag;
593 vir_bytes v;
595 flag = 0; /* counts number of 0-pointers seen */
596 ap = (char **) stack; /* points initially to 'nargs' */
597 ap++; /* now points to argv[0] */
598 while (flag < 2) {
599 if (ap >= (char **) &stack[ARG_MAX]) return; /* too bad */
600 if (*ap != NULL) {
601 v = (vir_bytes) *ap; /* v is relative pointer */
602 v += base; /* relocate it */
603 *ap = (char *) v; /* put it back */
604 } else {
605 flag++;
607 ap++;
611 /*===========================================================================*
612 * read_seg *
613 *===========================================================================*/
614 PRIVATE int read_seg(vp, off, proc_e, seg, seg_bytes)
615 struct vnode *vp; /* inode descriptor to read from */
616 off_t off; /* offset in file */
617 int proc_e; /* process number (endpoint) */
618 int seg; /* T, D, or S */
619 phys_bytes seg_bytes; /* how much is to be transferred? */
622 * The byte count on read is usually smaller than the segment count, because
623 * a segment is padded out to a click multiple, and the data segment is only
624 * partially initialized.
626 struct readwrite_req req;
627 struct readwrite_res res;
628 int r;
630 /* Make sure that the file is big enough */
631 if (vp->v_size < off+seg_bytes) return EIO;
633 /* Fill in request structure */
634 req.fs_e = vp->v_fs_e;
635 req.rw_flag = READING;
636 req.inode_nr = vp->v_inode_nr;
637 req.user_e = proc_e;
638 req.seg = seg;
639 req.pos = off;
640 req.num_of_bytes = seg_bytes;
641 req.user_addr = 0;
642 req.inode_index = vp->v_index;
644 /* Issue request */
645 if ((r = req_readwrite(&req, &res)) != OK) return r;
647 if (r == OK && res.cum_io != seg_bytes)
648 printf("VFSread_seg segment has not been read properly by exec() \n");
650 return r;
654 /*===========================================================================*
655 * clo_exec *
656 *===========================================================================*/
657 PRIVATE void clo_exec(rfp)
658 struct fproc *rfp;
660 /* Files can be marked with the FD_CLOEXEC bit (in fp->fp_cloexec).
662 int i;
664 /* Check the file desriptors one by one for presence of FD_CLOEXEC. */
665 for (i = 0; i < OPEN_MAX; i++)
666 if ( FD_ISSET(i, &rfp->fp_cloexec_set))
667 (void) close_fd(rfp, i);