[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.contrib.usher: 1336ca3b4c1b3
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.contrib.usher: 1336ca3b4c1b316eeeec33f333f7506dcc40a858 |
Date: |
Wed, 1 Jun 2011 10:22:58 +0200 (CEST) |
revision: 1336ca3b4c1b316eeeec33f333f7506dcc40a858
date: 2011-06-01T08:22:35
author: Richard Levitte <address@hidden>
branch: net.venge.monotone.contrib.usher
changelog:
Issue 175: usher depends on the underlying monotone server to output
'beginning service'. This is a bit fragile, it will fail if someone
prints a message from the rc file for that server, or if there's a -v
among the arguments to it.
A way to solve this is to simply try to connect to it, and if that fails,
see if the local monotone server is still running.
* src/server.cc (fork_server): Remove all checks for 'beginning service'.
(server::connect): For local monotone servers, loop around
sock::connect until it succeeds, but only as long as the local server
is still running. For remote servers, fail if sock::connect fails.
manifest:
format_version "1"
new_manifest [b134e209bb5a3183420f80b5544179db6200a973]
old_revision [4de67f067e7e4cc1c86d5d11d538309df648183d]
patch "src/server.cc"
from [faee2d3ecdc1ec94001f0046a25d0937cf495087]
to [0a6f67d6ee6e247ed4cf68dec60a426ac5fb98ad]
============================================================
--- src/server.cc faee2d3ecdc1ec94001f0046a25d0937cf495087
+++ src/server.cc 0a6f67d6ee6e247ed4cf68dec60a426ac5fb98ad
@@ -234,12 +234,27 @@ server::connect(string const &name)
pid = fork_server(logfilename, args);
}
}
- if (local && pid == -1)
- throw std::runtime_error("Cannot start server. Please ask the admin to review the server log.");
- sock s = sock::connect(addr, port);
- ++connection_count;
- clients.insert(name);
- return s;
+ while (!local || (pid != -1 && waitpid(pid, 0, WNOHANG) != -1))
+ {
+ usleep(10*1000);
+
+ try
+ {
+ sock s = sock::connect(addr, port);
+ ++connection_count;
+ clients.insert(name);
+ return s;
+ }
+ catch (platform_error &e)
+ {
+ if (!local)
+ throw;
+ }
+ catch (...) {
+ throw;
+ }
+ }
+ throw std::runtime_error("Cannot start server. Please ask the admin to review the server log.");
}
void
@@ -334,37 +349,7 @@ int fork_server(string const &logfile, v
exit(6);
} else {
close(err[1]);
- char head[256];
- int got = 0;
- int r = 0, w = 0;
- bool line = false;
- // the first line output on the server's stderr will be either
- // "mtn: beginning service on <interface> : <port>" or
- // "mtn: network error: bind(2) error: Address already in use"
- //
- // Now that reads a file instead of a pipe, we need to poll it
- // until either we get our output or the server dies. This is
- // because read() doesn't block on EOF.
- do {
- usleep(10*1000);
- r = read(err[0], head + got, 256 - got);
- if (r)
- cerr<<"Read '"<<string(head+got, r)<<"'\n";
- if (r > 0) {
- for (int i = 0; i < r && !line; ++i)
- if (head[got+i] == '\n')
- line = true;
- got += r;
- }
- w = waitpid(pid, 0, WNOHANG);
- } while((!w || r > 0) && !line && got < 256);
- head[got] = 0;
close(err[0]);
- if (string(head).find("beginning service") != string::npos)
- return pid;
- kill(pid, SIGKILL);
- int status;
- do {r = waitpid(pid, &status, 0);} while (r==-1 && errno == EINTR);
- return -1;
+ return pid;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.contrib.usher: 1336ca3b4c1b316eeeec33f333f7506dcc40a858,
code <=