Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/gitPublic

Commit02d57da

Browse files
author
Linus Torvalds
committed
Be slightly smarter about git-daemon client shutdown
Shut down connections that haven't even identified themselves as gitclients first. That should get rid of people who just connect to theport and wait for something to happen.
1 parenta232a13 commit02d57da

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

‎daemon.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ static int upload(char *dir, int dirlen)
2626
access("HEAD",R_OK))
2727
return-1;
2828

29+
/*
30+
* We'll ignore SIGTERM from now on, we have a
31+
* good client.
32+
*/
33+
signal(SIGTERM,SIG_IGN);
34+
2935
/* git-upload-pack only ever reads stuff, so this is safe */
3036
execlp("git-upload-pack","git-upload-pack",".",NULL);
3137
return-1;
@@ -128,33 +134,24 @@ static void remove_child(pid_t pid, unsigned deleted, unsigned spawned)
128134
*
129135
* Really, this is just a place-holder for a _real_ algorithm.
130136
*/
131-
staticvoidkill_some_children(intconnections,unsignedstart,unsignedstop)
137+
staticvoidkill_some_children(intsigno,unsignedstart,unsignedstop)
132138
{
133139
start %=MAX_CHILDREN;
134140
stop %=MAX_CHILDREN;
135141
while (start!=stop) {
136142
if (!(start&3))
137-
kill(live_child[start].pid,SIGTERM);
143+
kill(live_child[start].pid,signo);
138144
start= (start+1) %MAX_CHILDREN;
139145
}
140146
}
141147

142-
staticvoidhandle(intincoming,structsockaddr_in*addr,intaddrlen)
148+
staticvoidcheck_max_connections(void)
143149
{
144-
pid_tpid=fork();
145-
146-
if (pid) {
150+
for (;;) {
147151
intactive;
148152
unsignedspawned,reaped,deleted;
149153

150-
close(incoming);
151-
if (pid<0)
152-
return;
153-
154154
spawned=children_spawned;
155-
add_child(spawned %MAX_CHILDREN,pid,addr,addrlen);
156-
children_spawned=++spawned;
157-
158155
reaped=children_reaped;
159156
deleted=children_deleted;
160157

@@ -166,15 +163,36 @@ static void handle(int incoming, struct sockaddr_in *addr, int addrlen)
166163
children_deleted=deleted;
167164

168165
active=spawned-deleted;
169-
if (active>max_connections) {
170-
kill_some_children(active,deleted,spawned);
166+
if (active<=max_connections)
167+
break;
171168

172-
/* Wait to make sure they're gone */
173-
while (spawned-children_reaped>max_connections)
174-
sleep(1);
175-
}
176-
169+
/* Kill some unstarted connections with SIGTERM */
170+
kill_some_children(SIGTERM,deleted,spawned);
171+
if (active <=max_connections <<1)
172+
break;
173+
174+
/* If the SIGTERM thing isn't helping use SIGKILL */
175+
kill_some_children(SIGKILL,deleted,spawned);
176+
sleep(1);
177+
}
178+
}
179+
180+
staticvoidhandle(intincoming,structsockaddr_in*addr,intaddrlen)
181+
{
182+
pid_tpid=fork();
183+
184+
if (pid) {
185+
unsignedidx;
186+
187+
close(incoming);
188+
if (pid<0)
189+
return;
190+
191+
idx=children_spawned %MAX_CHILDREN;
192+
children_spawned++;
193+
add_child(idx,pid,addr,addrlen);
177194

195+
check_max_connections();
178196
return;
179197
}
180198

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp