##// END OF EJS Templates
chg: start server at a unique address...
Jun Wu -
r30620:937c52f0 default
parent child Browse files
Show More
@@ -31,6 +31,7 b''
31
31
32 struct cmdserveropts {
32 struct cmdserveropts {
33 char sockname[UNIX_PATH_MAX];
33 char sockname[UNIX_PATH_MAX];
34 char initsockname[UNIX_PATH_MAX];
34 char redirectsockname[UNIX_PATH_MAX];
35 char redirectsockname[UNIX_PATH_MAX];
35 char lockfile[UNIX_PATH_MAX];
36 char lockfile[UNIX_PATH_MAX];
36 size_t argsize;
37 size_t argsize;
@@ -163,6 +164,10 b' static void setcmdserveropts(struct cmds'
163 r = snprintf(opts->lockfile, sizeof(opts->lockfile), lockfmt, basename);
164 r = snprintf(opts->lockfile, sizeof(opts->lockfile), lockfmt, basename);
164 if (r < 0 || (size_t)r >= sizeof(opts->lockfile))
165 if (r < 0 || (size_t)r >= sizeof(opts->lockfile))
165 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
166 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
167 r = snprintf(opts->initsockname, sizeof(opts->initsockname),
168 "%s.%u", opts->sockname, (unsigned)getpid());
169 if (r < 0 || (size_t)r >= sizeof(opts->initsockname))
170 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
166 }
171 }
167
172
168 /*
173 /*
@@ -223,7 +228,7 b' static void execcmdserver(const struct c'
223 hgcmd,
228 hgcmd,
224 "serve",
229 "serve",
225 "--cmdserver", "chgunix",
230 "--cmdserver", "chgunix",
226 "--address", opts->sockname,
231 "--address", opts->initsockname,
227 "--daemon-postexec", "chdir:/",
232 "--daemon-postexec", "chdir:/",
228 };
233 };
229 size_t baseargvsize = sizeof(baseargv) / sizeof(baseargv[0]);
234 size_t baseargvsize = sizeof(baseargv) / sizeof(baseargv[0]);
@@ -247,7 +252,7 b' static hgclient_t *retryconnectcmdserver'
247 static const struct timespec sleepreq = {0, 10 * 1000000};
252 static const struct timespec sleepreq = {0, 10 * 1000000};
248 int pst = 0;
253 int pst = 0;
249
254
250 debugmsg("try connect to %s repeatedly", opts->sockname);
255 debugmsg("try connect to %s repeatedly", opts->initsockname);
251
256
252 unsigned int timeoutsec = 60; /* default: 60 seconds */
257 unsigned int timeoutsec = 60; /* default: 60 seconds */
253 const char *timeoutenv = getenv("CHGTIMEOUT");
258 const char *timeoutenv = getenv("CHGTIMEOUT");
@@ -255,9 +260,15 b' static hgclient_t *retryconnectcmdserver'
255 sscanf(timeoutenv, "%u", &timeoutsec);
260 sscanf(timeoutenv, "%u", &timeoutsec);
256
261
257 for (unsigned int i = 0; !timeoutsec || i < timeoutsec * 100; i++) {
262 for (unsigned int i = 0; !timeoutsec || i < timeoutsec * 100; i++) {
258 hgclient_t *hgc = hgc_open(opts->sockname);
263 hgclient_t *hgc = hgc_open(opts->initsockname);
259 if (hgc)
264 if (hgc) {
265 debugmsg("rename %s to %s", opts->initsockname,
266 opts->sockname);
267 int r = rename(opts->initsockname, opts->sockname);
268 if (r != 0)
269 abortmsgerrno("cannot rename");
260 return hgc;
270 return hgc;
271 }
261
272
262 if (pid > 0) {
273 if (pid > 0) {
263 /* collect zombie if child process fails to start */
274 /* collect zombie if child process fails to start */
@@ -269,7 +280,7 b' static hgclient_t *retryconnectcmdserver'
269 nanosleep(&sleepreq, NULL);
280 nanosleep(&sleepreq, NULL);
270 }
281 }
271
282
272 abortmsg("timed out waiting for cmdserver %s", opts->sockname);
283 abortmsg("timed out waiting for cmdserver %s", opts->initsockname);
273 return NULL;
284 return NULL;
274
285
275 cleanup:
286 cleanup:
@@ -312,7 +323,7 b' static hgclient_t *connectcmdserver(stru'
312 if (sockname == opts->redirectsockname)
323 if (sockname == opts->redirectsockname)
313 unlink(opts->sockname);
324 unlink(opts->sockname);
314
325
315 debugmsg("start cmdserver at %s", opts->sockname);
326 debugmsg("start cmdserver at %s", opts->initsockname);
316
327
317 pid_t pid = fork();
328 pid_t pid = fork();
318 if (pid < 0)
329 if (pid < 0)
@@ -46,7 +46,7 b' isolate socket directory for stable resu'
46 warm up server:
46 warm up server:
47
47
48 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
48 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
49 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
49 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
50
50
51 new server should be started if extension modified:
51 new server should be started if extension modified:
52
52
@@ -55,7 +55,7 b' new server should be started if extensio'
55 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
55 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
56 chg: debug: instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
56 chg: debug: instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
57 chg: debug: instruction: reconnect
57 chg: debug: instruction: reconnect
58 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
58 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
59
59
60 old server will shut down, while new server should still be reachable:
60 old server will shut down, while new server should still be reachable:
61
61
@@ -77,7 +77,7 b' since no server is reachable from socket'
77 (this test makes sure that old server shut down automatically)
77 (this test makes sure that old server shut down automatically)
78
78
79 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
79 $ CHGDEBUG= chg log 2>&1 | egrep 'instruction|start'
80 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server
80 chg: debug: start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
81
81
82 shut down servers and restore environment:
82 shut down servers and restore environment:
83
83
General Comments 0
You need to be logged in to leave comments. Login now