# [Solved] Syntax error (on boot) in a udev script

## Roman2K

Hello. I have a weird problem that I can't solve on my own, so here I am reaching out for help  :Rolling Eyes: .

I get a syntax error on boot-up, related to a udev script:

From /var/log/rc.log:

```
udev-mount      |/lib64/udev/shell-compat-KV.sh: line 23: 3 * 65536 + 1 * 256 + 0+ : syntax error: operand expected (error token is "+ ")

udev-mount      |/etc/init.d/udev-mount: line 16: [: -lt: unary operator expected

udev-mount      |/lib64/udev/shell-compat-KV.sh: line 23: 3 * 65536 + 1 * 256 + 0+ : syntax error: operand expected (error token is "+ ")

udev-mount      |/etc/init.d/udev-mount: line 24: [: -lt: unary operator expected

udev-mount      | * /dev is already mounted

udev            | * Starting udevd ...
```

(One consequence is that my custom rules in /etc/udev/rules.d aren't evaluated anymore.)

The allegedly erroneous line (23) in /lib64/udev/shell-compat-KV.sh:

```
# cat /lib64/udev/shell-compat-KV.sh

[...]

20                 local KV_MINOR=${x%%.*}

21                 x=${x#*.}

22                 local KV_MICRO=${x%%.*}

23                 local KV_int=$((${KV_MAJOR} * 65536 + ${KV_MINOR} * 256 + ${KV_MICRO} ))

24 

25                 # We make version 2.2.0 the minimum version we will handle as

26                 # a sanity check ... if its less, we fail ...

27                 [ "${KV_int}" -lt 131584 ] && return 1

[...]
```

This script is sourced within /etc/init.d/udev-mount:

```
# grep -Rn shell-compat-KV.sh /etc

/etc/init.d/udev-mount:9:. /lib64/udev/shell-compat-KV.sh
```

(Its interpreter is /sbin/runscript.)

I ran a syntax check on the udev script:

```
# bash --version

GNU bash, version 4.1.9(2)-release (x86_64-pc-linux-gnu)

# bash -n < /lib64/udev/shell-compat-KV.sh && echo OK

OK
```

It looks like the udev script is using a bash feature, calculations with $(( ... )), but the /sbin/runscript (symlink to /sbin/rc) can't understand it.

I don't know exactly when that started happening. Today, I have been switching back and forth between nouveau and nvidia drivers, and kernel v3.0.6, linux-stable v3.1.0+, nouveau/linux v3.1.0+. I also performed several emerge --update --deep --newuse @world after switching VIDEO_CARDS="nouveau" to "nvidia" and vice-versa.

Could one of the updated packages have broken runscript's delegation to bash, or something like that?

My attempt at solving the problem so far: re-emerging udev and openrc, just in case. (No difference.)

Thanks in advance.Last edited by Roman2K on Sun Nov 06, 2011 1:06 am; edited 1 time in total

----------

## Hu

It looks like KV_MICRO ended up with the value 0+ instead of straight 0.  What is the output of emerge --info when this fails?

----------

## Roman2K

 *Hu wrote:*   

> It looks like KV_MICRO ended up with the value 0+ instead of straight 0.  What is the output of emerge --info when this fails?

 

Spot on! I had just figured it out and am in the process of filing a bug report.

For the record:

```
# emerge --info

Portage 2.1.10.11 (default/linux/amd64/10.0/desktop, gcc-4.5.3, glibc-2.12.2-r0, 3.1.0+ x86_64)

=================================================================

System uname: Linux-3.1.0+-x86_64-Intel-R-_Core-TM-2_Duo_CPU_L9600_@_2.13GHz-with-gentoo-2.0.3

[...]
```

Fix in /lib64/udev/shell-compat-KV.sh:

```
--- /tmp/a   2011-11-06 01:55:56.561000021 +0100

+++ /tmp/b   2011-11-06 01:55:37.400000021 +0100

@@ -15,6 +15,11 @@

       [ -z $1 ] && return 1

 

       local x=${1%%-*}

+

+      # Development kernels may be numbered with a tailing +, for

+      # example: "3.1.0+"

+      x=${x%%+}

+

       echo "1="$1 "x="$x >> /tmp/test

       local KV_MAJOR=${x%%.*}

       x=${x#*.}
```

Thanks a lot!

EDIT: Actually, there's already a bug report. Google didn't lead me there earlier, unfortunately. #368197

----------

