Skip to content

Commit 6ddd6aa

Browse files
author
hongqi.gan
committed
fix: 修复setuid可能面临的其他错误,并给出警告
1 parent 31ed7e0 commit 6ddd6aa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/commands/pack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ exports.run = function (options) {
4848
while (1) {
4949
switch (_context.prev = _context.next) {
5050
case 0:
51+
// http://man7.org/linux/man-pages/man2/setuid.2.html
52+
// 以sudo身份执行的时候,会自动设置此环境变量
5153
if (process.env['SUDO_UID']) {
52-
process.setuid(parseInt(process.env['SUDO_UID']));
54+
try {
55+
process.setuid(parseInt(process.env['SUDO_UID']));
56+
} catch (e) {
57+
// 这里catch error,处理系统不支持意外,以后权限的问题
58+
logWarn('\u8BBE\u7F6Euid\u4E3A' + process.env['SUDO_UID'] + '\u53D1\u751F\u4E86\u95EE\u9898\u3002\u5982\u679C\u4E0D\u5F71\u54CD\u6700\u7EC8\u7684pack\u7ED3\u679C\uFF0C\u8BF7\u5FFD\u7565\u3002');
59+
logWarn(e);
60+
}
5361
}
5462

5563
if ((0, _keys2.default)(config.entry).length === 0) {

src/commands/pack.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ exports.run = function (options) {
4646
start.bind(this.project)().catch(console.log.bind(console));
4747

4848
async function start() {
49+
// http://man7.org/linux/man-pages/man2/setuid.2.html
50+
// 以sudo身份执行的时候,会自动设置此环境变量
4951
if (process.env['SUDO_UID']) {
50-
process.setuid(parseInt(process.env['SUDO_UID']));
52+
try {
53+
process.setuid(parseInt(process.env['SUDO_UID']));
54+
} catch(e) {
55+
// 这里catch error,处理系统不支持意外,以后权限的问题
56+
logWarn(`设置uid为${process.env['SUDO_UID']}发生了问题。如果不影响最终的pack结果,请忽略。`);
57+
logWarn(e);
58+
}
5159
}
5260

5361
if(Object.keys(config.entry).length === 0) {

0 commit comments

Comments
 (0)