home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / NETWORK / SOSS31.ZIP / SRC / NETD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-13  |  3.6 KB  |  152 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.5  1991/05/13  17:44:55  richb
  16.  * Add the -b command line option to specify read/write request size.
  17.  *
  18.  * Revision 1.4  1991/04/11  20:39:04  richb
  19.  * Add -t option and use standard parser (getopt).
  20.  *
  21.  */
  22.  
  23. #ifdef RCSID
  24. static char _rcsid_ = "$Id: netd.c_v 1.5 1991/05/13 17:44:55 richb Exp $";
  25. #endif
  26.  
  27. #include "common.h"
  28.  
  29. bool_t NFS_VERBOSE = FALSE;    /* flag for nfs verbose mode */
  30. bool_t NFS_READONLYFS = FALSE;    /* true if started as a read only filesystem */
  31. bool_t NFS_TRUNCATENAMES = FALSE; /* true if long names should be truncated */
  32. int    nfsrd_size = RD_SIZ;    /* I/O read default size */
  33. int    nfswr_size = WR_SIZ;    /* I/O write default size */
  34.  
  35. main(argc, argv)
  36.     int argc;
  37.     char *argv[];
  38. {
  39. time_t now;
  40.  
  41.     netd_init(argc, argv);        /* initialize netd */
  42.  
  43.     time (&now);
  44.     (void) printf("SOSS v%s %s (compiled %s)\n\nStarting net services at %s",
  45.               VERSION_NUM, VERSION_DATE, __DATE__, ctime (&now));
  46.  
  47.     Netinit(800);
  48.     in_init();
  49.     IcmpInit();
  50.     GgpInit();
  51.     UdpInit();
  52.  
  53.     /* initialize and register services */
  54.     if (! pmap_init())
  55.         netd_Punt("portmapper");
  56.     DBGPRT0 (nfsdebug, "netd: port mapper created");
  57.  
  58.     if (! mountd_init())
  59.         netd_Punt("mount daemon");
  60.     DBGPRT0 (nfsdebug, "netd: mount daemon created");
  61.  
  62.     if (! nfs_init())
  63.         netd_Punt("nfs server");
  64.     DBGPRT0 (nfsdebug, "netd: nfs server created");
  65.  
  66.     if (! inode_init())
  67.         netd_Punt("inode interface");
  68.  
  69.     if (! dtime_init())
  70.         netd_Punt("dos time interface");
  71.  
  72.     (void) printf("netd: port mapper, mountd and nfs server running\n\n");
  73.     DBGPRT1 (nfsdebug, "Memory available = %d\n", _memavl());
  74.     (void) svc_run();       /* wait for and service net requests */
  75.     netd_Punt("net daemon returned");
  76. }
  77.  
  78. /*
  79.  *  void netd_Punt(char *s) --
  80.  *      Prints net daemon error message and exits.
  81.  *      For irrecoverable errors.
  82.  */
  83. void netd_Punt(s)
  84.     char *s;
  85. {
  86.     int i;
  87.  
  88.     (void) fprintf(stderr, "net daemon error: %s\n", s);
  89.     for(i = 0; i < 3; i++)
  90.         sock_close(i);
  91.     exit(1);
  92. }
  93.  
  94.  
  95. /*
  96.  *  void netd_init(int argc, char **argv) --
  97.  *      Initializes the net daemon.  Should be called before any other
  98.  *      routine in the server.
  99.  */
  100. void netd_init(argc, argv)
  101.     int argc;
  102.     char *argv[];
  103. {
  104.         dbg_init ();
  105.     netd_parsecmdln(argc, argv);    /* parse command line */
  106.     signal(SIGINT, netd_break);    /* break handler */
  107. }
  108.  
  109. /*
  110.  *  void netd_break() --
  111.  *      Break handler.  Closes all sockets and exits.
  112.  */
  113. void netd_break()
  114. {
  115.     int i;
  116.  
  117.     (void) fprintf(stderr, "Netd:  break caught... exiting\n");
  118.     for(i = 0; i < 3; i++)
  119.         sock_close(i);
  120.  
  121.     exit(1);
  122. }
  123.  
  124. /*
  125.  *  void netd_parsecmdln(int argc, char **argv) --
  126.  *      Parse command line arguments.
  127.  */
  128. void netd_parsecmdln(argc, argv)
  129.     int argc;
  130.     char *argv[];
  131. {
  132.     int c;
  133.     extern int optind;
  134.     extern char *optarg;
  135.     int err = FALSE;
  136.  
  137.     while ((c = getopt (argc, argv, "b:rtv")) != -1)
  138.       switch (c) {
  139.     case 'b':       if (sscanf (optarg, "%d", &nfsrd_size) == 1)
  140.                  nfswr_size = nfsrd_size;
  141.               else
  142.                err = TRUE;
  143.               break;
  144.     case 'r':    NFS_READONLYFS = TRUE;    break;
  145.     case 't':    NFS_TRUNCATENAMES = TRUE; break;
  146.     case 'v':    NFS_VERBOSE = TRUE;      break;
  147.     default:        err = TRUE;
  148.       }
  149.       if (err || optind < argc)
  150.     netd_Punt("Usage: soss [ -b blocksize -rtv ]");
  151. }        
  152.