nfs-ganesha 1.4

svcgssd_main_loop.c

Go to the documentation of this file.
00001 /*
00002   Copyright (c) 2004 The Regents of the University of Michigan.
00003   All rights reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions
00007   are met:
00008 
00009   1. Redistributions of source code must retain the above copyright
00010      notice, this list of conditions and the following disclaimer.
00011   2. Redistributions in binary form must reproduce the above copyright
00012      notice, this list of conditions and the following disclaimer in the
00013      documentation and/or other materials provided with the distribution.
00014   3. Neither the name of the University nor the names of its
00015      contributors may be used to endorse or promote products derived
00016      from this software without specific prior written permission.
00017 
00018   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00019   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00020   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021   DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00022   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00025   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00026   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif  /* HAVE_CONFIG_H */
00034 
00035 #include <sys/param.h>
00036 #include <sys/socket.h>
00037 #include <sys/poll.h>
00038 #include <sys/types.h>
00039 #include <sys/stat.h>
00040 #include <netinet/in.h>
00041 
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include <memory.h>
00046 #include <fcntl.h>
00047 #include <errno.h>
00048 #include <unistd.h>
00049 
00050 #include "svcgssd.h"
00051 #include "err_util.h"
00052 
00053 void
00054 gssd_run()
00055 {
00056         int                     ret;
00057         FILE                    *f;
00058         struct pollfd           pollfd;
00059 
00060 #define NULLRPC_FILE "/proc/net/rpc/auth.rpcsec.init/channel"
00061 
00062         f = fopen(NULLRPC_FILE, "rw");
00063 
00064         if (!f) {
00065                 printerr(0, "failed to open %s: %s\n",
00066                          NULLRPC_FILE, strerror(errno));
00067                 exit(1);
00068         }
00069         pollfd.fd = fileno(f);
00070         pollfd.events = POLLIN;
00071         while (1) {
00072                 int save_err;
00073 
00074                 pollfd.revents = 0;
00075                 printerr(1, "entering poll\n");
00076                 ret = poll(&pollfd, 1, -1);
00077                 save_err = errno;
00078                 printerr(1, "leaving poll\n");
00079                 if (ret < 0) {
00080                         if (save_err != EINTR)
00081                                 printerr(0, "error return from poll: %s\n",
00082                                          strerror(save_err));
00083                 } else if (ret == 0) {
00084                         /* timeout; shouldn't happen. */
00085                 } else {
00086                         if (ret != 1) {
00087                                 printerr(0, "bug: unexpected poll return %d\n",
00088                                                 ret);
00089                                 exit(1);
00090                         }
00091                         if (pollfd.revents & POLLIN)
00092                                 handle_nullreq(f);
00093                 }
00094         }
00095 }