cron @reboot jobs race with setup of files under /sys

Bug #2043140 reported by Britton Kerin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cron (Ubuntu)
New
Undecided
Unassigned

Bug Description

It looks like @reboot cron jobs run before /sys is fully populated. This is super-unexpected and very bad,
since the desire and expectation for things in this slot is pretty much always going to be to do something
"last" in the boot process. The user will have something they've discovered they have to do and now they
want to make it automatic *exactly as if they did it manually every boot*.

The evidence of the problem:

I have the caps-lock-decreases-brightness bug and rather than deal with kernel compilation I thought I'd just fix it using a cron job and /sys/class/backlight/intel_backlight/brightness to force it high all the time. The script I wrote worked fine from command line but not when run as a root cron job at @reboot like this:

     SHELL=/bin/bash
     PATH=/usr/sbin:/usr/bin:/sbin:/bin
     @reboot /home/bkerin/.helper_scripts/brighterizer.perl

When run from cron, my script would die the first time it tried to read the
/sys/class/backlight/intel_backlight/max_brightness file. The fix turned out
to be to just wait in the script until the file shows up:

     # Max Brightness File
     my $mbf = '/sys/class/backlight/intel_backlight/max_brightness';
     # Current Brightness File
     my $cbf = '/sys/class/backlight/intel_backlight/brightness';

     # Because it looks like the contents of /sys aren't all entirely populated
     # before @reboot cron jobs run, since without these (or one or the other
     # of themn anyway) the first cat below fails when we're invoked from reboot
     # (but not otherwise).
     while ( not -r $mbf ) { sleep 0.1; }
     while ( not -r $cbf ) { sleep 0.1; }

     # Max Brightness
     my $mb = `cat $mbf`;
     $? == 0 or die;
     chomp($mb);

From this behavior I conclude that the @reboot cron job races with setup of files under /sys. For the reasons mentioned above this should be fixed.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: cron 3.0pl1-137ubuntu3
ProcVersionSignature: Ubuntu 6.2.0-36.37~22.04.1-generic 6.2.16
Uname: Linux 6.2.0-36-generic x86_64
ApportVersion: 2.20.11-0ubuntu82.5
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: ubuntu:GNOME
Date: Thu Nov 9 11:11:14 2023
InstallationDate: Installed on 2023-11-04 (5 days ago)
InstallationMedia: Ubuntu 22.04.3 LTS "Jammy Jellyfish" - Release amd64 (20230807.2)
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: cron
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Britton Kerin (britton-kerin) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.