home *** CD-ROM | disk | FTP | other *** search
/ ftp.mayn.de / ftp.mayn.de-pub.zip / ftp.mayn.de-pub / apple / apple_unix_2 / uwrap.c < prev    next >
C/C++ Source or Header  |  2017-03-06  |  4KB  |  129 lines

  1. /*
  2.  * I've implemented a SIGURG wrapper program which ignores SIGURG and
  3.  * then execs any arbitrary program (with its arguments) which is passed
  4.  * in as arguments to the wrapper program. As a special case, if no
  5.  * arguments are provided, the wrapper execs /etc/init. This avoids
  6.  * having to modify the kernel to start a different program as the
  7.  * precursor process; it does require additional configuration, however
  8.  * -- see below.
  9.  * 
  10.  * I've provided the source code to this simple program below so you may
  11.  * modify it to meet any local configuration requirements.
  12.  * 
  13.  * After compiling the program, which I am calling "uwrap", I
  14.  * suggest the following configuration steps, which I tested on an A/UX
  15.  * 3.1.1 system. You must perform these tasks as the super-user, root.
  16.  * 
  17.  * 1) Rename the original /etc/init; be sure to maintain the hard link
  18.  *    to telinit. Make sure that the new name is the same as used by
  19.  *    the 'uwrap' program.
  20.  *     # mv /etc/init /etc/init.orig
  21.  * 
  22.  * 2) Install uwrap in /etc and make it the new /etc/init.
  23.  *     # cc -O uwrap.c -o uwrap
  24.  *     # cp ~/uwrap /etc/uwrap
  25.  *     # chmod 500 /etc/uwrap
  26.  *     # ln /etc/uwrap /etc/init
  27.  * 
  28.  * 3) Edit /etc/inittab to call uwrap to invoke cron, nfsd and bind
  29.  *    as necessary for your site if desired. Since 'init' itself is
  30.  *    ignoring SIGURG, all processes, unless they specifically call
  31.  *    signal(SIGURG, SIG_DFL) _and_ are using SysV signals (ie: not
  32.  *    linked with -lbsd or not linked with -lposix or not calling
  33.  *    set42sig()), will be SIGURG protected; thus no additional
  34.  *    wrapping is really needed. If you do desire to wrap them
  35.  *    anyway, they should look like:
  36.  * 
  37.  *     cr:2:wait: /etc/uwrap /etc/cron </dev/syscon >/dev/syscon 2>&1
  38.  *     nfs4:2:wait: /etc/uwrap /etc/biod 4
  39.  * 
  40.  * 4) Restart the reconfigured system.
  41.  * 
  42.  * The target programs should now be ignoring SIGURG.
  43.  * 
  44.  * Let me know if you have any questions or feedback.
  45.  * 
  46.  * Regards,
  47.  * John Sovereign
  48.  * Server OS Platforms
  49.  * jms@apple.com
  50.  * 
  51.  * Version History:
  52.  * 1.0: Original by John
  53.  *
  54.  * 1.1: Modifications by Jim Jagielski <jim@jaguNET.com>
  55.  *       o if called as 'init', behave as 'init'. ie:
  56.  *         'init s' will behave correctly and not try to
  57.  *         wrap "s", which may not exist
  58.  *       o Description "improved"
  59.  *
  60.  */
  61.  
  62. #define ORIGINIT        "/etc/init.orig"
  63.  
  64. #include <signal.h>
  65.  
  66. extern char **environ;
  67.  
  68. main(argc, argv)
  69. char **argv;
  70. {
  71.     char *file;
  72.     char *iam;
  73.  
  74.     (void) signal(SIGURG, SIG_IGN);
  75.  
  76.     /*
  77.      * As a special case, if no arguments are passed, start init.
  78.      * Init will only cooperate if the pid == 1.
  79.      */
  80.     if (argc == 1)
  81.     {
  82.     argv++;            /* skip over our name */
  83.     argv[0] = "/etc/init";
  84.     argv[1] = 0;
  85.     file = ORIGINIT;
  86.     }
  87.     else
  88.     {
  89.     /*
  90.      * Hmmm we have arguments. Were we called as 'init' or
  91.      * as the wrapper? Emulate string functions here to
  92.      * reduce our size.
  93.      */
  94.     iam = file = *argv;
  95.     do
  96.     {        /* emulate rindex()... Look for last '/' */
  97.         if (*file++ == '/')
  98.         iam = file;
  99.     }
  100.     while (*file);
  101.     if (iam[0] == 'i' &&
  102.         iam[1] == 'n' &&
  103.         iam[2] == 'i' &&
  104.         iam[3] == 't' &&
  105.         iam[4] == '\0')
  106.     {        /* emulate strcmp(iam, "init") */
  107.         argv[0] = "/etc/init";
  108.         file = ORIGINIT;
  109.     }
  110.     else
  111.     {
  112.         argv++;        /* skip over our name */
  113.         file = argv[0];
  114.     }
  115.     }
  116. #ifdef JUST_TEST_IT
  117.     printf("%s", file);
  118.     do
  119.     {
  120.     printf(" %s", *argv);
  121.     }
  122.     while (*++argv);
  123.     printf("\n");
  124. #else
  125.     (void) execve(file, argv, environ);
  126. #endif
  127.     perror(file);
  128. }
  129.