[PATCH] invalid "-K" value cause smem ended with IndexError exception
I do "smem -w -K a.txt -R 2048M" and got following error:
zhichyu@w-shpd-zcyu:~/sftw4ubuntu$ smem-0.1/smem -w -K a.txt -R 2048M
size: 'a.txt': No such file
Traceback (most recent call last):
File "smem-0.1/smem", line 607, in <module>
showsystem()
File "smem-0.1/smem", line 361, in showsystem
k = kernelsize()
File "smem-0.1/smem", line 77, in kernelsize
d = os.popen("size %s" % options.kernel).readlines()[1]
IndexError: list index out of range
The root cause is that os.popen("size a.txt") returns only one line.
If the user provides an invalid kernel image file path, I think it's
better to assume the image size is zero than raise an exception.
This commit is contained in:
parent
4865bf2967
commit
04b9f552f4
1 changed files with 5 additions and 2 deletions
7
smem
7
smem
|
|
@ -83,8 +83,11 @@ _kernelsize = 0
|
|||
def kernelsize():
|
||||
global _kernelsize
|
||||
if not _kernelsize and options.kernel:
|
||||
d = os.popen("size %s" % options.kernel).readlines()[1]
|
||||
_kernelsize = int(d.split()[3]) / 1024
|
||||
try:
|
||||
d = os.popen("size %s" % options.kernel).readlines()[1]
|
||||
_kernelsize = int(d.split()[3]) / 1024
|
||||
except:
|
||||
pass
|
||||
return _kernelsize
|
||||
|
||||
def pidmaps(pid):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue