~ubuntu-branches/debian/wheezy/autofs/wheezy

« back to all changes in this revision

Viewing changes to debian/patches/060_non_replicated_ping.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2008-03-08 01:36:09 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080308013609-cvs4f2ecoyoism02
Tags: 4.1.4+debian-2.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Add -DLDAP_DEPRECATED to CFLAGS, to fix compatibility with OpenLDAP
  2.4 on 64-bit architectures.  Closes: #463419.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh /usr/share/dpatch/dpatch-run
 
2
## 060_non_replicated_ping.dpatch
 
3
##
 
4
## DP: No description.
 
5
 
 
6
@DPATCH@
 
7
 
 
8
diff -Naur .B/modules/mount_nfs.c .A/modules/mount_nfs.c
 
9
--- .B/modules/mount_nfs.c      2005-04-05 12:42:42.000000000 +0000
 
10
+++ .A/modules/mount_nfs.c      2007-01-07 21:36:35.000000000 +0000
 
11
@@ -31,6 +31,7 @@
 
12
 #include <netinet/in.h>
 
13
 #include <linux/nfs.h>
 
14
 #include <linux/nfs2.h>
 
15
+#include <ctype.h>
 
16
 
 
17
 #define MODULE_MOUNT
 
18
 #include "automount.h"
 
19
@@ -105,28 +106,117 @@
 
20
        
 
21
        return 1;
 
22
 }
 
23
+
 
24
+/*
 
25
+ * If the entry doesn't contain a ',' or doesn't contain more than
 
26
+ * one ':' then @what is not a replicated server entry.
 
27
+ */
 
28
+static int inline is_replicated_entry(char *what)
 
29
+{
 
30
+       return strchr(what, ',') ||
 
31
+               (strchr(what, ':') != strrchr(what, ':'));
 
32
+}
 
33
+
 
34
+/*
 
35
+ *  Check to see if the 'host:path' or 'host' is on the local machine
 
36
+ *  Returns < 0 if there is a host lookup problem, otherwise returns 0
 
37
+ *  if it's not a local mount, and returns > 0 if it is a local mount.
 
38
+ */
 
39
+int is_local_mount(const char *hostpath)
 
40
+{
 
41
+       struct hostent *he;
 
42
+       char **haddr;
 
43
+       char *delim;
 
44
+       char *hostname;
 
45
+       int hostnamelen;
 
46
+       int local = 0;
 
47
+
 
48
+       debug(MODPREFIX "is_local_mount: %s", hostpath);
 
49
+       delim = strpbrk(hostpath,":");
 
50
+
 
51
+       if (delim) 
 
52
+               hostnamelen = delim - hostpath; 
 
53
+       else 
 
54
+               hostnamelen = strlen(hostpath);
 
55
+
 
56
+       hostname = malloc(hostnamelen+1);
 
57
+       strncpy(hostname, hostpath, hostnamelen);
 
58
+       hostname[hostnamelen] = '\0';
 
59
+       he = gethostbyname(hostname);
 
60
+       if (!he) {
 
61
+               error(MODPREFIX "host %s: lookup failure", hostname);
 
62
+               return -1;
 
63
+       }
 
64
+
 
65
+       for (haddr = he->h_addr_list; *haddr; haddr++) {
 
66
+               local = is_local_addr(hostname, *haddr, he->h_length);
 
67
+               if (local < 0) 
 
68
+                       return local;
 
69
+               if (local) {
 
70
+                       debug(MODPREFIX "host %s: is localhost",
 
71
+                                       hostname);
 
72
+                       return local;
 
73
+               }
 
74
+       }
 
75
+       return 0;
 
76
+}
 
77
+
 
78
 /*
 
79
  * Given a mount string, return (in the same string) the
 
80
- * best mount to use based on weight/locality/rpctime
 
81
+ * best mount to use based on locality/weight/rpctime.
 
82
+ *
 
83
+ * If longtimeout is set to 0 then we only do 100 ms pings to hosts.  In
 
84
+ * the event that this fails, we call ourself recursively with the
 
85
+ * longtimeout option set to 1.  In this case we ping for up to 10s and
 
86
+ * skip logic for detecting if a localhost has been passed. (if a local
 
87
+ * host had been passed, we would have returned that mount as the best
 
88
+ * mount.  The skipping of local maps in this case is an optimization).
 
89
+ *
 
90
  * - return -1 and what = '\0' on error,
 
91
  *           1 and what = local mount path if local bind,
 
92
  *     else  0 and what = remote mount path
 
93
  */
 
94
-int get_best_mount(char *what, const char *original, int longtimeout, int skiplocal)
 
95
+int get_best_mount(char *what, const char *original, int longtimeout)
 
96
 {
 
97
        char *p = what;
 
98
        char *winner = NULL;
 
99
        int winner_weight = INT_MAX, local = 0;
 
100
        double winner_time = 0;
 
101
-       char *delim;
 
102
+       char *delim, *pstrip;
 
103
        int sec = (longtimeout) ? 10 : 0;
 
104
        int micros = (longtimeout) ? 0 : 100000;
 
105
+       int skiplocal = longtimeout; /* clearly local is not available */
 
106
 
 
107
        if (!p) {
 
108
                *what = '\0';
 
109
                return -1;
 
110
        }
 
111
 
 
112
+       /*
 
113
+        *  If only one mountpoint has been passed in, we don't need to
 
114
+        *  do anything except strip whitespace from the end of the string.
 
115
+        */
 
116
+       if (!is_replicated_entry(p)) {
 
117
+               for (pstrip = p+strlen(p) - 1; pstrip >= p; pstrip--) 
 
118
+                       if (isspace(*pstrip))
 
119
+                               *pstrip = '\0';
 
120
+
 
121
+               /* Check if the host is the localhost */
 
122
+               if (is_local_mount(p) > 0) {
 
123
+                       debug(MODPREFIX "host %s: is localhost", p);
 
124
+
 
125
+                       /* Strip off hostname and ':' */
 
126
+                       delim = strchr(p,':');
 
127
+                       while (delim && *delim != '\0') {
 
128
+                               delim++;
 
129
+                               *what = *delim;
 
130
+                               what++;
 
131
+                       }
 
132
+                       return 1;
 
133
+               }
 
134
+               return 0;
 
135
+       }
 
136
+
 
137
        while (p && *p) {
 
138
                char *next;
 
139
                unsigned int ping_stat = 0;
 
140
@@ -171,37 +261,17 @@
 
141
                /* p points to a server, "next is our next parse point */
 
142
                if (!skiplocal) {
 
143
                        /* Check if it's localhost */
 
144
-                       struct hostent *he;
 
145
-                       char **haddr;
 
146
-
 
147
-                       he = gethostbyname(p);
 
148
-                       if (!he) {
 
149
-                               error(MODPREFIX "host %s: lookup failure", p);
 
150
-                               p = next;
 
151
-                               continue;
 
152
-                       }
 
153
-
 
154
-                       /* Check each host in round robin list */
 
155
-                       for (haddr = he->h_addr_list; *haddr; haddr++) {
 
156
-                               local = is_local_addr(p, *haddr, he->h_length);
 
157
-
 
158
-                               if (local < 0)
 
159
-                                       continue;
 
160
-
 
161
-                               if (local) {
 
162
-                                       winner = p;
 
163
-                                       break;
 
164
-                               }
 
165
-                       }
 
166
-                       
 
167
+                       local = is_local_mount(p);
 
168
                        if (local < 0) {
 
169
                                local = 0;
 
170
                                p = next;
 
171
                                continue;
 
172
                        }
 
173
 
 
174
-                       if (local)
 
175
+                       if (local) {
 
176
+                               winner = p;
 
177
                                break;
 
178
+                       }
 
179
                }
 
180
 
 
181
                /* ping each (or the) entry to see if it's alive. */
 
182
@@ -214,6 +284,7 @@
 
183
                /* First unweighted or only host is alive so set winner */
 
184
                if (!winner) {
 
185
                        winner = p;
 
186
+                       winner_time = 1;
 
187
                        /* No more to check, return it */
 
188
                        if (!next || !*next)
 
189
                                break;
 
190
@@ -256,7 +327,7 @@
 
191
         */
 
192
        if (!local && winner_weight == INT_MAX) {
 
193
                /* We had more than one contender and none responded in time */
 
194
-               if (winner_time != 0 && winner_time > 500) {
 
195
+               if (winner_time == 0 || winner_time > 500) {
 
196
                        /* We've already tried a longer timeout */
 
197
                        if (!longtimeout) {
 
198
                                /* Reset string and try again */
 
199
@@ -267,16 +338,14 @@
 
200
                                      "retrying with longer timeout",
 
201
                                      original);
 
202
 
 
203
-                               return get_best_mount(what, original, 1, 1);
 
204
+                               return get_best_mount(what, original, 1);
 
205
                        }
 
206
                }
 
207
        }
 
208
 
 
209
-       /* No winner found so bail */
 
210
-       if (!winner) {
 
211
-               *what = '\0';
 
212
-               return 0;
 
213
-       }
 
214
+       /* No winner found so return first */
 
215
+       if (!winner)
 
216
+               winner = what;
 
217
 
 
218
        /*
 
219
         * We now have our winner, copy it to the front of the string,
 
220
@@ -395,7 +464,7 @@
 
221
                /* No colon, take this as a bind (local) entry */
 
222
                local = 1;
 
223
        } else if (!nosymlink) {
 
224
-               local = get_best_mount(whatstr, what, 0, 0);
 
225
+               local = get_best_mount(whatstr, what, 0);
 
226
                if (!*whatstr) {
 
227
                        warn(MODPREFIX "no host elected");
 
228
                        return 1;