home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / lan / soss.arj / SRC / NETD.C < prev    next >
C/C++ Source or Header  |  1991-04-11  |  3KB  |  140 lines

  1. /*
  2.  *  netd.c -- 
  3.  *      Net daemon for PC NFS file server.  It sets up and
  4.  *      arbitrates the port mapper daemon, mount daemon and
  5.  *      the NFS server.
  6.  *
  7.  *  Author:
  8.  *      See-Mong Tan, 6/11/88
  9.  *  Modified by:
  10.  *      Rich Braun, 3/29/91
  11.  *
  12.  *  Revision history:
  13.  *  
  14.  * $Log: netd.c_v $
  15.  * Revision 1.4  1991/04/11  20:39:04  richb
  16.  * Add -t option and use standard parser (getopt).
  17.  *
  18.  */
  19.  
  20. #ifdef RCSID
  21. static char _rcsid_ = "$Id: netd.c_v 1.4 1991/04/11 20:39:04 richb Exp $";
  22. #endif
  23.  
  24. #include "common.h"
  25.  
  26. bool_t NFS_VERBOSE = FALSE;    /* flag for nfs verbose mode */
  27. bool_t NFS_READONLYFS = FALSE;    /* true if started as a read only filesystem */
  28. bool_t NFS_TRUNCATENAMES = FALSE; /* true if long names should be truncated */
  29.  
  30. main(argc, argv)
  31.     int argc;
  32.     char *argv[];
  33. {
  34. time_t now;
  35.  
  36.     netd_init(argc, argv);        /* initialize netd */
  37.  
  38.     time (&now);
  39.     (void) printf("SOSS v%s %s (compiled %s)\n\nStarting net services at %s",
  40.               VERSION_NUM, VERSION_DATE, __DATE__, ctime (&now));
  41.  
  42.     Netinit(800);
  43.     in_init();
  44.     IcmpInit();
  45.     GgpInit();
  46.     UdpInit();
  47.  
  48.     /* initialize and register services */
  49.     if (! pmap_init())
  50.         netd_Punt("portmapper");
  51.     DBGPRT0 (nfsdebug, "netd: port mapper created");
  52.  
  53.     if (! mountd_init())
  54.         netd_Punt("mount daemon");
  55.     DBGPRT0 (nfsdebug, "netd: mount daemon created");
  56.  
  57.     if (! nfs_init())
  58.         netd_Punt("nfs server");
  59.     DBGPRT0 (nfsdebug, "netd: nfs server created");
  60.  
  61.     if (! inode_init())
  62.         netd_Punt("inode interface");
  63.  
  64.     if (! dtime_init())
  65.         netd_Punt("dos time interface");
  66.  
  67.     (void) printf("netd: port mapper, mountd and nfs server running\n\n");
  68.     DBGPRT1 (nfsdebug, "Memory available = %d\n", _memavl());
  69.     (void) svc_run();       /* wait for and service net requests */
  70.     netd_Punt("net daemon returned");
  71. }
  72.  
  73. /*
  74.  *  void netd_Punt(char *s) --
  75.  *      Prints net daemon error message and exits.
  76.  *      For irrecoverable errors.
  77.  */
  78. void netd_Punt(s)
  79.     char *s;
  80. {
  81.     int i;
  82.  
  83.     (void) fprintf(stderr, "net daemon error: %s\n", s);
  84.     for(i = 0; i < 3; i++)
  85.         sock_close(i);
  86.     exit(1);
  87. }
  88.  
  89.  
  90. /*
  91.  *  void netd_init(int argc, char **argv) --
  92.  *      Initializes the net daemon.  Should be called before any other
  93.  *      routine in the server.
  94.  */
  95. void netd_init(argc, argv)
  96.     int argc;
  97.     char *argv[];
  98. {
  99.         dbg_init ();
  100.     netd_parsecmdln(argc, argv);    /* parse command line */
  101.     signal(SIGINT, netd_break);    /* break handler */
  102. }
  103.  
  104. /*
  105.  *  void netd_break() --
  106.  *      Break handler.  Closes all sockets and exits.
  107.  */
  108. void netd_break()
  109. {
  110.     int i;
  111.  
  112.     (void) fprintf(stderr, "Netd:  break caught... exiting\n");
  113.     for(i = 0; i < 3; i++)
  114.         sock_close(i);
  115.  
  116.     exit(1);
  117. }
  118.  
  119. /*
  120.  *  void netd_parsecmdln(int argc, char **argv) --
  121.  *      Parse command line arguments.
  122.  */
  123. void netd_parsecmdln(argc, argv)
  124.     int argc;
  125.     char *argv[];
  126. {
  127.     int c;
  128.     extern int optind;
  129.  
  130.     while ((c = getopt (argc, argv, "rtv")) != -1)
  131.       switch (c) {
  132.     case 'r':    NFS_READONLYFS = TRUE;    break;
  133.     case 't':    NFS_TRUNCATENAMES = TRUE; break;
  134.     case 'v':    NFS_VERBOSE = TRUE;      break;
  135.     default:        netd_Punt("Usage: soss [ -rtv ]");
  136.       }
  137.       if (optind < argc)
  138.     netd_Punt("Usage: soss [ -rtv ]");
  139. }        
  140.