1 /*
   2  * CDDL HEADER START
   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 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /* endless_exe.c part of delegation C testcases */
  28 
  29 #include <unistd.h>
  30 #include <stdlib.h>
  31 #include <fcntl.h>
  32 #include <nfs/nfs.h>
  33 #include <nfs/export.h>
  34 #include <nfs/nfssys.h>
  35 
  36 extern int      _nfssys(int, void *);
  37 
  38 #define OK      0
  39 
  40 /*
  41  * Main test loop.
  42  */
  43 
  44 int
  45 main(int argc, char **argv)
  46 {
  47         int i = 0;
  48         int j = 0;
  49         int delay = 1;
  50         int fd;
  51         struct nfs4_svc_args nsa;
  52 
  53         if (argc > 1)
  54                 delay = atoi(argv[1]);
  55 
  56         if ((fd = open(argv[0], O_RDONLY)) < 0) {
  57                 perror("open() failed");
  58                 i = -1;
  59         } else {
  60                 nsa.fd = fd;
  61                 nsa.cmd = NFS4_DQUERY;
  62                 nsa.netid = (char *)&i;
  63 
  64                 if (_nfssys(NFS4_SVC, &nsa)) {
  65                         perror("ERROR: nfssys NFS4_SVC");
  66                         i = -1;
  67                 } else {
  68                         printf("delegation type granted: <%d>\n", i);
  69                         fflush(stdout);
  70                         close(1);
  71                 }
  72         }
  73 
  74         if (i > 0)
  75                 while (j++ < delay)
  76                         sleep(1);
  77 
  78         return (i);
  79 }