Print this page
195 Need replacement for nfs/lockd+klm
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Jeremy Jones <jeremy@delphix.com>
Reviewed by: Jeff Biseda <jbiseda@delphix.com>


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 
  25 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  26 /*        All Rights Reserved   */
  27 
  28 /*
  29  * University Copyright- Copyright (c) 1982, 1986, 1988
  30  * The Regents of the University of California
  31  * All Rights Reserved
  32  *
  33  * University Acknowledgment- Portions of this document are derived from
  34  * software developed by the University of California, Berkeley, and its
  35  * contributors.
  36  */
  37 




  38 #include <stdio.h>
  39 #include <stdio_ext.h>
  40 #include <stdlib.h>
  41 #include <ftw.h>
  42 #include <signal.h>
  43 #include <string.h>
  44 #include <syslog.h>
  45 #include <netconfig.h>
  46 #include <unistd.h>
  47 #include <netdb.h>
  48 #include <rpc/rpc.h>
  49 #include <netinet/in.h>
  50 #include <sys/param.h>
  51 #include <sys/resource.h>
  52 #include <sys/file.h>
  53 #include <sys/types.h>
  54 #include <sys/stat.h>
  55 #include <sys/sockio.h>
  56 #include <dirent.h>
  57 #include <errno.h>


 202         char *(*local)();
 203 
 204         /*
 205          * Dispatch according to which protocol is being used:
 206          *      NSM_ADDR_PROGRAM is the private lockd address
 207          *              registration protocol.
 208          *      SM_PROG is the normal statd (NSM) protocol.
 209          */
 210         if (rqstp->rq_prog == NSM_ADDR_PROGRAM) {
 211                 switch (rqstp->rq_proc) {
 212                 case NULLPROC:
 213                         svc_sendreply(transp, xdr_void, (caddr_t)NULL);
 214                         return;
 215 
 216                 case NSMADDRPROC1_REG:
 217                         xdr_argument = xdr_reg1args;
 218                         xdr_result = xdr_reg1res;
 219                         local = (char *(*)()) nsmaddrproc1_reg;
 220                         break;
 221 

 222                 default:
 223                         svcerr_noproc(transp);
 224                         return;
 225                 }
 226         } else {

 227                 switch (rqstp->rq_proc) {
 228                 case NULLPROC:
 229                         svc_sendreply(transp, xdr_void, (caddr_t)NULL);
 230                         return;
 231 
 232                 case SM_STAT:
 233                         xdr_argument = xdr_sm_name;
 234                         xdr_result = xdr_sm_stat_res;
 235                         local = (char *(*)()) sm_status;
 236                         break;
 237 
 238                 case SM_MON:
 239                         xdr_argument = xdr_mon;
 240                         xdr_result = xdr_sm_stat_res;
 241                         local = (char *(*)()) sm_mon;
 242                         break;
 243 
 244                 case SM_UNMON:
 245                         xdr_argument = xdr_mon_id;
 246                         xdr_result = xdr_sm_stat;
 247                         local = (char *(*)()) sm_unmon;
 248                         break;
 249 
 250                 case SM_UNMON_ALL:
 251                         xdr_argument = xdr_my_id;
 252                         xdr_result = xdr_sm_stat;
 253                         local = (char *(*)()) sm_unmon_all;
 254                         break;
 255 
 256                 case SM_SIMU_CRASH:
 257                         xdr_argument = xdr_void;
 258                         xdr_result = xdr_void;
 259                         local = (char *(*)()) sm_simu_crash;
 260                         break;
 261 
 262                 case SM_NOTIFY:
 263                         xdr_argument = xdr_stat_chge;
 264                         xdr_result = xdr_void;
 265                         local = (char *(*)()) sm_notify;
 266                         break;
 267 
 268                 default:
 269                         svcerr_noproc(transp);
 270                         return;
 271                 }
 272         }
 273 
 274         (void) memset(&argument, 0, sizeof (argument));
 275         if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
 276                 svcerr_decode(transp);
 277                 return;
 278         }
 279 
 280         (void) memset(&result, 0, sizeof (result));
 281         (*local)(&argument, &result);
 282         if (!svc_sendreply(transp, xdr_result, (caddr_t)&result)) {
 283                 svcerr_systemerr(transp);
 284         }
 285 


 567          * establish our lock on the lock file and write our pid to it.
 568          * exit if some other process holds the lock, or if there's any
 569          * error in writing/locking the file.
 570          */
 571         ppid = _enter_daemon_lock(STATD);
 572         switch (ppid) {
 573         case 0:
 574                 break;
 575         case -1:
 576                 syslog(LOG_ERR, "error locking for %s: %s", STATD,
 577                     strerror(errno));
 578                 exit(2);
 579         default:
 580                 /* daemon was already running */
 581                 exit(0);
 582         }
 583 
 584         /* Get other aliases from each interface. */
 585         merge_hosts();
 586 



 587         /*
 588          * Set to automatic mode such that threads are automatically
 589          * created
 590          */
 591         mode = RPC_SVC_MT_AUTO;
 592         if (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) {
 593                 syslog(LOG_ERR,
 594                     "statd:unable to set automatic MT mode.");
 595                 exit(1);
 596         }
 597 
 598         /*
 599          * Set non-blocking mode and maximum record size for
 600          * connection oriented RPC transports.
 601          */
 602         if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) {
 603                 syslog(LOG_INFO, "unable to set maximum RPC record size");
 604         }
 605 
 606         if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "netpath")) {




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */
  28 
  29 /*
  30  * University Copyright- Copyright (c) 1982, 1986, 1988
  31  * The Regents of the University of California
  32  * All Rights Reserved
  33  *
  34  * University Acknowledgment- Portions of this document are derived from
  35  * software developed by the University of California, Berkeley, and its
  36  * contributors.
  37  */
  38 
  39 /*
  40  * Copyright (c) 2012 by Delphix. All rights reserved.
  41  */
  42 
  43 #include <stdio.h>
  44 #include <stdio_ext.h>
  45 #include <stdlib.h>
  46 #include <ftw.h>
  47 #include <signal.h>
  48 #include <string.h>
  49 #include <syslog.h>
  50 #include <netconfig.h>
  51 #include <unistd.h>
  52 #include <netdb.h>
  53 #include <rpc/rpc.h>
  54 #include <netinet/in.h>
  55 #include <sys/param.h>
  56 #include <sys/resource.h>
  57 #include <sys/file.h>
  58 #include <sys/types.h>
  59 #include <sys/stat.h>
  60 #include <sys/sockio.h>
  61 #include <dirent.h>
  62 #include <errno.h>


 207         char *(*local)();
 208 
 209         /*
 210          * Dispatch according to which protocol is being used:
 211          *      NSM_ADDR_PROGRAM is the private lockd address
 212          *              registration protocol.
 213          *      SM_PROG is the normal statd (NSM) protocol.
 214          */
 215         if (rqstp->rq_prog == NSM_ADDR_PROGRAM) {
 216                 switch (rqstp->rq_proc) {
 217                 case NULLPROC:
 218                         svc_sendreply(transp, xdr_void, (caddr_t)NULL);
 219                         return;
 220 
 221                 case NSMADDRPROC1_REG:
 222                         xdr_argument = xdr_reg1args;
 223                         xdr_result = xdr_reg1res;
 224                         local = (char *(*)()) nsmaddrproc1_reg;
 225                         break;
 226 
 227                 case NSMADDRPROC1_UNREG: /* Not impl. */
 228                 default:
 229                         svcerr_noproc(transp);
 230                         return;
 231                 }
 232         } else {
 233                 /* Must be SM_PROG */
 234                 switch (rqstp->rq_proc) {
 235                 case NULLPROC:
 236                         svc_sendreply(transp, xdr_void, (caddr_t)NULL);
 237                         return;
 238 
 239                 case SM_STAT:
 240                         xdr_argument = xdr_sm_name;
 241                         xdr_result = xdr_sm_stat_res;
 242                         local = (char *(*)()) sm_stat_svc;
 243                         break;
 244 
 245                 case SM_MON:
 246                         xdr_argument = xdr_mon;
 247                         xdr_result = xdr_sm_stat_res;
 248                         local = (char *(*)()) sm_mon_svc;
 249                         break;
 250 
 251                 case SM_UNMON:
 252                         xdr_argument = xdr_mon_id;
 253                         xdr_result = xdr_sm_stat;
 254                         local = (char *(*)()) sm_unmon_svc;
 255                         break;
 256 
 257                 case SM_UNMON_ALL:
 258                         xdr_argument = xdr_my_id;
 259                         xdr_result = xdr_sm_stat;
 260                         local = (char *(*)()) sm_unmon_all_svc;
 261                         break;
 262 
 263                 case SM_SIMU_CRASH:
 264                         xdr_argument = xdr_void;
 265                         xdr_result = xdr_void;
 266                         local = (char *(*)()) sm_simu_crash_svc;
 267                         break;
 268 
 269                 case SM_NOTIFY:
 270                         xdr_argument = xdr_stat_chge;
 271                         xdr_result = xdr_void;
 272                         local = (char *(*)()) sm_notify_svc;
 273                         break;
 274 
 275                 default:
 276                         svcerr_noproc(transp);
 277                         return;
 278                 }
 279         }
 280 
 281         (void) memset(&argument, 0, sizeof (argument));
 282         if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
 283                 svcerr_decode(transp);
 284                 return;
 285         }
 286 
 287         (void) memset(&result, 0, sizeof (result));
 288         (*local)(&argument, &result);
 289         if (!svc_sendreply(transp, xdr_result, (caddr_t)&result)) {
 290                 svcerr_systemerr(transp);
 291         }
 292 


 574          * establish our lock on the lock file and write our pid to it.
 575          * exit if some other process holds the lock, or if there's any
 576          * error in writing/locking the file.
 577          */
 578         ppid = _enter_daemon_lock(STATD);
 579         switch (ppid) {
 580         case 0:
 581                 break;
 582         case -1:
 583                 syslog(LOG_ERR, "error locking for %s: %s", STATD,
 584                     strerror(errno));
 585                 exit(2);
 586         default:
 587                 /* daemon was already running */
 588                 exit(0);
 589         }
 590 
 591         /* Get other aliases from each interface. */
 592         merge_hosts();
 593 
 594         /* Get all of the configured IP addresses. */
 595         merge_ips();
 596 
 597         /*
 598          * Set to automatic mode such that threads are automatically
 599          * created
 600          */
 601         mode = RPC_SVC_MT_AUTO;
 602         if (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) {
 603                 syslog(LOG_ERR,
 604                     "statd:unable to set automatic MT mode.");
 605                 exit(1);
 606         }
 607 
 608         /*
 609          * Set non-blocking mode and maximum record size for
 610          * connection oriented RPC transports.
 611          */
 612         if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) {
 613                 syslog(LOG_INFO, "unable to set maximum RPC record size");
 614         }
 615 
 616         if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "netpath")) {