From 49ab01fc4be8eef199f96596b5ff45cd91dff955 Mon Sep 17 00:00:00 2001 From: alichinese Date: Fri, 24 May 2024 17:13:12 +0800 Subject: [PATCH] main: optimize root check * The source code uses getpass.getuser() to get the current user, which sometimes is not accurate. Instead, use pwd.getpwuid(os.getuid())[0] to get the current user Signed-off-by: alichinese --- src/oebuild/app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oebuild/app/main.py b/src/oebuild/app/main.py index c9b0364..4a5f941 100644 --- a/src/oebuild/app/main.py +++ b/src/oebuild/app/main.py @@ -13,7 +13,7 @@ import os import sys import pathlib from collections import OrderedDict -import getpass +import pwd import oebuild.util as oebuild_util import oebuild.const as oebuild_const @@ -168,7 +168,7 @@ def check_user(): ''' check execute user must in normal user ''' - if getpass.getuser() == "root": + if pwd.getpwuid(os.getuid())[0] == "root": logger.error("can not use oebuild in root") return False return True -- Gitee