From nobody Mon Dec 04 17:46:24 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SkWM31xJsz53c2p for ; Mon, 4 Dec 2023 17:46:55 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Received: from sdaoden.eu (sdaoden.eu [217.144.132.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4SkWM26Nfcz3KGR for ; Mon, 4 Dec 2023 17:46:54 +0000 (UTC) (envelope-from steffen@sdaoden.eu) Authentication-Results: mx1.freebsd.org; none Date: Mon, 04 Dec 2023 18:46:24 +0100 Author: Steffen Nurpmeso From: Steffen Nurpmeso To: "Dr. Amr Osman" Cc: freebsd-hackers@freebsd.org Subject: Re: devd lid close event Message-ID: <20231204174624.ZCilZWAd@steffen%sdaoden.eu> In-Reply-To: References: User-Agent: s-nail v14.9.24-573-g7d89a8210a OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD; url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15987, ipnet:217.144.128.0/20, country:DE] X-Rspamd-Queue-Id: 4SkWM26Nfcz3KGR List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org Dr. Amr Osman wrote in : |Hello, |I have freeBSD 14 on Thinkpad x270, |I just did do a fresh install and installed dwm and slock |the issue is I want to make laptop lock screen whenever I close the lid | |here is my /usr/local/etc/devd/lid.conf |``` |notify 10 { | match "system" "ACPI"; | match "subsystem" "Lid"; | match "notify" "0x00"; | action "/usr/local/bin/slock"; |}; | |``` |here is my /var/run/devd.pipe when I close the lid | |``` |!system=ACPI subsystem=Lid type=\_SB_.LID_ notify=0x00 !system=ACPI |subsystem=Lid type=\_SB_.LID_ notify=0x00 !system=ACPI |subsystem=Suspend type=\ notify=0x03 !system=IFNET subsystem=wlan0 |type=LINK_DOWN |``` | |what am I doing wrong? At minimum slock needs the $DISPLAY to connect to, eg :0. devd does not run within the X session, so no chance. Also the above runs slock as root, not the user who actually owns the X display. For the very same use case, on linux, i use if command -v X >/dev/null 2>&1 && command -v slock >/dev/null 2>&1; then had_z= for p in $(pgrep X); do ^ use pgrep to find all X instances uid=$(awk '/^Uid:/{print $2}' < /proc/$p/status) disp=$(sed -Ee 's/^.*DISPLAY=:([[:digit:]]+).*$/\1/' < /proc/$p/environ) [ -z "$disp" ] && disp=$(xargs -0 printf '%s\n' < /proc/$p/cmdline | awk '/^:[[:digit:]]+/{sub(":", ""); print}') ^ unfortunately non-portable approach to find out user id and actual display of _this_ X instance if [ -z "$disp" ]; then [ -n "$had_z" ] && continue had_z=y disp=0 elif [ $disp = 0 ]; then [ -n "$had_z" ] && continue had_z=y fi act "DISPLAY=:$disp $SUPER -u $uid slock /dev/null 2>&1 &" ^ and here we lock that display for the given user. $SUPER is doas(1) in this case, but was sudo(1) in the past (and could be super(1) like ~20 years ago if that could be find anywhere on the internet). done fi |Thank You |Dr. Amr Osman Ciao. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt) | | Only in December: lightful Dubai COP28 Narendra Modi quote: | A small part of humanity has ruthlessly exploited nature. | But the entire humanity is bearing the cost of it, | especially the inhabitants of the Global South. | The selfishness of a few will lead the world into darkness, | not just for themselves but for the entire world.