Reply
Thread Tools
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#1
Hope I'm not being too silly here, but I have a little problem that's got me flummoxed.

I'm writing a startup script to handle setting up the swap devices (which I plan on packaging up and uploading to extras-devel), and as part of that, it looks for the compcache kernel module. Works fine when I test, but fails when I run it during boot.

PHP Code:
whoami
ls 
-la /lib/modules
stat 
/lib/modules/current
stat $compcache_module 
Give...
PHP Code:
root
drwxr
-xr-x    4 root     root           376 Nov 19 12:09 .
drwxr-xr-x   10 root     root          8096 Jul  1 20:58 ..
drwxr-xr-x    3 root     root          7664 May 22  2011 2.6.28-omap1
drwxr
-xr-x    2 root     root         20936 Nov 19 12:09 2.6.28.10-power49
lrwxrwxrwx    1 root     root            17 Nov 19 12
:09 current -> 2.6.28.10-power49
  File
'/lib/modules/current' -> '2.6.28.10-power49'
  
Size17              Blocks0          IO Block4096   symbolic link
Device
fe01h/65025d    Inode1681667     Links1
Access
: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access2011-11-19 12:09:10.000000000
Modify
2011-11-19 12:09:10.000000000
Change
2011-11-19 12:09:10.000000000

  File
: /lib/modules/current/ramzswap.ko
  Size
22280           Blocks48         IO Block4096   regular file
Device
fe01h/65025d    Inode1681513     Links1
Access
: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access2011-11-19 12:09:00.000000000
Modify
2011-11-18 22:04:17.000000000
Change
2011-11-19 12:09:04.000000000 
...but later in the script when I use:
PHP Code:
compcache_module=/lib/modules/current/ramzswap.ko
...
if [ -
e $compcache_module 
I get "line 72: /lib/modules/current/ramzswap.ko: Permission denied"

...any ideas?

[edit]
I'm going to change it to just use the output of stat...but I don't like unsolved mysteries...

Last edited by mr_jrt; 2011-11-27 at 22:32.
 

The Following User Says Thank You to mr_jrt For This Useful Post:
Posts: 560 | Thanked: 422 times | Joined on Mar 2011
#2
Are there conditions 'user' can do things that 'root' cannot? Sorry can't be more helpful.

How did you get all those colours in your terminal? I want...
 
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#3
Nothing wrong with your configuration I would say.

The error message indicates you try to execute the module. Are you sure it is line 72 that contains the if statement?

Attaching the script may help in a further analysis...
 
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#4
Originally Posted by demolition View Post
Are there conditions 'user' can do things that 'root' cannot? Sorry can't be more helpful.

How did you get all those colours in your terminal? I want...
Those colours are just the forum's php code tags, sorry. ...you can play with your ~/.bashrc file though

I test as both root and user, so that's not it. All very annoying. Probably in use or something, but I wouldn't have though if [ -e ] would fail like that....
 

The Following User Says Thank You to mr_jrt For This Useful Post:
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#5
Originally Posted by ade View Post
Nothing wrong with your configuration I would say.

The error message indicates you try to execute the module. Are you sure it is line 72 that contains the if statement?

Attaching the script may help in a further analysis...
It's not line 72, that's the end of the conditional on line 53, so I'm happy enough taking that as it. Here's the script (but I've removed 8 lines of commented out debug gumph, so line numbers are now reported at line 64, but I think it's line 45.
PHP Code:
  1 #!/bin/sh
  
2
  3 
# Debugging
  
if [ true ]
  
5 then
  6         rm 
/ramtest.log
  7         exec  
&> /ramtest.log
  8 fi
  9
 10 
# Tuning
 
11 compcache_size=65536  # Size of cache in KB
 
12 priority_compcache=15
 13 priority_external
=10
 14 priority_internal
=0
 15 compcache_timeout
=10  # Timeout for device node to be ready in seconds
 
16
 17 
# Constants
 
18 compcache_module=/lib/modules/current/ramzswap.ko
 19 device_internal
=mmcblk0
 20 device_external
=mmcblk1
 21 device_compcache
=ramzswap0
 22
 23 whoami
 24 ls 
-la /lib/modules
 25 stat 
/lib/modules/current
 26 stat $compcache_module
 27
 28 
# Calculated
 
29 swapdrivelist_internal=$(sfdisk -lnd grep Id=82 awk "/$device_internal/ {print \$1}")
 
30 swapdrivelist_external=$(sfdisk -lnd grep Id=82 awk "/$device_external/ {print \$1}")
 
31 if [ -"$(swapon 2>&1 | grep "\-p")" ]
 
32 then
 33         priority_available
=true
 34 fi
 35
 36 
# If priority support is available, use it
 
37 if [ $priority_available ]
 
38 then
 39         priority_compcache
="-p $priority_compcache "
 
40         priority_external="-p $priority_external "
 
41         priority_internal="-p $priority_internal "
 
42 fi
 43
 44 
# Compcache first - we want stuff to get bumped here.
 
45 if [ -e $compcache_module ]
 
46 then
 47         
if [ $priority_available ]
 
48         then
 49                 priority
=$priority_compcache
 50         fi
 51
 52         compcache_succeeded
=insmod $compcache_module disksize_kb=$compcache_size
 53         
if [ $compcache_succeeded ]
 
54         then
 55                 start_wait
=$(date +%s)
 
56                 while [ ! -/dev/$device_compcache -$(($(date +%s) - $start_wait)) -lt $compcache_timeout ]
 
57                 do
 
58                         printf "Waiting %ds for compcache to be ready... " $(($compcache_timeout - ($(date +%s) - $start_wait)))
 
59                 done
 60                 
echo
 
61                 swapon $priority/dev/$device_compcache
 62                 
exit
 
63         fi
 64 fi
 65
 66 
# Turn on SD swap first
 
67 for swapdrive in $swapdrivelist_external
 68 
do
 
69         if [ $priority_available ]
 
70         then
 71                 priority
=$priority_external
 72         fi
 73         swapon $priority$swapdrive
 74 done
 75
 76 
# If we have at least one other type of swap, diable the internal swap temporarily
 
77 if [ "$compcache_succeeded--"$swapdrivelist_sd]
 
78 then
 79         
# Turn off the internal swap to bump things into our preferred locations
 
80         for swapdrive in $swapdrivelist_internal
 81         
do
 
82                 swapoff $swapdrive
 83         done
 84
 85         
# Turn on internal swap again just in case
 
86         for swapdrive in $swapdrivelist_internal
 87         
do
 
88                 if [ $priority_available ]
 
89                 then
 90                         priority
=$priority_internal
 91                 fi
 92                 swapon $priority$swapdrive
 93         done
 94 fi 
...oh, and my bad, seems it does give the same error when run normally as boot. Interesting...been toggling bits of it on and off and made a mistake it seems. Still shouldn't fail there though I think...
 
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#6
...nope, ignore me. The error is actually coming from the insmod on line 52. I'm not too experienced with shell scripting, and silly me, I thought I'd get the error code from the line with the error, not the end of the outermost block.
 
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#7
Originally Posted by mr_jrt View Post
...nope, ignore me. The error is actually coming from the insmod on line 52. I'm not too experienced with shell scripting, and silly me, I thought I'd get the error code from the line with the error, not the end of the outermost block.
That was what I was going to say: you assign the the execution of a command (insmod) to variable. Place it between quotes if you want to assign the text of the insmod.
 

The Following User Says Thank You to ade For This Useful Post:
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#8
Originally Posted by ade View Post
That was what I was going to say: you assign the the execution of a command (insmod) to variable. Place it between quotes if you want to assign the text of the insmod.
...and the answer is:
PHP Code:
insmod $compcache_module disksize_kb=$compcache_size
compcache_succeeded
=$? 
...I guess you can't grab the exit status directly with assignment. That's another one for today's list of something new learnt.
 
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#9
Originally Posted by mr_jrt View Post
...and the answer is:
PHP Code:
insmod $compcache_module disksize_kb=$compcache_size
compcache_succeeded
=$? 
...I guess you can't grab the exit status directly with assignment. That's another one for today's list of something new learnt.
What you want to do now is okay and also common practice.

One line would mean
insmod $compcache_module disksize_kb=$compcache_size && echo success

Last edited by ade; 2011-11-27 at 23:39.
 

The Following User Says Thank You to ade For This Useful Post:
peterleinchen's Avatar
Posts: 4,118 | Thanked: 8,901 times | Joined on Aug 2010 @ Ruhrgebiet, Germany
#10
One line command with direct assignment should work also, like this:
Code:
compcache_succeeded=`insmod $compcache_module disksize_kb=$compcache_size]`
But there are almost always more than one way in scripting language ...

Last edited by peterleinchen; 2011-11-28 at 22:34.
 
Reply


 
Forum Jump


All times are GMT. The time now is 00:02.