Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
a87e8be2
G
git
项目概览
李少辉-开发者
/
git
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a87e8be2
编写于
7月 13, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a "git-daemon" that listens on a TCP port
.. and does a "git-upload-pack" on demand.
上级
85c414b5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
1 deletion
+118
-1
Makefile
Makefile
+1
-1
daemon.c
daemon.c
+117
-0
未找到文件。
Makefile
浏览文件 @
a87e8be2
...
...
@@ -48,7 +48,7 @@ PROG= git-update-cache git-diff-files git-init-db git-write-tree \
git-diff-stages git-rev-parse git-patch-id git-pack-objects
\
git-unpack-objects git-verify-pack git-receive-pack git-send-pack
\
git-prune-packed git-fetch-pack git-upload-pack git-clone-pack
\
git-show-index
git-show-index
git-daemon
all
:
$(PROG)
...
...
daemon.c
0 → 100644
浏览文件 @
a87e8be2
#include "cache.h"
#include "pkt-line.h"
#include <sys/socket.h>
#include <netinet/in.h>
static
const
char
daemon_usage
[]
=
"git-daemon [--port=n]"
;
static
int
upload
(
char
*
dir
,
int
dirlen
)
{
if
(
chdir
(
dir
)
<
0
)
return
-
1
;
chdir
(
".git"
);
/*
* Security on the cheap.
*
* We want a readable HEAD, usable "objects" directory, and
* a "git-daemon-export-ok" flag that says that the other side
* is ok with us doing this.
*/
if
(
access
(
"git-daemon-export-ok"
,
F_OK
)
||
access
(
"objects/00"
,
X_OK
)
||
access
(
"HEAD"
,
R_OK
))
return
-
1
;
/* git-upload-pack only ever reads stuff, so this is safe */
execlp
(
"git-upload-pack"
,
"git-upload-pack"
,
"."
,
NULL
);
return
-
1
;
}
static
int
execute
(
char
*
line
,
int
len
)
{
if
(
!
strncmp
(
"git-upload-pack /"
,
line
,
17
))
return
upload
(
line
+
16
,
len
-
16
);
fprintf
(
stderr
,
"got bad connection '%s'
\n
"
,
line
);
return
-
1
;
}
static
void
handle
(
int
incoming
,
struct
sockaddr_in
*
addr
,
int
addrlen
)
{
static
char
line
[
1000
];
int
len
;
if
(
fork
())
{
close
(
incoming
);
return
;
}
dup2
(
incoming
,
0
);
dup2
(
incoming
,
1
);
close
(
incoming
);
len
=
packet_read_line
(
0
,
line
,
sizeof
(
line
));
if
(
len
&&
line
[
len
-
1
]
==
'\n'
)
line
[
--
len
]
=
0
;
exit
(
execute
(
line
,
len
));
}
static
int
serve
(
int
port
)
{
int
sockfd
;
struct
sockaddr_in
addr
;
sockfd
=
socket
(
PF_INET
,
SOCK_STREAM
,
IPPROTO_IP
);
if
(
sockfd
<
0
)
die
(
"unable to open socket (%s)"
,
strerror
(
errno
));
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
sin_port
=
htons
(
port
);
addr
.
sin_family
=
AF_INET
;
if
(
bind
(
sockfd
,
(
void
*
)
&
addr
,
sizeof
(
addr
))
<
0
)
die
(
"unable to bind to port %d (%s)"
,
port
,
strerror
(
errno
));
if
(
listen
(
sockfd
,
5
)
<
0
)
die
(
"unable to listen to port %d (%s)"
,
port
,
strerror
(
errno
));
for
(;;)
{
struct
sockaddr_in
in
;
socklen_t
addrlen
=
sizeof
(
in
);
int
incoming
=
accept
(
sockfd
,
(
void
*
)
&
in
,
&
addrlen
);
if
(
incoming
<
0
)
{
switch
(
errno
)
{
case
EAGAIN
:
case
EINTR
:
case
ECONNABORTED
:
continue
;
default:
die
(
"accept returned %s"
,
strerror
(
errno
));
}
}
handle
(
incoming
,
&
in
,
addrlen
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
port
=
DEFAULT_GIT_PORT
;
int
i
;
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
char
*
arg
=
argv
[
i
];
if
(
!
strncmp
(
arg
,
"--port="
,
7
))
{
char
*
end
;
unsigned
long
n
;
n
=
strtoul
(
arg
+
7
,
&
end
,
0
);
if
(
arg
[
7
]
&&
!*
end
)
{
port
=
n
;
continue
;
}
}
usage
(
daemon_usage
);
}
return
serve
(
port
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录