Category Archives: Uncategorized
Awesome rant
I am a long time user of Awesome WM as my window manager. However we had a major version bump (3.5 -> 4.1) from the ports today and my configuration disintegrated like a mellowcake that just found itself teleported into the twenty-fourth dimension. This is a recurring problem with this window manager, their API is as much stable as a node.js developer under influence on St Patrick’s day. Now if you are using the default configuration you’ll be fine. But if your configuration is heavily customized, man, you are in for a ride!
Thankfully FreeBSD port maintainers being the good guys that they are, it is still possible to install the older version from the x11-wm/awesome3
port. This will remove x11-wm/awesome-vicious
though. But if you ever need to install lib-vicious for Awesome3, I archived my own version here. This also comes with patches for some widgets on FreeBSD which I have been too lazy to report (my bad).
Now I am not yet entirely sure if I will stay on Awesome3 for a while, upgrade to Awesome4 eventually, switch to i3 or xmonad. Well, we’ll see about that.
Hide logs from wheel users
If you have grown accustomed to FreeBSD administration, you’ve probably learned that users need to be member of the wheel group to be able to use the su
command. Some in the land of GNU don’t agree so much with this way of doing and firmly believe that wheel
is an instrument of power (which is true in a literal sens) but that’s another story.
In fact I am perfectly fine with this save for one little detail. By default most log files are owned by root:wheel
. Altough while some of them have permission 600, a lot of them are 640 which means that members of the wheel group will be able to read them. We have basically two solutions to fix this:
- Fix permissions in
/etc/newsyslog.conf
. - Use another group instead of
wheel
for thesu
command.
Fixing newsyslog.conf
is quite easy, just replace the mode column with any permission you fancy (in our case 600). Don’t forget to restart newsyslog
and fix existing permissions with find /var/log -type f -exec chmod 600 {} \;
.
However that might not be enough. You see on most BSD wheel
has gid 0, whereas on Linux it is root
that has gid 0. Nobody is supposed to be a member of root
, but it serves as a general purpose group for anything owned solely by root. As such you can often use chown 0:0
as a synonym of owned by root.
But root:root
on Linux would not have the same meaning as root:wheel
on BSD. In particular you can generally suppose that files owned by root:root
with permission 640 on Linux are only readable by the root user but the same supposition doesn’t translate so well for us BSD users.
While I’m not keen of importing such kind of Linuxism into FreeBSD, one way to deal with it would be to use another group for su
users. For this we would:
- Create the
su
system group. - Move all members of
wheel
to this group. - Modify
/etc/pam.d/su
to usegroup=su
instead ofgroup=wheel
.
Now I don’t personally do that, but I guess what you do it’s your business.
It ain’t rocket science
Quote
Suicide-burn is how I land people on the moon.
On the nose aerobraking is how I bring them back.
Custom user Xsession with SDDM
Debian stretch is out, a lot of obsolete packages, a lot of major upgrades, which all in all resulted in quite a painful transition the last few days. But I’ll tell you more about that in the following posts.
I don’t really spend much time on Linux nowadays so KDE (along with KDM) has always been my goto solution for a jack all trade no-BS works-out-of-the-box desktop environment. And it worked like that just fine, until… well you know how software goes. KDE has been upgraded, KDM has been depreciated and replaced with SDDM.
I also use xsession
so that I have a common way of starting session scripts and daemons (such as this one) and configuring stuff across different desktops. I generally selected custom session in the display manager and that was it. But SDDM does not seem to provide a way to do so, or at least that’s not so clear.
By default, it will execute /etc/sddm/xsession
which itself sources /etc/X11/Xsession
to which it will pass as argument the value of the Exec line in the desktop file (located in /usr/share/xsessions
) describing the currently selected session.
If we want to bypass this, we need to scrap the argument passed to /etc/X11/Xsession
no matter what SDDM thinks the current session should be. To do so create a wrapper for Xsession in /etc/X11/user-Xsession
:
#!/bin/sh export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin # Discard argument, we don't care about selecting the desktop environment. /etc/X11/Xsession
And now configure SDDM to use this instead of its own version of it, in /etc/sddm.conf
:
[X11] SessionCommand=/etc/X11/user-Xsession
MSP430 and Contiki on FreeBSD
If you were trying to compile a Contiki application that targets an MSP430 platform (T-Mote Sky for example) on FreeBSD, you might have noticed that msp430-gcc was removed from the port tree and replaced by gcc-msp430-ti-toolchain. Contiki does not support this newer toolchain so you might find yourself a bit stuck there.
Fortunately you can still access the last version of the msp430-gcc packages from the FreeBSD archives:
Time is a sorcerer, space is a clown
Quote
Why is it even so hard to reach escape velocity?
How do we fill the interstellar space between sterile worlds?
How do we cope with an ever expanding universe,
red-shifted galaxies fading away in loneliness,
while we wave our hands one last time to those billions of giants?
Suspend on lid closed + battery
If you use FreeBSD 11 on the good ol’ ThinkPad X201, you’ve probably noticed now that suspend and resume work perfectly flawlessly with the latest FreeBSD release.
You probably wish to take advantage of this and suspend your laptop automatically when the lid is closed. Nothing could be easier:
sysctl hw.acpi.lid_switch_state=S3
Save this option /etc/sysctl.conf
for it to be permanent.
Close the lid, the laptop goes to sleep, you’re done!
It’s that simple.
But, with this method it will go to sleep each time the lid is closed, completely ignoring whether the laptop is on battery or not. And if you’re like me you probably don’t want this. Instead you want it to suspend itself when the lid is closed and the laptop is on battery. Easy enough! We just have to invoke the mighty power of devd along with a very little shell script.
First we need to tell devd how to react when the lid is closed. Put this in /etc/devd/lid.conf
, then restart (service devd restart
):
# Notify lid close/open events. notify 10 { match "system" "ACPI"; match "subsystem" "Lid"; action "/etc/acpi/lid.sh $notify"; };
Now we will make a script that checks the lid and AC line states and chooses to suspend the laptop when both the lid is closed and AC line is disconnected. This goes in /etc/acpi/lid.sh
:
#!/bin/sh lid="$1" # 0x00 is closed, 0x01 is open (see devd.conf) acline=$(sysctl -n hw.acpi.acline) # 0 is battery, 1 is online (man acpi) if [ \( "$lid" = "0x00" \) -a \( "$acline" -eq 0 \) ] then logger "Lid closed on battery. Going to sleep." acpiconf -s3 fi
Try it out! Disconnect the AC line, close the lid, it should go to sleep within seconds. However if it doesn’t work you might want to modify the script above a little to check whether lid events are received correctly or not.
Now you may use a modified version of this script to lock xscreensaver when the lid is closed and before the actual suspend. Well OK, I’ve done that for you:
#!/bin/sh # XScreensaver should be called BEFORE going to sleep to avoid the desktop to be # shown for a few seconds when the system resumes from sleep. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin lid="$1" # 0x00 is closed, 0x01 is open (see devd.conf) acline=$(sysctl -n hw.acpi.acline) # 0 is battery, 1 is online (man acpi) lock_display() ( socket="$1" display=$(echo "$socket" | tr "X" ":") # Temporary pid file for the watching command tpid=$(mktemp) # Wait until the display is actually locked. (timeout 2s xscreensaver-command -display "$display" -watch & echo $! > $tpid) | ( # Issue the lock command only when we know that # the watching pipe is ready. xscreensaver-command -display "$display" -lock while read line do line=$(echo $line | cut -d' ' -f 1) if [ "$line" = LOCK ] then # We have to kill the watching command manually before breaking. kill -TERM $(cat $tpid) break fi done ) rm $tpid ) # The X server may not be running if [ ! -d /tmp/.X11-unix ] then exit 0 fi # Lock each available display for socket in $(ls /tmp/.X11-unix) do # Lock the display logger "Locking xscreensaver on $socket" lock_display $socket & done # Wait until every displays are locked wait # Now we can suspend if needed if [ \( "$lid" = "0x00" \) -a \( "$acline" -eq 0 \) ] then logger "Lid closed on battery. Going to sleep." acpiconf -s3 fi
Disk failure happens
So my not-so-trusty-anymore 5 years old HDD crashed unexpectedly this morning. That happened on my working laptop. But thank god I do backups! I still probably lost some documents but it could have been much worse.
Coincidentally I was just saying to myself that it would be a good idea to reinstall it just to force me to clean this old setup a little bit. Well that providential failure forced my hand. Thanks for that!
This also prompted me to start building a NAS, an idea that I have in my mind since quite a few months now. So you will probably read more of that in a few weeks.