home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / LIB / unix.zoo / execl.c < prev    next >
Text File  |  2009-11-06  |  9KB  |  204 lines

  1.  
  2. /***************************************************************************/
  3. /*                                                                         */
  4. /* execl() : Unix library (OS9/68000)                                      */
  5. /* =======                                                                 */
  6. /*                                                                         */
  7. /* Author:     K. Schmitt                                                  */
  8. /* Compiler:   Microware C Vers. 3.0                                       */
  9. /* OS:         OS9/68000 Vers. 2.2                                         */
  10. /*                                                                         */
  11. /* Edition History                                                         */
  12. /* ===============                                                         */
  13. /*                                                                         */
  14. /* Ed. 0.00  Date 11/16/88                                                 */
  15. /*           First version                                                 */
  16. /*                                                                         */
  17. /***************************************************************************/
  18. /*                                                                         */
  19. /* Description                                                             */
  20. /*
  21.  
  22.      SYNOPSIS
  23.           int execl (path, arg0, arg1, ..., argn, (char *)0)
  24.           char *path, *arg0, *arg1, ..., *argn;
  25.  
  26.      DESCRIPTION
  27.           Exec in all its forms transforms the calling process into a
  28.           new process.  The new process is constructed from an
  29.           ordinary, executable file called the new process file.  This
  30.           file consists of a header, a text segment,
  31.           and a data segment.  The data segment contains an
  32.           initialized portion and an uninitialized portion (bss).
  33.           There can be no return from a successful exec because the
  34.           calling process is overlaid by the new process.
  35.  
  36.           When a C program is executed, it is called as follows:
  37.  
  38.                main (argc, argv, envp)
  39.                int argc;
  40.                char **argv, **envp;
  41.  
  42.           where argc is the argument count and argv is an array of
  43.           character pointers to the arguments themselves.  As
  44.           indicated, argc is conventionally at least one and the first
  45.           member of the array points to a string containing the name
  46.           of the file.
  47.  
  48.           Path points to a path name that identifies the new process
  49.           file.
  50.  
  51.           File points to the new process file.  The path prefix for
  52.           this file is obtained by a search of the directories passed
  53.           as the environment line "PATH =".  The
  54.           environment is supplied by the shell.
  55.  
  56.           Arg0, arg1, ..., argn are pointers to null-terminated
  57.           character strings.  These strings constitute the argument
  58.           list available to the new process.  By convention, at least
  59.           arg0 must be present and point to a string that is the same 
  60.           as path (or its last component).
  61.  
  62.           Argv is an array of character pointers to null-terminated
  63.           strings.  These strings constitute the argument list
  64.           available to the new process.  By convention, argv must have
  65.           at least one member, and it must point to a string that is
  66.           the same as path (or its last component).  Argv is
  67.           terminated by a null pointer.
  68.  
  69.           Envp is an array of character pointers to null-terminated
  70.           strings.  These strings constitute the environment for the
  71.           new process.  Envp is terminated by a null pointer.  For
  72.           execl and execv, the C run-time start-off routine places a
  73.           pointer to the environment of the calling process in the
  74.           global cell:
  75.                extern char **environ;
  76.           and it is used to pass the environment of the calling
  77.           process to the new process.
  78.  
  79.           File descriptors open in the calling process remain open in
  80.           the new process, except for those whose close-on-exec flag
  81.           is set; see fcntl(2).  For those file descriptors that
  82.           remain open, the file pointer is unchanged.
  83.  
  84.           Signals set to terminate the calling process will be set to
  85.           terminate the new process.  Signals set to be ignored by the
  86.           calling process will be set to be ignored by the new
  87.           process.  Signals set to be caught by the calling process
  88.           will be set to terminate new process.
  89.  
  90.           If the set-user-ID mode bit of the new process file is set,
  91.           exec sets the effective user ID of the new
  92.           process to the owner ID of the new process file.  Similarly,
  93.           if the set-group-ID mode bit of the new process file is set,
  94.           the effective group ID of the new process is set to the
  95.           group ID of the new process file.  The real user ID and real
  96.           group ID of the new process remain the same as those of the
  97.           calling process.
  98.  
  99.           The shared memory segments attached to the calling process
  100.           will not be attached to the new process.
  101.  
  102.           The new process also inherits the following attributes from
  103.           the calling process:
  104.  
  105.                process ID
  106.                parent process ID
  107.                process group ID
  108.                tty group ID
  109.                trace flag
  110.                time left until an alarm clock signal
  111.                current working directory
  112.                root directory
  113.                file mode creation mask
  114.                file size limit
  115.                utime, stime, cutime and cstime
  116.  
  117.           Exec will fail and return to the calling process if one or
  118.           more of the following are true:
  119.  
  120.           [ENOENT]       One or more components of the new process
  121.                          path name of the file do not exist.
  122.  
  123.           [ENOTDIR]      A component of the new process path of the
  124.                          file prefix is not a directory.
  125.  
  126.           [EACCES]       Search permission is denied for a directory
  127.                          listed in the new process file's path prefix.
  128.  
  129.           [EACCES]       The new process file is not an ordinary file.
  130.  
  131.           [EACCES]       The new process file mode denies execution
  132.                          permission.
  133.  
  134.           [ENOEXEC]      The exec is not an execlp or execvp, and the
  135.                          new process file has the appropriate access
  136.                          permission but an invalid magic number in its 
  137.                          header.
  138.  
  139.           [ETXTBSY]      The new process file is a pure procedure
  140.                          (shared text) file that is currently open for
  141.                          writing by some process.
  142.  
  143.        
  144.           [ENOMEM]       The new process requires more memory than is
  145.                          allowed by the system-imposed maximum MAXMEM.
  146.  
  147.           [E2BIG]        The number of bytes in the new process's
  148.                          argument list is greater than the system-
  149.                          imposed limit of 5120 bytes.
  150.  
  151.           [EFAULT]       The new process file is not as long as
  152.                          indicated by the size values in its header.
  153.  
  154.           [EFAULT]       Path, argv, or envp point to an illegal
  155.                          address.
  156.  
  157.      RETURN VALUE  
  158.           If exec returns to the calling process an error has
  159.           occurred; the return value will be -1 and errno will be set
  160.           to indicate the error.
  161.  
  162. */
  163.  
  164. /* VARARGS */
  165. int execl (path, arg0, argn)
  166.           char *path, *arg0, *argn;
  167.           {
  168.           register long *argp;
  169.           register char **argv;
  170.           register int nargs;
  171.           extern char **malloc();
  172.           extern int errno, chainc(), os9exec(), modload();
  173.           extern char **environ;
  174.  
  175.           argp = (long *) &argn;
  176.           nargs = 1;
  177.           while (*argp)
  178.                {
  179.                nargs++;
  180.                argp++;
  181.                }
  182.  
  183.           modload(path,0); /* load module (use 'path') */
  184.  
  185.           if ((argv=malloc(sizeof(char *) * (nargs+1))) == (char **) 0)
  186.                {
  187.                exit(errno);
  188.                }
  189.  
  190.           argv[0] = arg0;
  191.           argp = (long *) &argn;
  192.           nargs = 1;
  193.           while (*argp)
  194.                {
  195.                argv[nargs++] = (char *) *argp++;
  196.                }
  197.  
  198.           argv[nargs] = (char *) 0;
  199.  
  200.           exit(os9exec(chainc,arg0,argv,environ,0,0,32));
  201.  
  202.           } /* end of execl */
  203.  
  204.