dpgk --configure -a 挂起设置 base-files ,显然是在 systemd-tty-ask-password-agent 中

dpgk --configure -a 挂起设置 base-files ,显然是在 systemd-tty-ask-password-agent 中

dpkg --configure -a设置时挂起base-files。从目前的诊断来看,似乎dpkg --configure -a运行/var/lib/dpkg/info/base-files.postinst,运行deb-systemd-invoke start motd-news.timer,执行systemd-tty-ask-password-agent --watch,永远等待(无需在终端上输入密码)。详细诊断:

$ sudo strace -o /tmp/dpkg-strace -tt -ff dpkg --debug=222 --configure -a
Setting up base-files (11ubuntu5.4) ...
D000002: fork/exec /var/lib/dpkg/info/base-files.postinst ( configure 11ubuntu5.3 )

手动运行此postinst脚本并bash -xv在执行时挂起deb-systemd-invoke start motd-news.timer,还揭示了一些问题pstree(针对没有 strace 运行的情况):

bash───sudo───dpkg───base-files.post───systemctl───systemd-tty-ask

Strace 输出大约 10k 行。其中一个 strace 输出文件似乎与命令相对应deb-systemd-invoke start motd-news.timer,以 结尾ppoll,显然是在等待套接字。选自deb-systemd-invoke start motd-news.timer(PID 51072):

10:50:46.673278 close(10)               = 0
10:50:46.673319 execve("/usr/bin/deb-systemd-invoke", ["deb-systemd-invoke", "start", "motd-news.timer"], 0x56297d000c88 /* 37 vars */) = 0
10:50:46.673511 brk(NULL)               = 0x55fff0539000
10:50:46.673534 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd593b7540) = -1 EINVAL (Invalid argument)
10:50:46.673574 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
10:50:46.673613 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10:50:46.673641 fstat(3, {st_mode=S_IFREG|0644, st_size=160254, ...}) = 0
10:50:46.673663 mmap(NULL, 160254, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f3bdfb5e000
10:50:46.673686 close(3)                = 0
10:50:46.673713 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
[...]
10:50:46.708457 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
[...]
10:50:46.710298 sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\1\4\1\24\0\0\0\2\0\0\0\227\0\0\0\1\1o\0\31\0\0\0/org/fre"..., iov_len=168}, {iov_base="\17\0\0\0motd-news.timer\0", iov_len=20}], msg_iovlen=2, msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 188
10:50:46.710350 recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\2\1\0017\0\0\0\3\0\0\0007\0\0\0\5\1u\0\2\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = 24
10:50:46.710422 recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="\7\1s\0\30\0\0\0org.freedesktop.systemd1"..., iov_len=103}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = 103
10:50:46.710472 sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\1\4\19\0\0\0\3\0\0\0\250\0\0\0\1\1o\0002\0\0\0/org/fre"..., iov_len=184}, {iov_base="\35\0\0\0org.freedesktop.systemd1.Uni"..., iov_len=57}], msg_iovlen=2, msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 241
10:50:46.710522 recvmsg(3, {msg_namelen=0}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
10:50:46.710565 ppoll([{fd=3, events=POLLIN}], 1, {tv_sec=24, tv_nsec=999957000}, NULL, 8) = 1 ([{fd=3, revents=POLLIN}], left {tv_sec=24, tv_nsec=999940266})
10:50:46.710626 recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\2\1\1\10\0\0\0\4\0\0\0007\0\0\0\5\1u\0\3\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = 24
10:50:46.710676 recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="\7\1s\0\30\0\0\0org.freedesktop.systemd1"..., iov_len=56}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = 56
10:50:46.710745 recvmsg(3, {msg_namelen=0}, MSG_DONTWAIT|MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
10:50:46.710794 ppoll([{fd=3, events=POLLIN}], 1, NULL, NULL, 8

另一个,,systemd-tty-ask-password-agent --watch以 结尾poll,显然是在等待套接字或 inotify 事件以显示密码。51076 的选择:

10:50:46.709061 set_robust_list(0x7fb46e4f98e0, 24) = 0
10:50:46.709158 prctl(PR_SET_NAME, "(sd-askpwagent)"...) = 0
10:50:46.709242 geteuid()               = 0
10:50:46.709322 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb46e9cd000
10:50:46.709349 prctl(PR_SET_MM, PR_SET_MM_ARG_START, 0x7fb46e9cd000, 0, 0) = 0
10:50:46.709371 prctl(PR_SET_MM, PR_SET_MM_ARG_END, 0x7fb46e9cd010, 0, 0) = 0
10:50:46.709393 prctl(PR_SET_PDEATHSIG, SIGTERM) = 0
10:50:46.709416 rt_sigaction(SIGHUP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb46e808210}, NULL, 8) = 0
10:50:46.709439 rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb46e808210}, NULL, 8) = 0
10:50:46.709459 rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fb46e808210}, NULL, 8) = 0
[...]
10:50:46.711627 prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=512*1024, rlim_max=512*1024}) = 0
10:50:46.711660 prlimit64(0, RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=512*1024}, NULL) = 0
10:50:46.711690 execve("/bin/systemd-tty-ask-password-agent", ["/bin/systemd-tty-ask-password-ag"..., "--watch"], 0x7ffce60ac808 /* 37 vars */) = 0
10:50:46.711926 brk(NULL)               = 0x55abfc744000
10:50:46.711956 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe7027e8f0) = -1 EINVAL (Invalid argument)
[...]
10:50:46.722618 read(3, "", 1024)       = 0
10:50:46.722637 close(3)                = 0
10:50:46.722659 stat("/run/systemd/ask-password-block", {st_mode=S_IFDIR|0700, st_size=160, ...}) = 0
10:50:46.722683 mknod("/run/systemd/ask-password-block/136:6", S_IFIFO|0600) = -1 EEXIST (File exists)
10:50:46.722706 openat(AT_FDCWD, "/run/systemd/ask-password-block/136:6", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC) = 3
10:50:46.722728 stat("/run/systemd", {st_mode=S_IFDIR|0755, st_size=520, ...}) = 0
10:50:46.722751 mkdir("/run/systemd/ask-password", 0755) = -1 EEXIST (File exists)
10:50:46.722779 stat("/run/systemd/ask-password", {st_mode=S_IFDIR|0755, st_size=40, ...}) = 0
10:50:46.722803 rt_sigprocmask(SIG_SETMASK, [TERM], NULL, 8) = 0
10:50:46.722823 signalfd4(-1, [TERM], 8, SFD_CLOEXEC|SFD_NONBLOCK) = 4
10:50:46.722845 inotify_init1(IN_CLOEXEC) = 5
10:50:46.722865 inotify_add_watch(5, "/run/systemd/ask-password", IN_CLOSE_WRITE|IN_MOVED_TO) = 1
10:50:46.722891 openat(AT_FDCWD, "/run/systemd/ask-password", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 6
10:50:46.722913 fstat(6, {st_mode=S_IFDIR|0755, st_size=40, ...}) = 0
10:50:46.722937 getdents64(6, /* 2 entries */, 32768) = 48
10:50:46.722959 getdents64(6, /* 0 entries */, 32768) = 0
10:50:46.722977 close(6)                = 0
10:50:46.722995 poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1

主进程和脚本 base-files.postinst 似乎正在等待wait4其他进程完成:

10:50:46.017699 execve("/usr/bin/dpkg", ["dpkg", "--configure", "-a"], 0x7fffb1462800 /* 27 vars */) = 0
10:50:46.018044 brk(NULL)               = 0x5636a8783000
10:50:46.018135 arch_prctl(0x3001 /* ARCH_??? */, 0x7fffa60dac50) = -1 EINVAL (Invalid argument)
10:50:46.018208 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
10:50:46.018264 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10:50:46.018307 fstat(3, {st_mode=S_IFREG|0644, st_size=160254, ...}) = 0
10:50:46.018343 mmap(NULL, 160254, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa02ba19000
10:50:46.018377 close(3)                = 0
10:50:46.018416 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
10:50:46.018450 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@p\0\0\0\0\0\0"..., 832) = 832
[...]
10:50:46.163945 fcntl(5, F_SETFD, FD_CLOEXEC) = 0
10:50:46.164043 fstat(5, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
10:50:46.164180 write(5, "#padding\n#padding\n#padding\n#padd"..., 4096) = 4096
10:50:46.164354 write(5, "padding\n#padding\n#padding\n#paddi"..., 512) = 512
10:50:46.164486 lseek(5, 0, SEEK_SET)   = 0
10:50:46.164598 stat("/var/lib/dpkg/info/base-files.postinst", {st_mode=S_IFREG|0755, st_size=5664, ...}) = 0
10:50:46.164718 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa02b7406d0) = 51032
10:50:46.165711 rt_sigaction(SIGQUIT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa02b840210}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
10:50:46.165855 rt_sigaction(SIGINT, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7fa02b840210}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
10:50:46.166017 wait4(51032,

10:50:46.165943 set_robust_list(0x7fa02b7406e0, 24) = 0
10:50:46.166455 chdir("/")              = 0
10:50:46.166748 execve("/var/lib/dpkg/info/base-files.postinst", ["/var/lib/dpkg/info/base-files.po"..., "configure", "11ubuntu5.3"], 0x5636a87c4840 /* 36 vars */) = 0
10:50:46.168230 brk(NULL)               = 0x56297cffd000
10:50:46.168542 arch_prctl(0x3001 /* ARCH_??? */, 0x7fffc0915d90) = -1 EINVAL (Invalid argument)
10:50:46.168877 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
10:50:46.169322 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
10:50:46.169734 fstat(3, {st_mode=S_IFREG|0644, st_size=160254, ...}) = 0
10:50:46.169951 mmap(NULL, 160254, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f5c7351e000
10:50:46.170127 close(3)                = 0
[...]
10:50:46.673001 close(1)                = 0
10:50:46.673018 fcntl(11, F_SETFD, FD_CLOEXEC) = 0
10:50:46.673035 dup2(3, 1)              = 1
10:50:46.673051 close(3)                = 0
10:50:46.673068 stat("/usr/local/sbin/deb-systemd-invoke", 0x7fffc09159a0) = -1 ENOENT (No such file or directory)
10:50:46.673093 stat("/usr/local/bin/deb-systemd-invoke", 0x7fffc09159a0) = -1 ENOENT (No such file or directory)
10:50:46.673113 stat("/usr/sbin/deb-systemd-invoke", 0x7fffc09159a0) = -1 ENOENT (No such file or directory)
10:50:46.673132 stat("/usr/bin/deb-systemd-invoke", {st_mode=S_IFREG|0755, st_size=4430, ...}) = 0
10:50:46.673156 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5c7351d850) = 51072
10:50:46.673267 wait4(-1,

大多数其他内容以“+++ exited with 0 +++”结尾,或者我没有看到任何可疑内容。

看起来似乎deb-systemd-invoke start motd-news.timerdeb-systemd-invoke start motd-news.timer永远都在等待密码,但用户界面上看不到任何请求。根据这篇博文,重新启动应该可以解决这个问题:

当 systemd-tty-ask 或 /bin/systemd-tty-ask-password-agent –watch 在软件包安装、服务启动或停止操作期间挂起时,这相当烦人。

虽然重新启动系统可以解决问题,但幸运的是,只需重新启动 systemd 管理器就足够了:

sudo systemctl daemon-reexec

我怀疑这是一个 systemd 错误,因为 daemon-reexec 除了通过重新读取配置重新启动守护进程之外没有执行任何特殊操作。

但是,执行sudo systemctl daemon-reexec或重启系统都无法解决问题。问了这个问题之后,我才发现这个密切相关的问题但那里没有提出令人满意的解决方案(我愿意相信不需要重新安装系统)。

这好像是launchpad 上的这个错误与此有关,可能直接导致了这个问题

我该如何摆脱这种困境dpkg --configure -abase-files除了重新安装系统之外,还有其他已知的解决方法吗?

答案1

这似乎最终是由于 systemd 中的一个错误,因为在此处的启动板上报告。该错误导致systemctl start ...在运行时挂起systemd-tty-ask-password-agent。一些安装后脚本会运行systemctl start(或者更确切地说是它的同类脚本deb-systemd-invoke start),但我不知道为什么这会在某些系统上挂起,而在另一些系统上不会。

通过编辑并取消注释行 ,可以dpkg --configure -a完成(或者说保持不完整)。完成此操作后,将通过安装后脚本。但是,这不是令人满意的解决方案。首先,不在安装后脚本中启动服务可能会对系统产生副作用。其次,在下一个 中,在另一个安装后脚本(在本例中)中挂起,因此可能必须为相当多的软件包配置解决方法,每种情况下都有待确定的副作用。/var/lib/dpkg/base-files.postinstdeb-systemd-invoke start 'motd-news.timer' >/dev/null || truedpkg --configure -abase-filesapt upgradedpkgapt.postinst

在对启动板错误的评论中提出的替代方案(运行)systemctl start --no-ask-password对我的情况没有任何影响。

相关内容