Red Hat Enterprise Linux Diagnostics and Troubleshooting
Troubleshoot an application with runtime problems.
Outcomes
You should be able to run ltrace and strace to diagnose runtime application issues.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start application-debugging
This command installs a custom application called program.
Instructions
A user reports that their application named program is not working. The application runs with the program command but displays an error that a configuration file is missing.
Troubleshoot the issue to discover which configuration file the program application requires.
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Run the
programcommand.It displays an error message that the application cannot load its configuration file.
[root@servera ~]#
programUnable to load configuration file.View the
/var/log/messagesfile for recent errors.No relevant errors are expected.
[root@servera ~]#
tail -n 5 /var/log/messagesOct 29 12:37:56 server NetworkManager[923]: <info> [1635525476.9586] device (eth1): state change: ip-config -> failed (reason 'ip-config-unavailable', sys-iface-state: 'managed') Oct 29 12:37:56 server NetworkManager[923]: <warn> [1635525476.9595] device (eth1): Activation: failed for connection 'Wired connection 2' Oct 29 12:37:56 server NetworkManager[923]: <info> [1635525476.9597] device (eth1): state change: failed -> disconnected (reason 'none', sys-iface-state: 'managed') Oct 29 12:37:56 server NetworkManager[923]: <info> [1635525476.9637] dhcp4 (eth1): canceled DHCP transaction Oct 29 12:37:56 server NetworkManager[923]: <info> [1635525476.9637] dhcp4 (eth1): state changed timeout -> doneRun the
stracecommand to display the system calls from theprogramapplication.The program tries to open the
/etc/program.conffile but fails because the file does not exist.[root@servera ~]#
strace program...output omitted... openat(AT_FDCWD, "/etc/program.conf", O_RDONLY) = -1 ENOENT (No such file or directory) dup(2) = 3 fcntl(3, F_GETFL) = 0x402 (flags O_RDWR|O_APPEND) fstat(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0 write(3, "Unable to load configuration fil"..., 35Unable to load configuration file.) = 35 write(3, ": No such file or directory\n", 28: No such file or directory) = 28 close(3) = 0 exit_group(1) = ? +++ exited with 1 +++For comparison, run the
ltracecommand to display the library calls from the application.The output displays similar information to the
stracecommand in the form of C library calls.[root@servera ~]#
ltrace programfopen("/etc/program.conf", "r") = nil puts("Unable to load configuration fil"...Unable to load configuration file. ) = 35 exit(1 <no return ...> +++ exited (status 1) +++Create the
/etc/program.conffile.[root@servera ~]#
touch /etc/program.confRun the
programcommand again.The command runs successfully and returns a zero exit status.
[root@servera ~]#
programProgram successfully executed. [root@servera ~]#echo $?0View the output of the
straceandltracecommands when the/etc/program.conffile is present but the read permissions are removed from theprogramexecutable.Change the permissions of the
programexecutable so that unprivileged users cannot read it.[root@servera ~]#
chmod 711 /usr/bin/program[root@servera ~]#ls -l /usr/bin/program-rwx--x--x. 1 root root 17536 Nov 1 10:57 /usr/bin/programExit the
rootshell and run thestrace programcommand as thestudentuser.The
stracecommand indicates that the application uses theopenatsystem call, but does not print the name of the file.[root@servera ~]#
exitlogout [student@servera ~]$strace program...output omitted... openat(AT_FDCWD, 0x4006fa, O_RDONLY) = 3 fstat(1, 0x7ffe2d759340) = 0 write(1, 0x1816490, 31Program successfully executed. ) = 31 exit_group(0) = ? +++ exited with 0 +++Run the
ltrace programcommand. A "permission denied" error is expected, because theltracecommand requires read access to the executable file.[student@servera ~]$
ltrace programCan't open /usr/bin/program: Permission denied
Return to
workstationas thestudentuser.[student@servera ~]$
exit[student@workstation ~]$