summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3bd62c2)
raw | patch | inline | side by side (parent: 3bd62c2)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 24 Aug 2008 20:27:10 +0000 (13:27 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 26 Aug 2008 05:49:49 +0000 (22:49 -0700) |
* "else" on the same line as "}" that closes corresponding "if (...) {";
* multi-line comments begin with "/*\n";
* sizeof, even it is not a function, is written as "sizeof(...)";
* no need to check x?alloc() return value -- it would have died;
* "if (...) { ... }" that covers the whole function body can be dedented
by returning from the function early with "if (!...) return;";
* SP on each side of an operator, i.e. "a > 0", not "a>0";
Also removes stale comment describing how remove_child() used to do its
thing.
Signed-off-by: Junio C Hamano <gitster@pobox.com>:
Signed-off-by: Junio C Hamano <gitster@pobox.com>
* multi-line comments begin with "/*\n";
* sizeof, even it is not a function, is written as "sizeof(...)";
* no need to check x?alloc() return value -- it would have died;
* "if (...) { ... }" that covers the whole function body can be dedented
by returning from the function early with "if (!...) return;";
* SP on each side of an operator, i.e. "a > 0", not "a>0";
Also removes stale comment describing how remove_child() used to do its
thing.
Signed-off-by: Junio C Hamano <gitster@pobox.com>:
Signed-off-by: Junio C Hamano <gitster@pobox.com>
daemon.c | patch | blob | history |
diff --git a/daemon.c b/daemon.c
index 79f0388204848f1e1085c48be8e6a86bb14cef68..23278e28dc16cc30bd9516f2f2675cd93d5ac182 100644 (file)
--- a/daemon.c
+++ b/daemon.c
char buf[1024];
vsnprintf(buf, sizeof(buf), err, params);
syslog(priority, "%s", buf);
- }
- else {
- /* Since stderr is set to linebuffered mode, the
+ } else {
+ /*
+ * Since stderr is set to linebuffered mode, the
* logging of different processes will not overlap
*/
fprintf(stderr, "[%d] ", (int)getpid());
static void add_child(pid_t pid, struct sockaddr *addr, int addrlen)
{
- struct child *newborn;
- newborn = xcalloc(1, sizeof *newborn);
- if (newborn) {
- struct child **cradle;
-
- live_children++;
- newborn->pid = pid;
- memcpy(&newborn->address, addr, addrlen);
- for (cradle = &firstborn; *cradle; cradle = &(*cradle)->next)
- if (!memcmp(&(*cradle)->address, &newborn->address,
- sizeof newborn->address))
- break;
- newborn->next = *cradle;
- *cradle = newborn;
- }
- else
- logerror("Out of memory spawning new child");
+ struct child *newborn, **cradle;
+
+ /*
+ * This must be xcalloc() -- we'll compare the whole sockaddr_storage
+ * but individual address may be shorter.
+ */
+ newborn = xcalloc(1, sizeof(*newborn));
+ live_children++;
+ newborn->pid = pid;
+ memcpy(&newborn->address, addr, addrlen);
+ for (cradle = &firstborn; *cradle; cradle = &(*cradle)->next)
+ if (!memcmp(&(*cradle)->address, &newborn->address,
+ sizeof(newborn->address)))
+ break;
+ newborn->next = *cradle;
+ *cradle = newborn;
}
-/*
- * Walk from "deleted" to "spawned", and remove child "pid".
- *
- * We move everything up by one, since the new "deleted" will
- * be one higher.
- */
static void remove_child(pid_t pid)
{
struct child **cradle, *blanket;
*/
static void kill_some_child(void)
{
- const struct child *blanket;
+ const struct child *blanket, *next;
- if ((blanket = firstborn)) {
- const struct child *next;
+ if (!(blanket = firstborn))
+ return;
- for (; (next = blanket->next); blanket = next)
- if (!memcmp(&blanket->address, &next->address,
- sizeof next->address)) {
- kill(blanket->pid, SIGTERM);
- break;
- }
- }
+ for (; (next = blanket->next); blanket = next)
+ if (!memcmp(&blanket->address, &next->address,
+ sizeof(next->address))) {
+ kill(blanket->pid, SIGTERM);
+ break;
+ }
}
static void check_dead_children(void)
int status;
pid_t pid;
- while ((pid = waitpid(-1, &status, WNOHANG))>0) {
+ while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
const char *dead = "";
remove_child(pid);
- if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
+ if (!WIFEXITED(status) || (WEXITSTATUS(status) > 0))
dead = " (with error)";
loginfo("[%d] Disconnected%s", (int)pid, dead);
}
if (max_connections && live_children >= max_connections) {
kill_some_child();
- sleep(1); /* give it some time to die */
+ sleep(1); /* give it some time to die */
check_dead_children();
if (live_children >= max_connections) {
close(incoming);
static void child_handler(int signo)
{
- /* Otherwise empty handler because systemcalls will get interrupted
+ /*
+ * Otherwise empty handler because systemcalls will get interrupted
* upon signal receipt
* SysV needs the handler to be rearmed
*/
if (log_syslog) {
openlog("git-daemon", LOG_PID, LOG_DAEMON);
set_die_routine(daemon_die);
- }
- else
+ } else
setlinebuf(stderr); /* avoid splitting a message in the middle */
if (inetd_mode && (group_name || user_name))