使用strace解決pacman提示無法鎖定數據庫的問題

原文地址:https://www.lujun9972.win/blog/2020/05/25/使用strace解決pacman提示無法鎖定數據庫的問題/index.html

某次滾動升級archlinux的時候忘了插電,導致滾動到一半的時候斷電了。導致插電後再升級時提示:

:: 正在同步軟件包數據庫...
錯誤:無法升級 core (無法鎖定數據庫)
錯誤:無法升級 extra (無法鎖定數據庫)
錯誤:無法升級 community (無法鎖定數據庫)
錯誤:無法升級 multilib (無法鎖定數據庫)
錯誤:無法升級 archlinuxcn (無法鎖定數據庫)
錯誤:未能成功同步所有數據庫

從錯誤提示我能推測出大概率是升級到一半斷電導致某個鎖文件未被刪除,問題是,這個鎖文件在哪呢?

還好有 strace,可以幫我找出鎖文件的路徑

sudo strace -e openat pacman -Syu --noconfirm 2>&1
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libalpm.so.12", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libarchive.so.13", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libgpgme.so.11", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libcurl.so.4", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libcrypto.so.1.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libacl.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libexpat.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/liblzma.so.5", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libzstd.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/liblz4.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libbz2.so.1.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libassuan.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libgpg-error.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libnghttp2.so.14", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libidn2.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libssh2.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libpsl.so.5", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libssl.so.1.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libgssapi_krb5.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libkrb5.so.3", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libk5crypto.so.3", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libcom_err.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libattr.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libunistring.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libkrb5support.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libkeyutils.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/pacman.conf", O_RDONLY) = 3
openat(AT_FDCWD, "/etc/pacman.d/mirrorlist", O_RDONLY) = 4
openat(AT_FDCWD, "/etc/pacman.d/mirrorlist", O_RDONLY) = 4
openat(AT_FDCWD, "/etc/pacman.d/mirrorlist", O_RDONLY) = 4
openat(AT_FDCWD, "/etc/pacman.d/mirrorlist", O_RDONLY) = 4
openat(AT_FDCWD, "/var/lib/pacman/local/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/var/lib/pacman/local/ALPM_DB_VERSION", O_RDONLY) = 4
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/var/log/pacman.log", O_WRONLY|O_CREAT|O_APPEND|O_CLOEXEC, 0644) = 3
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/pacman.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/pacman.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/pacman.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/pacman.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
:: Synchronizing package databases...
openat(AT_FDCWD, "/var/lib/pacman/db.lck", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 000) = -1 EEXIST (File exists)
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/libalpm.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libalpm.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/libalpm.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libalpm.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
error: failed to update core (unable to lock database)
openat(AT_FDCWD, "/var/lib/pacman/db.lck", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 000) = -1 EEXIST (File exists)
error: failed to update extra (unable to lock database)
openat(AT_FDCWD, "/var/lib/pacman/db.lck", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 000) = -1 EEXIST (File exists)
error: failed to update community (unable to lock database)
openat(AT_FDCWD, "/var/lib/pacman/db.lck", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 000) = -1 EEXIST (File exists)
error: failed to update multilib (unable to lock database)
openat(AT_FDCWD, "/var/lib/pacman/db.lck", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 000) = -1 EEXIST (File exists)
error: failed to update archlinuxcn (unable to lock database)
error: failed to synchronize all databases
+++ exited with 1 +++

可以看到,在輸出 :: Synchronizing package databases... 後,pacman會去檢查 "/var/lib/pacman/db.lck" 是否存在,然後跟着提示 error: failed to update archlinuxcn (unable to lock database)

所以很容易就能推測出,鎖文件爲 /var/lib/pacman/db.lck,跟網上搜索的內容一致。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章