git-daemon: re-organize code a bit for --inetd flag

Alexey Nezhdanov sent a patch that made git-daemon usable from inetd (ie
where inetd has already done the accept on the new connection, the fork,
and the setup of stdin/stdout).  I wanted to organize the thing slightly
differently, though.
This commit is contained in:
Linus Torvalds 2005-07-15 09:27:05 -07:00
Родитель e68b6f1525
Коммит 7d80694af1
1 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -28,8 +28,16 @@ static int upload(char *dir, int dirlen)
return -1; return -1;
} }
static int execute(char *line, int len) static int execute(void)
{ {
static char line[1000];
int len;
len = packet_read_line(0, line, sizeof(line));
if (len && line[len-1] == '\n')
line[--len] = 0;
if (!strncmp("git-upload-pack /", line, 17)) if (!strncmp("git-upload-pack /", line, 17))
return upload(line + 16, len - 16); return upload(line + 16, len - 16);
@ -39,9 +47,6 @@ static int execute(char *line, int len)
static void handle(int incoming, struct sockaddr_in *addr, int addrlen) static void handle(int incoming, struct sockaddr_in *addr, int addrlen)
{ {
static char line[1000];
int len;
if (fork()) { if (fork()) {
close(incoming); close(incoming);
return; return;
@ -50,12 +55,7 @@ static void handle(int incoming, struct sockaddr_in *addr, int addrlen)
dup2(incoming, 0); dup2(incoming, 0);
dup2(incoming, 1); dup2(incoming, 1);
close(incoming); close(incoming);
len = packet_read_line(0, line, sizeof(line)); exit(execute());
if (len && line[len-1] == '\n')
line[--len] = 0;
exit(execute(line, len));
} }
static int serve(int port) static int serve(int port)