大多数开发人员使用git send-email发送邮件,本文也采用这种方式,当然也可以使用其他邮箱客户端,详细要求见《Linux邮件客户端配置信息》:
https://www.kernel.org/doc/html/latest/translations/zh_CN/process/email-clients.html
下面是真实的patch提交过程记录。
一、环境搭建
使用的主机系统是ubuntu-20.04 。
1.1 安装git和git-email
sudo apt-get install git
sudo apt-get install git-email
1.2 linux源码下载
使用如下命令下载linux主分支代码:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
如果比较慢,可以用
git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable
在不进行科学上网情况下,一般git clone速度很慢,且容易断连,推荐使用如下脚本进行下载:
#!/bin/sh
echo "======start git clone======"
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
while [ $? -ne 0 ]
do
echo "======clone failed, re-clone again======"
sleep 3
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
done
主分支代码一般不够新,我们需要基于linux-next分支修改并提交patch:
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
增加linux-next远程仓库后,拉取代码到本地:
git fetch --tags linux-next
有些模块的Maintainer还会维护自己的代码分支,详细信息可以linux内核源码的MAINTAINERS文件中找到,以driver-core模块为例:
/* MAINTAINERS */
DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
R: "Rafael J. Wysocki" <rafael@kernel.org>
S: Supported
T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
F: Documentation/core-api/kobject.rst
F: drivers/base/
F: fs/debugfs/
F: fs/sysfs/
F: include/linux/debugfs.h
F: include/linux/kobj*
F: lib/kobj*
可以看到driver core模块的维护者是Greg Kroah-Hartman,他的邮箱地址是gregkh@linuxfoundation.org,代码分支地址为:
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
拉取代码的步骤与linux-next分支方法相同:
git remote add driver-core git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
git fetch --tags driver-core
此时查看源码下的分支情况:
git branch -a
输出如下:
remotes/driver-core/debugfs_cleanup
remotes/driver-core/debugfs_cleanup_arm
remotes/driver-core/debugfs_cleanup_crypto
remotes/driver-core/debugfs_cleanup_ib
remotes/driver-core/debugfs_cleanup_mips
remotes/driver-core/debugfs_cleanup_scsi
remotes/driver-core/debugfs_cleanup_x86
remotes/driver-core/debugfs_remove_return_value
remotes/driver-core/dev_groups_all_drivers
remotes/driver-core/driver-core-linus
remotes/driver-core/driver-core-next
remotes/driver-core/driver-core-testing
remotes/driver-core/generic_lookup_helpers
remotes/driver-core/master
remotes/linux-next/akpm
remotes/linux-next/akpm-base
remotes/linux-next/master
remotes/linux-next/pending-fixes
remotes/linux-next/stable
remotes/origin/HEAD -> origin/master
remotes/origin/master
假设我们要修改的是driver core模块的代码,我们需将代码切到driver-core-next,并创建本地分支:
git checkout -b driver-core-next remotes/driver-core/driver-core-next
至此,源码的环境即搭建完成。
1.3 配置git
配置用户名和邮箱:
git config --global user.name "xxx"
git config --global user.email "xxx@email.com"
1.4 配置git-email
此处以gmail邮箱举例,手动修改~/.gitconfig文件或者git仓库下的.git/config文件,添加[sendemail]节:
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
smtpuser = xxx@gmail.com
smtpserverport = 587
举例
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
smtpuser = $(mail address)
smtpserverport = 587
from = $(name) <$(mail address)>
smtppass = (google生成的密码 5.7.9 Application-specific password required. Learn more at
5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor h7sm4628816pjc.15 - gsmtp)
chainreplyto = false
confirm = auto
smtpuser需替换成自己的gmail邮箱。
1.5 配置终端代理
首先安装proxychains4工具:
sudo apt-get install proxychains4
然后修改配置文件:
sudo vim /etc/proxychains.conf
将最后一行改为:
# socks4 127.0.0.1 9050
socks5 127.0.0.1 1080
测试配置是否生效:
proxychains4 curl www.google.com
有数据返回则说明生效,也有可能返回如下错误:
也有可能返回如下错误:
curl: (5) Could not resolve proxy: http
此时可以检查下系统环境变量:
env | grep -i proxy
如果相关proxy项已被设置,则需要清空:
export http_proxy=""
export https_proxy=""
export all_proxy=""
export ALL_PROXY=""
export HTTP_PROXY=""
export HTTPS_PROXY=""
export NO_PROXY=""
export no_proxy=""
再次查看环境变量,输出如下即可:
no_proxy=
https_proxy=
NO_PROXY=
HTTPS_PROXY=
HTTP_PROXY=
http_proxy=
ALL_PROXY=
all_proxy=
代理源大家自行获取,推荐electron-ssr工具
二、提交patch
2.1 提交修改
首先add自己修改后的文件:
git add 修改的文件
然后添加commit信息:
/* -s:自动在commit中添加Signed-off-by行 */
git commit -s
linux社区对commit信息的格式有严格要求,具体参考Documentation/process/submitting-patches.rst文档,大致如下:
module name: fix some bugs
why and how
Signed-off-by: Name <xxx@gmail.com>
补丁的第一行是标题,首先是模块名称,可使用git log查看所修改文件以前的提交记录,举例如下:
git log drivers/base/bus.c
输出:
commit a4723041857eaa35f189d237da769c4c63235544
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Mon Oct 29 16:31:26 2018 +0100
driver core: drop use of BUS_ATTR()
We are trying to get rid of BUS_ATTR() so drop the last user of it from
the tree. We had to "open code" it in order to prevent a function name
conflict due to the use of DEVICE_ATTR_WO() earlier in the file :(
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
可见模块名称为driver core。
commit信息添加完成后保存退出,此时执行git log即可看到刚刚的提交详情。
2.2 制作补丁
使用git format-patch命令生成补丁:
/* -1表明只有一个补丁 */
git format-patch -s -1
生成文件如下:
0001-module-name-fix-some-bugs.patch
使用内核自带的脚本对补丁进行检查:
./scripts/checkpatch.pl 0001-module-name-fix-some-bugs.patch
输出:
total: 0 errors, 0 warnings, 78 lines checked
00001-module-name-fix-some-bugs.patch has no obvious style problems and is ready for submission.
如有errors或者warnings则需要根据提示进行修复,如果没有,则说明该补丁可以准备提交。
2.3 提交补丁
首先需要知道补丁应该发给谁,MAINTAINERS文件中有写,但一般不全,内核中也提供了相应的脚本进行获取:
./scripts/get_maintainer.pl 0001-module-name-fix-some-bugs.patch
输出:
Greg Kroah-Hartman <gregkh@linuxfoundation.org> (supporter:DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS)
"Rafael J. Wysocki" <rafael@kernel.org> (reviewer:DRIVER CORE, KOBJECTS, DEBUGFS AND SYSFS)
Jonathan Corbet <corbet@lwn.net> (maintainer:DOCUMENTATION)
linux-doc@vger.kernel.org (open list:DOCUMENTATION)
linux-kernel@vger.kernel.org (open list)
前三行即是需要发送的人员,后面两个linux-开头的邮箱地址抄送即可;使用git send-email命令进行发送:
git send-email 0001-module-name-fix-some-bugs.patch \
--to gregkh@linuxfoundation.org,rafael@kernel.org,corbet@lwn.net \
--cc linux-doc@vger.kernel.org,linux-kernel@vger.kernel.org
执行上述命令发现会有如下报错:
Unable to initialize SMTP properly. Check config and use --smtp-debug. VALUES: server=smtp.gmail.com encryption=tls hello=localhost.localdomain port=587 at /usr/lib/git-core/git-send-email line 1558.
原因是此处是使用的gmail邮箱,需要采用代理才可进行操作:
proxychains4 git send-email 0001-module-name-fix-some-bugs.patch \
--to gregkh@linuxfoundation.org,rafael@kernel.org,corbet@lwn.net \
--cc linux-doc@vger.kernel.org,linux-kernel@vger.kernel.org
最终提示如下则说明发送成功:
OK. Log says:
此外,还会自动抄送到自己的发送邮箱,可以检查是否成功收到了补丁文件。实际试了一下,如果命令中不主动添加,好像不会自动抄送,需要自己添加自己的邮箱地址
最后,安静等待Maintainer的回复与合并即可