vrijdag 12 mei 2017

Waking up Linux from suspend mode

To see wake-up sources on Linux, use acpitool -w:

acpitool -w

   Device S-state  Status   Sysfs node
  1. UAR1  S3 *disabled
  2. RP01  S4 *disabled  pci:0000:00:1c.0
  3. PXSX  S4 *disabled
  4. RP02  S4 *disabled

[cut for brevity]

  16. RP08  S4 *disabled  pci:0000:00:1c.7
  17. PXSX  S4 *disabled  pci:0000:0e:00.0
  18. GLAN  S4 *enabled   pci:0000:00:19.0
  19. EHC1  S3 *enabled   pci:0000:00:1d.0
  20. EHC2  S3 *enabled   pci:0000:00:1a.0
  21. XHC  S4 *enabled   pci:0000:00:14.0
  22. HDEF  S4 *disabled  pci:0000:00:1b.0
  23. TPD4  S4 *disabled
  24. TPD7  S0 *disabled
  25. TPD8  S0 *disabled
  26. PEG0  S4 *disabled  pci:0000:00:01.0
  27. PEGP  S4 *disabled  pci:0000:01:00.0
  28. PEGA  S4 *disabled
  29. PEG1  S4 *disabled
  30. PEG2  S4 *disabled
  31. LID0  S3 *enabled   platform:PNP0C0D:00
  32. PBTN  S3 *enabled   platform:PNP0C0C:00

To modify:

 sudo acpitool -W 18


18. GLAN  S4 *disabled  pci:0000:00:19.0

Or use the raw kernel API:

cat /proc/acpi/wakeup
echo GLAN | sudo tee /proc/acpi/wakeup
cat /proc/acpi/wakeup

donderdag 6 april 2017

Linux shell script to fix LibreOffice 5.1's docx "unknown error" word/document.xml issues

I investigated some issues that caused LibreOffice version to error out when opening certain docx files created with Microsoft Office.

Here's the error:

File format error found at # SAXParseException: '[word/document.xml line 2]: unknown error', Stream 'word/document.xml', Line 2, Column 928831(row,col).

After a deep debugging session, it turns out this is caused by some values of the relativeHeight attributes in the word/document.xml file of the docx.

I made a script to workaround the relativeHeight issue by setting all relativeHeight attributes to zero which, according to the docx specification, means infinite.

After fixing this, I ran into another problem where LibreOffice would sometimes duplicate the w:themeColor attribute upon saving in docx format, thereby invalidating the XML. That is also checked and fixed by the code below.

I figured other people might find this useful, so here's my script:

# Fix to workaround LibreOffice 5 docx issues
# Copyleft 2017 (c) Tom Van Braeckel <tomvanbraeckel@gmail.com>

# This fixes these errors I've been getting:

# File format error found at 
# SAXParseException: '[word/document.xml line 2]: unknown error', Stream 'word/document.xml', Line 2, Column 928831(row,col).
# Problematic LibreOffice version:
# --------------------------------
# Version:
# Build ID: 1:5.1.6~rc2-0ubuntu1~xenial1
# CPU Threads: 4; OS Version: Linux 4.11; UI Render: default; 
# Locale: en-US (en_US.UTF-8); Calc: group

if [ -z "$tofix" ]; then
echo "Usage: $0 <filetofix>"
echo "Example: $0 bla.dockx"
exit 1
tofixreal=$(readlink -f "$tofix")

tempdir=$(mktemp -d)
cd "$tempdir"

unzip "$tofixreal"

# Fix relativeHeight issue
sed -i "s/relativeHeight=\"[^\"]\+\"/relativeHeight=\"0\"/g" word/document.xml
# and then after saving in LibreOffice 5.2 docx format, we sometimes need this fix:
sed -i 's/w:themeColor="text1" w:themeColor="text1"/w:themeColor="text1"/g' word/document.xml

zip -r "$tofixreal" *

cd "$cwd"

echo "Done! The file $tofixreal has been cleaned from relativeHeight and themeColor issues."

To use this script, make sure it is executable and do:

./fixdocx.sh filename.dockx