]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* |
a7ab6ec8 UD |
2 | * Copyright (c) 2010, Oracle America, Inc. |
3 | * Redistribution and use in source and binary forms, with or without | |
4 | * modification, are permitted provided that the following conditions are | |
5 | * met: | |
c4029823 | 6 | * |
a7ab6ec8 UD |
7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * * Redistributions in binary form must reproduce the above | |
10 | * copyright notice, this list of conditions and the following | |
11 | * disclaimer in the documentation and/or other materials | |
12 | * provided with the distribution. | |
13 | * * Neither the name of the "Oracle America, Inc." nor the names of its | |
14 | * contributors may be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
c4029823 | 16 | * |
a7ab6ec8 UD |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
21 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | |
24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
c4029823 | 29 | * |
28f540f4 RM |
30 | * This is the rpc server side idle loop |
31 | * Wait for input, call server program. | |
32 | */ | |
bdb04ee8 | 33 | |
e7fd8a39 | 34 | #include <errno.h> |
bdb04ee8 | 35 | #include <unistd.h> |
4360eafd | 36 | #include <libintl.h> |
bdb04ee8 | 37 | #include <sys/poll.h> |
28f540f4 | 38 | #include <rpc/rpc.h> |
28f540f4 | 39 | |
1f07e617 UD |
40 | /* This function can be used as a signal handler to terminate the |
41 | server loop. */ | |
42 | void | |
43 | svc_exit (void) | |
44 | { | |
bdb04ee8 UD |
45 | free (svc_pollfd); |
46 | svc_pollfd = NULL; | |
47 | svc_max_pollfd = 0; | |
1f07e617 | 48 | } |
021db4be | 49 | libc_hidden_nolink_sunrpc (svc_exit, GLIBC_2_0) |
1f07e617 | 50 | |
28f540f4 | 51 | void |
e7fd8a39 | 52 | svc_run (void) |
28f540f4 | 53 | { |
bdb04ee8 | 54 | int i; |
11bf311e UD |
55 | struct pollfd *my_pollfd = NULL; |
56 | int last_max_pollfd = 0; | |
1f07e617 | 57 | |
e7fd8a39 UD |
58 | for (;;) |
59 | { | |
11bf311e UD |
60 | int max_pollfd = svc_max_pollfd; |
61 | if (max_pollfd == 0 && svc_pollfd == NULL) | |
62 | break; | |
bdb04ee8 | 63 | |
11bf311e | 64 | if (last_max_pollfd != max_pollfd) |
32c075e1 | 65 | { |
11bf311e UD |
66 | struct pollfd *new_pollfd |
67 | = realloc (my_pollfd, sizeof (struct pollfd) * max_pollfd); | |
68 | ||
69 | if (new_pollfd == NULL) | |
70 | { | |
71 | perror (_("svc_run: - out of memory")); | |
72 | break; | |
73 | } | |
74 | ||
75 | my_pollfd = new_pollfd; | |
76 | last_max_pollfd = max_pollfd; | |
b1a758f3 | 77 | } |
1f07e617 | 78 | |
11bf311e | 79 | for (i = 0; i < max_pollfd; ++i) |
bdb04ee8 UD |
80 | { |
81 | my_pollfd[i].fd = svc_pollfd[i].fd; | |
82 | my_pollfd[i].events = svc_pollfd[i].events; | |
83 | my_pollfd[i].revents = 0; | |
84 | } | |
85 | ||
11bf311e | 86 | switch (i = __poll (my_pollfd, max_pollfd, -1)) |
e7fd8a39 UD |
87 | { |
88 | case -1: | |
89 | if (errno == EINTR) | |
bdb04ee8 UD |
90 | continue; |
91 | perror (_("svc_run: - poll failed")); | |
11bf311e | 92 | break; |
e7fd8a39 UD |
93 | case 0: |
94 | continue; | |
95 | default: | |
7b57bfe5 | 96 | svc_getreq_poll (my_pollfd, i); |
11bf311e | 97 | continue; |
28f540f4 | 98 | } |
11bf311e | 99 | break; |
e7fd8a39 | 100 | } |
11bf311e UD |
101 | |
102 | free (my_pollfd); | |
28f540f4 | 103 | } |
4df46dbd L |
104 | #ifdef EXPORT_RPC_SYMBOLS |
105 | libc_hidden_def (svc_run) | |
106 | #else | |
021db4be | 107 | libc_hidden_nolink_sunrpc (svc_run, GLIBC_2_0) |
4df46dbd | 108 | #endif |