Monday, December 2, 2013

Using `strace` as a quick debugging tool.

The software SNAPP was throwing the error:

Failed to load dbi driver, please check db and/or dbi settings

In order to track down what was missing strace was used.  

By running the command with strace:

# strace snapp-collector -c /usr/local/etc/snapp_config.xml --foreground

The following was output:

execve("/usr/local/sbin/snapp-collector", ["snapp-collector", "-c", "/usr/local/etc/snapp_config.xml", "--foreground"], [/* 20 vars */]) = 0
brk(0)                                  = 0x1e5e000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2c9ca12000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=63119, ...}) = 0
mmap(NULL, 63119, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f2c9ca02000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/libsnmp.so.15", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\27\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=620224, ...}) = 0
mmap(NULL, 2929152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2c9c526000
mprotect(0x7f2c9c5bb000, 2093056, PROT_NONE) = 0
.......
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fca66878000
mprotect(0x7fca66878000, 4096, PROT_NONE) = 0
clone(child_stack=0x7fca668b7e30, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fca668b89d0, tls=0x7fca668b8700, child_tidptr=0x7fca668b89d0) = 58461
openat(AT_FDCWD, "/usr/lib/dbd", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
futex(0x7fca6c229a68, FUTEX_WAKE_PRIVATE, 2147483647) = 0
stat("/usr/local/etc/snapp_config.xml", {st_mode=S_IFREG|0644, st_size=210, ...}) = 0
stat("/usr/local/etc/snapp_config.xml", {st_mode=S_IFREG|0644, st_size=210, ...}) = 0
stat("/usr/local/etc/snapp_config.xml", {st_mode=S_IFREG|0644, st_size=210, ...}) = 0
open("/usr/local/etc/snapp_config.xml", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=210, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fca66877000
read(3, "SNAPP"..., 16384) = 210
read(3, "", 12288)                      = 0
lseek(3, 0, SEEK_CUR)                   = 210
close(3)                                = 0
munmap(0x7fca66877000, 4096)            = 0
write(2, "Failed to load dbi driver, pleas"..., 63Failed to load dbi driver, please check db and/or dbi settings
) = 63
tgkill(58447, 58461, SIGRTMIN)          = 0
tgkill(58447, 58449, SIGRTMIN)          = 0
tgkill(58447, 58450, SIGRTMIN)          = 0
tgkill(58447, 58451, SIGRTMIN)          = 0
tgkill(58447, 58452, SIGRTMIN)          = 0
.....


To find the error look around the output for the error: "Failed to load dbi driver....", then look above that line until something looks like the obvious problem.   In this example, we know that dbi failed to load.   Looking up a few lines we find the error:

openat(AT_FDCWD, "/usr/lib/dbd", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

Checking to see if this file exists:

ls -al /usr/lib/dbd
ls: cannot access /usr/lib/dbd: No such file or directory 

It does not.

Install the proper file:

apt-get install libdbd-mysql 

Run the program again and it works:

snapp-collector -c /usr/local/etc/snapp_config.xml --foreground
SNAPP-collector (version 3.0.7 (svn 9662)) started
collection_classes loaded=0, collections_loaded=0
config loaded
Snapp initialization complete 


No comments:

Post a Comment

Followers