討論有關於「pkexec」和「PATH」 #25
-
討論有關於「pkexec」和「PATH」緣起我也有遇到在另一個「Issue」描述的狀況。 三不五時就會跳出如下圖的對話框。
探索環境
/usr/share/polkit-1/actions/com.lingmo.brightness.pkexec.policy執行下面指令 cat /usr/share/polkit-1/actions/com.lingmo.brightness.pkexec.policy 顯示 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="com.lingmo.brightness.pkexec">
<message>Authentication is required to Change Brightness</message>
<icon_name>battery</icon_name>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/lingmo-screen-brightness</annotate>
</action>
</policyconfig>
測試「pkexec」執行下面指令,就會出現上面那個圖的對話框。 pkexec lingmo-screen-brightness --set 100
於是改執行下面指令,就會如預期正常運作 pkexec /usr/bin/lingmo-screen-brightness --set 100 pkexec /usr/bin/lingmo-screen-brightness --set 90
lingmo-core/settings-daemon/brightness/brightnessmanager.cpp我有稍微找了一下實作的程式碼,找到如下 程式碼片段: lingmo-core/settings-daemon/brightness/brightnessmanager.cpp process.start("pkexec", QStringList() << "lingmo-screen-brightness" << "--set" << QString::number(value));
測試「PATH」執行下面指令 echo $PATH 顯示
執行下面指令 file /bin 顯示
執行 which lingmo-screen-brightness 顯示
執行 which ls 顯示
以上的測試,就可以了解到為何會發生上面提到的狀況 執行下面指令 pkexec lingmo-screen-brightness --set 100 就會出先一個對話框,提示訊息如下
關於「Debian」原本的「PATH」設定找了一下「Debian」原本的「PATH」設定 可以找到「/etc/profile」開頭其中有一段「程式碼片段」如下 if [ "$(id -u)" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH 在「Debian」執行下面指令 echo $PATH 顯示
關於「Lingmo」目前的「PATH」設定在「Lingmo」執行下面指令 echo $PATH 顯示
# Append "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
append_path () {
case ":$PATH:" in
*:"$1":*)
;;
*)
PATH="${PATH:+$PATH:}$1"
esac
}
# Append our default paths
append_path '/usr/local/sbin'
append_path '/usr/local/bin'
append_path '/usr/bin'
# Force PATH to be environment
export PATH
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -r "$profile" && . "$profile"
done
unset profile
fi
# Unload our profile API functions
unset -f append_path
echo "start: ${PATH}" > /tmp/log.txt
# Append our default paths
append_path '/usr/local/sbin'
append_path '/usr/local/bin'
append_path '/usr/bin'
echo "end: ${PATH}" >> /tmp/log.txt 重新開機後,執行下面指令, cat /tmp/log.txt 觀看「
echo "start: ${PATH}" > /tmp/log.txt
# Init PATH
PATH=""
echo "init: ${PATH}" >> /tmp/log.txt
# Append our default paths
append_path '/usr/local/bin'
append_path '/usr/local/sbin'
append_path '/usr/bin'
append_path '/bin'
echo "end: ${PATH}" >> /tmp/log.txt 重新開機後,執行下面指令, cat /tmp/log.txt 觀看「
另外也修改了一個「prepend」的版本,程式碼片段如下。 # Prepend "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
prepend_path () {
case ":$PATH:" in
*:"$1":*)
;;
*)
PATH="$1${PATH:+:$PATH}"
esac
}
# Init PATH
PATH=""
# Prepend our default paths
prepend_path '/bin'
prepend_path '/usr/bin'
prepend_path '/usr/local/sbin'
prepend_path '/usr/local/bin'
# Force PATH to be environment
export PATH
# Unload our profile API functions
unset -f prepend_path
建議
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
最开始我还不信他跟profile有关,查了一大堆文件(甚至对比原cutefish的brightness模块,polkit rule,etc.)最后发现确实是PATH的问题( 以下为正常的Debian 13的PATH: root@f6cfc8cc7b01:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@f6cfc8cc7b01:/# (Arch Linux的PATH里甚至没有 事实证明, |
Beta Was this translation helpful? Give feedback.
-
Fixed in LingmoOS/lingmo-core#18 |
Beta Was this translation helpful? Give feedback.
-
在「上面」我有提到,我做了點測試 發現到,在進入「/etc/profile」的流程前, 一開始的「 我剛剛在「探索sddm」時, 執行「sddm --example-config」後,發現到其中一個片段如下 [Users]
# Default $PATH for logged in users
DefaultPath=/bin:/usr/bin
我們可以來做個小實驗,編輯「 [Users]
# Default $PATH for logged in users
DefaultPath=/bin:/usr/bin:/opt/bin
然後我們先登出,重新登入,開啟「Terminal」,執行「 以上補充,報告完畢 |
Beta Was this translation helpful? Give feedback.
最开始我还不信他跟profile有关,查了一大堆文件(甚至对比原cutefish的brightness模块,polkit rule,etc.)最后发现确实是PATH的问题(
以下为正常的Debian 13的PATH:
(Arch Linux的PATH里甚至没有
/bin
)事实证明,
/bin
本该在后面