daemon.c: minor style fixup
* "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>
This commit is contained in:
parent
3bd62c2176
commit
460c201039
74
daemon.c
74
daemon.c
@ -81,9 +81,9 @@ static void logreport(int priority, const char *err, va_list params)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
vsnprintf(buf, sizeof(buf), err, params);
|
vsnprintf(buf, sizeof(buf), err, params);
|
||||||
syslog(priority, "%s", buf);
|
syslog(priority, "%s", buf);
|
||||||
}
|
} else {
|
||||||
else {
|
/*
|
||||||
/* Since stderr is set to linebuffered mode, the
|
* Since stderr is set to linebuffered mode, the
|
||||||
* logging of different processes will not overlap
|
* logging of different processes will not overlap
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "[%d] ", (int)getpid());
|
fprintf(stderr, "[%d] ", (int)getpid());
|
||||||
@ -596,31 +596,24 @@ static struct child {
|
|||||||
|
|
||||||
static void add_child(pid_t pid, struct sockaddr *addr, int addrlen)
|
static void add_child(pid_t pid, struct sockaddr *addr, int addrlen)
|
||||||
{
|
{
|
||||||
struct child *newborn;
|
struct child *newborn, **cradle;
|
||||||
newborn = xcalloc(1, sizeof *newborn);
|
|
||||||
if (newborn) {
|
|
||||||
struct child **cradle;
|
|
||||||
|
|
||||||
live_children++;
|
/*
|
||||||
newborn->pid = pid;
|
* This must be xcalloc() -- we'll compare the whole sockaddr_storage
|
||||||
memcpy(&newborn->address, addr, addrlen);
|
* but individual address may be shorter.
|
||||||
for (cradle = &firstborn; *cradle; cradle = &(*cradle)->next)
|
*/
|
||||||
if (!memcmp(&(*cradle)->address, &newborn->address,
|
newborn = xcalloc(1, sizeof(*newborn));
|
||||||
sizeof newborn->address))
|
live_children++;
|
||||||
break;
|
newborn->pid = pid;
|
||||||
newborn->next = *cradle;
|
memcpy(&newborn->address, addr, addrlen);
|
||||||
*cradle = newborn;
|
for (cradle = &firstborn; *cradle; cradle = &(*cradle)->next)
|
||||||
}
|
if (!memcmp(&(*cradle)->address, &newborn->address,
|
||||||
else
|
sizeof(newborn->address)))
|
||||||
logerror("Out of memory spawning new child");
|
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)
|
static void remove_child(pid_t pid)
|
||||||
{
|
{
|
||||||
struct child **cradle, *blanket;
|
struct child **cradle, *blanket;
|
||||||
@ -642,18 +635,17 @@ static void remove_child(pid_t pid)
|
|||||||
*/
|
*/
|
||||||
static void kill_some_child(void)
|
static void kill_some_child(void)
|
||||||
{
|
{
|
||||||
const struct child *blanket;
|
const struct child *blanket, *next;
|
||||||
|
|
||||||
if ((blanket = firstborn)) {
|
if (!(blanket = firstborn))
|
||||||
const struct child *next;
|
return;
|
||||||
|
|
||||||
for (; (next = blanket->next); blanket = next)
|
for (; (next = blanket->next); blanket = next)
|
||||||
if (!memcmp(&blanket->address, &next->address,
|
if (!memcmp(&blanket->address, &next->address,
|
||||||
sizeof next->address)) {
|
sizeof(next->address))) {
|
||||||
kill(blanket->pid, SIGTERM);
|
kill(blanket->pid, SIGTERM);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_dead_children(void)
|
static void check_dead_children(void)
|
||||||
@ -661,10 +653,10 @@ static void check_dead_children(void)
|
|||||||
int status;
|
int status;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
while ((pid = waitpid(-1, &status, WNOHANG))>0) {
|
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
|
||||||
const char *dead = "";
|
const char *dead = "";
|
||||||
remove_child(pid);
|
remove_child(pid);
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
|
if (!WIFEXITED(status) || (WEXITSTATUS(status) > 0))
|
||||||
dead = " (with error)";
|
dead = " (with error)";
|
||||||
loginfo("[%d] Disconnected%s", (int)pid, dead);
|
loginfo("[%d] Disconnected%s", (int)pid, dead);
|
||||||
}
|
}
|
||||||
@ -676,7 +668,7 @@ static void handle(int incoming, struct sockaddr *addr, int addrlen)
|
|||||||
|
|
||||||
if (max_connections && live_children >= max_connections) {
|
if (max_connections && live_children >= max_connections) {
|
||||||
kill_some_child();
|
kill_some_child();
|
||||||
sleep(1); /* give it some time to die */
|
sleep(1); /* give it some time to die */
|
||||||
check_dead_children();
|
check_dead_children();
|
||||||
if (live_children >= max_connections) {
|
if (live_children >= max_connections) {
|
||||||
close(incoming);
|
close(incoming);
|
||||||
@ -705,7 +697,8 @@ static void handle(int incoming, struct sockaddr *addr, int addrlen)
|
|||||||
|
|
||||||
static void child_handler(int signo)
|
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
|
* upon signal receipt
|
||||||
* SysV needs the handler to be rearmed
|
* SysV needs the handler to be rearmed
|
||||||
*/
|
*/
|
||||||
@ -1089,8 +1082,7 @@ int main(int argc, char **argv)
|
|||||||
if (log_syslog) {
|
if (log_syslog) {
|
||||||
openlog("git-daemon", LOG_PID, LOG_DAEMON);
|
openlog("git-daemon", LOG_PID, LOG_DAEMON);
|
||||||
set_die_routine(daemon_die);
|
set_die_routine(daemon_die);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
setlinebuf(stderr); /* avoid splitting a message in the middle */
|
setlinebuf(stderr); /* avoid splitting a message in the middle */
|
||||||
|
|
||||||
if (inetd_mode && (group_name || user_name))
|
if (inetd_mode && (group_name || user_name))
|
||||||
|
Loading…
Reference in New Issue
Block a user