Xsessions has_option code error with fix

Bug #1995236 reported by Peter D.
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
xorg (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

Jammy Jellyfish 22.04.1 LTS and others. There have been numerous bug reports and failed fixes for this over several years and releases.

There are a couple of problems in /etc/X11/Xsessions where it fails to handle options, causing bogus error messages and, doubtless, many errors.

The first bug is that the entire options file, including comments, is read into a variable.

Where the variable "OPTIONS" is assigned;

Replacing "cat" with "grep" strips out comments and blank lines;

$ diff Xsession Xsession.orig
65c65
< grep -v "^\s*\#\|^\s*$" "$OPTIONFILE"
---
> cat "$OPTIONFILE"

The second problem is that checking for a non-existent directory inside a command substitution does not work. It just appends garbage onto the output string.

That is probably a bug in BASH, but I defer to your opinion there.

The immediate work around is to create an empty directory so that the test does not fail. Better still, force the creation of the directory and remove the test.

eg. change this;

OPTIONS="$(
  if [ -r "$OPTIONFILE" ]; then
    cat "$OPTIONFILE"
  fi
  if [ -d /etc/X11/Xsession.options.d ]; then
    run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat
  fi
)"

to this;

OPTIONSDIR=/etc/X11/Xsession.options.d
mkdir --parents ${OPTIONSDIR}
OPTIONS="$(
  if [ -r "$OPTIONFILE" ]; then
    grep -v "^\s*\#\|^\s*$" "$OPTIONFILE"
  fi
  run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat
)"

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: xorg 1:7.7+23ubuntu2
ProcVersionSignature: Ubuntu 5.15.0-52.58-generic 5.15.60
Uname: Linux 5.15.0-52-generic x86_64
.tmp.unity_support_test.0:

ApportVersion: 2.20.11-0ubuntu82.1
Architecture: amd64
BootLog: Error: [Errno 13] Permission denied: '/var/log/boot.log'
CasperMD5CheckResult: pass
CompositorRunning: None
CurrentDesktop: XFCE
Date: Mon Oct 31 16:33:14 2022
DistUpgraded: Fresh install
DistroCodename: jammy
DistroVariant: ubuntu
DkmsStatus:
 virtualbox/6.1.38, 5.15.0-362206031516-generic, x86_64: installed
 virtualbox/6.1.38, 5.15.0-52-generic, x86_64: installed
ExtraDebuggingInterest: Yes
GraphicsCard:
 Advanced Micro Devices, Inc. [AMD/ATI] Raven Ridge [Radeon Vega Series / Radeon Vega Mobile Series] [1002:15dd] (rev c8) (prog-if 00 [VGA controller])
   Subsystem: Advanced Micro Devices, Inc. [AMD/ATI] Raven Ridge [Radeon Vega Series / Radeon Vega Mobile Series] [1002:15dd]
InstallationDate: Installed on 2022-10-20 (11 days ago)
InstallationMedia: Kubuntu 22.04.1 LTS "Jammy Jellyfish" - Release amd64 (20220809.1)
MachineType: Micro-Star International Co., Ltd. MS-7B89
ProcKernelCmdLine: ro root=PARTUUID=1c70e394-574c-46cc-a65e-a402f0e077d4 fbcon=rotate:2 initrd=\initrd.img
SourcePackage: xorg
Symptom: display
UpgradeStatus: No upgrade log present (probably fresh install)
dmi.bios.date: 02/01/2021
dmi.bios.release: 5.17
dmi.bios.vendor: American Megatrends International, LLC.
dmi.bios.version: 2.C0
dmi.board.asset.tag: To be filled by O.E.M.
dmi.board.name: B450M MORTAR MAX (MS-7B89)
dmi.board.vendor: Micro-Star International Co., Ltd.
dmi.board.version: 1.0
dmi.chassis.asset.tag: To be filled by O.E.M.
dmi.chassis.type: 3
dmi.chassis.vendor: Micro-Star International Co., Ltd.
dmi.chassis.version: 1.0
dmi.modalias: dmi:bvnAmericanMegatrendsInternational,LLC.:bvr2.C0:bd02/01/2021:br5.17:svnMicro-StarInternationalCo.,Ltd.:pnMS-7B89:pvr1.0:rvnMicro-StarInternationalCo.,Ltd.:rnB450MMORTARMAX(MS-7B89):rvr1.0:cvnMicro-StarInternationalCo.,Ltd.:ct3:cvr1.0:skuTobefilledbyO.E.M.:
dmi.product.family: To be filled by O.E.M.
dmi.product.name: MS-7B89
dmi.product.sku: To be filled by O.E.M.
dmi.product.version: 1.0
dmi.sys.vendor: Micro-Star International Co., Ltd.
version.compiz: compiz 1:0.9.14.1+22.04.20220820-0ubuntu1
version.libdrm2: libdrm2 2.4.110-1ubuntu1
version.libgl1-mesa-dri: libgl1-mesa-dri 22.0.5-0ubuntu0.1
version.libgl1-mesa-glx: libgl1-mesa-glx 22.0.5-0ubuntu0.1
version.xserver-xorg-core: xserver-xorg-core 2:21.1.3-2ubuntu2.2
version.xserver-xorg-input-evdev: xserver-xorg-input-evdev N/A
version.xserver-xorg-video-ati: xserver-xorg-video-ati 1:19.1.0-2ubuntu1
version.xserver-xorg-video-intel: xserver-xorg-video-intel 2:2.99.917+git20210115-1
version.xserver-xorg-video-nouveau: xserver-xorg-video-nouveau 1:1.0.17-2build1

Revision history for this message
Peter D. (0123peter) wrote :
Revision history for this message
Peter D. (0123peter) wrote :

Bother. There is a third problem, a scope issue of some sort.
The errors in ~/.xsession.error go away if "has_options" is moved from Xsession to its own file in Xsession.d

I don't see why sourceing it should make any difference, but it does.

$ cat /etc/X11/Xsession.d/00
has_option () {
  # Ensure that a later no-foo overrides an earlier foo
  if [ "$(echo "$OPTIONS" | grep -Eo "^(no-)?$1\>" | tail -n 1)" == "$1" ]; then
    return 0
  else
    return 1
  fi
}

Also I changed a "=" to "==", but that should be cosmetic.

Revision history for this message
Peter D. (0123peter) wrote :

And now OPTIONS has to be exported,
and probably should be protected against being empty in the new file. So it becomes ${OPTIONS:-} and ${1:-}

What else have I missed?

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Bug 1922414 covers one of the issues with has_option so please reword this bug to cover one other issue only.

Changed in xorg (Ubuntu):
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for xorg (Ubuntu) because there has been no activity for 60 days.]

Changed in xorg (Ubuntu):
status: Incomplete → Expired
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.