Skip to content

Commit 730c1bc

Browse files
committed
add PRByMail
1 parent 014fe5a commit 730c1bc

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

source/_posts/trueblog/PRbyMail.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: 古老的基础设施:使用邮件提交补丁
3+
date: 2024/11/23 09:22:00
4+
updated: 2024/11/23 23:10:00
5+
tags:
6+
- not-ctf
7+
- debuginfod
8+
thumbnail: /assets/trueblog/debuginfod.png
9+
excerpt: 最近Arch上的debuginfod更新了,也带来了bug...还好只是shell脚本的错误,还在我的能力范畴之内。花了一段时间如何通过邮件向上游提交补丁,最终解决了这个bug。
10+
---
11+
12+
<!-- 在网鼎杯上,手机被收了,离比赛开始还有好久,无聊到写博客了 -->
13+
14+
## 修复
15+
16+
最近Arch上的debuginfod更新了,也带来了bug...在启动shell时会显示无匹配错误:
17+
`/etc/profile.d/debuginfod.sh:14: no matches found: /etc/debuginfod/*.certpath`
18+
于是我就找这个文件看
19+
20+
```sh
21+
# $HOME/.profile* or similar files may first set $DEBUGINFOD_URLS.
22+
# If $DEBUGINFOD_URLS is not set there, we set it from system *.url files.
23+
# $HOME/.*rc or similar files may then amend $DEBUGINFOD_URLS.
24+
# See also [man debuginfod-client-config] for other environment variables
25+
# such as $DEBUGINFOD_MAXSIZE, $DEBUGINFOD_MAXTIME, $DEBUGINFOD_PROGRESS.
26+
27+
prefix="/usr"
28+
if [ -z "$DEBUGINFOD_URLS" ]; then
29+
DEBUGINFOD_URLS=$(cat /dev/null "/etc/debuginfod"/*.urls 2>/dev/null | tr '\n' ' ' || :)
30+
[ -n "$DEBUGINFOD_URLS" ] && export DEBUGINFOD_URLS || unset DEBUGINFOD_URLS
31+
fi
32+
33+
if [ -z "$DEBUGINFOD_IMA_CERT_PATH" ]; then
34+
DEBUGINFOD_IMA_CERT_PATH=$(cat /dev/null "/etc/debuginfod"/*.certpath 2>/dev/null | tr '\n' ':' || :)
35+
[ -n "$DEBUGINFOD_IMA_CERT_PATH" ] && export DEBUGINFOD_IMA_CERT_PATH || unset DEBUGINFOD_IMA_CERT_PATH
36+
fi
37+
unset prefix
38+
```
39+
40+
{% notel blue fa-book bash与zsh对于glob的处理 %}
41+
对于bash来说当匹配不到字符串时,会保留原字符串,例如`*.nothing -> '*.nothing'`
42+
而这个字符串接着传到`cat`中,由于不存在这个文件,会输出错误,紧接着错误被丢弃,
43+
因此对于bash来说,这段代码能够正常运行。
44+
45+
然而,zsh视无法匹配的glob为错误,并终止当前命令,因此会打印出zsh的错误,
46+
这里不是cat的错误。
47+
{% endnotel %}
48+
49+
一开始想着这不是加个shebang的事?加上以后发现无济于事。`profile.d`...?
50+
经过查找,这个文件是被`source`加载的,并不是直接运行,因此只能是由当前shell运行脚本。
51+
继续调查,`/etc/debuginfod/`下没有其他文件夹,因此可以使用`find`来匹配文件并运行。
52+
`cat /dev/null "/etc/debuginfod"/*.urls 2>/dev/null | tr '\n' ' ' || :`修改为:
53+
`find "/etc/debuginfod" -name "*.urls" -print0 2>/dev/null | xargs -0 cat 2>/dev/null | tr '\n' ' ' || :`
54+
55+
{% note blue fa-info %}
56+
`|| :`中的`:`不做任何事。`find`缺省使用空格分隔文件名,`-print0`可以让`xargs`分清带有空格的文件名。
57+
{% endnote %}
58+
59+
## PATCH IT
60+
61+
知道怎么修之后,就可以向上游发送补丁了。但是 **elfutils** 属于一个
62+
*project run by Unix bros who want the 90s back*,他们不使用GitHub或是Gitlab等现代化设施接受PR,
63+
而是使用`git send-email`,通过邮件的方式发送补丁。类似的,Linux同样使用这个方式来接受补丁。
64+
65+
为了发送补丁,首先需要拉取上游:`git clone git://sourceware.org/git/elfutils.git`
66+
然后对文件做出修改后commit。再用`git format-patch origin/main`生成一个邮件patch,
67+
最后使用`git send-email 0001-${COMMIT}.patch`发送邮件。
68+
69+
还可以提前配置发送对象,这样就不用每次都在发送时输入一遍。
70+
71+
```ini .git/config
72+
[sendemail]
73+
74+
suppresscc = self # prevent cc to myself
75+
confirm = always
76+
```
77+
78+
## SEND IT
79+
80+
一切准备就绪,接下去就是发送邮件了。我平时使用outlook邮箱,但是微软不再允许使用简单认证登录,
81+
换言之,不能使用密码或是应用密码登录,必须使用OAuth2的方式登录。然而,
82+
git并没有内建OAuth2支持。因此,无法使用outlook邮箱。奇怪的是,用gmail同样不行。
83+
看起来git自带的send-email写的一坨,可用性存在问题。于是我看到[可以用msmtp](https://jade.fyi/blog/oh-no-git-send-email/)
84+
85+
{% note purple fa-circle-arrow-right %}
86+
要调试git-send-email需要使用参数`--smtp-debug=1`,只有`--smtp-debug`不起效
87+
{% endnote %}
88+
89+
我看到博客里一般用gmail,因为gmail的应用密码没有微软那样的校验,可以直接登录,
90+
于是配置好msmtp后,再把git配置一下就可以发送邮件了。
91+
92+
```properties .msmtprc
93+
account default
94+
host smtp.gmail.com
95+
port 587
96+
auth on
97+
tls on
98+
tls_starttls on
99+
logfile ~/.msmtp.log
100+
```
101+
102+
```ini .git/config
103+
[sendemail]
104+
smtpserver = /usr/bin/msmtp
105+
smtpserveroption = -a
106+
smtpserveroption = default
107+
```
108+
109+
{% note green fa-info %}
110+
可以在gmail网页端中找到应用密码的申请入口
111+
{% endnote %}
112+
113+
## ACCEPTED
114+
115+
过了几天后,我的patch顺利被合入到主线了。
116+
117+
![accepted](/assets/trueblog/patchAccepted.png)
118+
119+
又过了几天,我看到debuginfod的包更新了,于是我在arch包的gitlab帖子中看到有人反映这个bug,
120+
然后打包者发现了我的patch,做了一个cherry-pick,把bug修了。
121+
[帖子](https://gitlab.archlinux.org/archlinux/packaging/packages/elfutils/-/issues/2)里我还看到了fedora的bugzilla引用,
122+
感觉这个patch帮助了不少人呢。
123+
124+
![update](/assets/trueblog/pkgupdate.png)
125+
126+
<img src="/assets/trueblog/cherry-pick.png" height="80%" width="80%">
127+
128+
## outlook: more than OAuth2
129+
130+
原本我还是想使用outlook邮箱的,因为我看到了`oama`等工具能使用OAuth2认证。
131+
然而,看了一系列类似的工具,无不需要`client_id``client_secret`这样的客户端认证信息
132+
(是认证客户端,不是认证用户)。但这个认证信息,需要自己到微软企业端申请,
133+
虽然账户可以免费注册,但是需要登记一张visa信用卡,之后才能申请邮箱客户端认证。
134+
然后我并没有visa信用卡,只好作罢。
135+
136+
这些工具还说可以找开源客户端的认证信息,但是我并没有找到...在自己的电脑上装了KMail,
137+
也成功发出了邮件,看来KMail是配置了认证信息,不过我并不知道从哪里获取它的认证信息,
138+
并且也KMail不能作为邮件代理,用来发送git的邮件。
139+
140+
## 参考
141+
142+
1. [[PATCH] config: fix globing error for zsh](https://sourceware.org/pipermail/elfutils-devel/2024q4/007580.html)
143+
2. [/etc/profile.d/debuginfod.sh causes spurious output on interactive login for non-bash shells](https://gitlab.archlinux.org/archlinux/packaging/packages/elfutils/-/issues/2)
144+
3. [Bug 32314 - Profile script in elfutils-debuginfod-client throws error on login](https://sourceware.org/bugzilla/show_bug.cgi?id=32314)
145+
4. [Bug 2321818 - Profile script in elfutils-debuginfod-client throws error on login](https://bugzilla.redhat.com/show_bug.cgi?id=2321818)
170 KB
Loading

source/assets/trueblog/debuginfod.png

33.8 KB
Loading
144 KB
Loading

source/assets/trueblog/pkgupdate.png

51.7 KB
Loading

0 commit comments

Comments
 (0)