distcc源代码详解(1)
1、distcc分为server端和client端,其中client端,是在执行make命令编译的时候调用,而server端,是程序接受client端的请求,完成编译的任务
在dameon.c中可以找到main函数,是server函数的入口
/**
* distcc daemon. May run from inetd, or standalone. Accepts
* requests from clients to compile files.
**/
int main(int argc, char *argv[])
{
int ret;
dcc_setup_startup_log();
if (distccd_parse_options(argc, (const char **) argv))
dcc_exit(EXIT_DISTCC_FAILED);
/* check this before redirecting the logs, so that it's really obvious */
if (!dcc_should_be_inetd())
if (opt_allowed == NULL) {
rs_log_error("--allow option is now mandatory; "
"you must specify which clients are allowed to connect");
ret = EXIT_BAD_ARGUMENTS;
goto out;
}
if ((ret = dcc_set_lifetime()) != 0)
dcc_exit(ret);
/* do this before giving away root */
if (nice(opt_niceness) == -1) {
rs_log_warning("nice %d failed: %s", opt_niceness,
strerror(errno));
/* continue anyhow */
}
if ((ret = dcc_discard_root()) != 0)
dcc_exit(ret);
/* Discard privileges before opening log so that if it's created, it has
* the right ownership. */
dcc_setup_real_log();
/* Do everything from $TMPDIR directory. Allows start directory to be
* unmounted. */
if ((ret = dcc_get_tmp_top(&dcc_daemon_wd)))
goto out;
if (chdir(dcc_daemon_wd) == -1) {
rs_log_error("failed to chdir to %s: %s",
dcc_daemon_wd, strerror(errno));
ret = EXIT_IO_ERROR;
goto out;
} else {
rs_trace("chdir to %s", dcc_daemon_wd);
}
if ((ret = dcc_setup_daemon_path()))
goto out;
#ifdef HAVE_GSSAPI
/* Obtain credentials if authentication is requested. */
if (dcc_auth_enabled) {
if ((ret = dcc_gssapi_acquire_credentials()) != 0) {
goto out;
}
/* Read contents of list file into an array and apply qsort. */
if (opt_blacklist_enabled || opt_whitelist_enabled) {
if ((ret = dcc_gssapi_obtain_list((opt_blacklist_enabled) ? 1 : 0)) != 0) {
goto out;
}
}
}
#endif
/* Initialize the distcc io timeout value */
dcc_get_io_timeout();
if (dcc_should_be_inetd())
ret = dcc_inetd_server();
else
ret = dcc_standalone_server();
out:
dcc_exit(ret);
}
distccd_parse_options函数解析入参,dcc_discard_root()如果进程具有root权限,则换成一个低权限的运行,dcc_run_job这个函数接受client端的请求并完成编译,
dcc_run_job中该函数dcc_r_request_header得到对端的版本信息。
dcc_r_argv中获取client端发送的编译参数信息,即执行gcc时的参数信息,其中已经去除需要本地编译的参数必去-i,-I之类的
浙公网安备 33010602011771号