Bookmark this page

Guided Exercise: Debugging Application Execution

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.

  1. Log in to servera and switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Run the program command.

    It displays an error message that the application cannot load its configuration file.

    [root@servera ~]# program
    Unable to load configuration file.
  3. View the /var/log/messages file for recent errors.

    No relevant errors are expected.

    [root@servera ~]# tail -n 5 /var/log/messages
    Oct 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 -> done
  4. Run the strace command to display the system calls from the program application.

    The program tries to open the /etc/program.conf file 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 +++
  5. For comparison, run the ltrace command to display the library calls from the application.

    The output displays similar information to the strace command in the form of C library calls.

    [root@servera ~]# ltrace program
    fopen("/etc/program.conf", "r")                                                    = nil
    puts("Unable to load configuration fil"...Unable to load configuration file.
    )                                                                                  = 35
    exit(1 <no return ...>
    +++ exited (status 1) +++
  6. Create the /etc/program.conf file.

    [root@servera ~]# touch /etc/program.conf
  7. Run the program command again.

    The command runs successfully and returns a zero exit status.

    [root@servera ~]# program
    Program successfully executed.
    [root@servera ~]# echo $?
    0
  8. View the output of the strace and ltrace commands when the /etc/program.conf file is present but the read permissions are removed from the program executable.

    1. Change the permissions of the program executable 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/program
    2. Exit the root shell and run the strace program command as the student user.

      The strace command indicates that the application uses the openat system call, but does not print the name of the file.

      [root@servera ~]# exit
      logout
      [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 +++
    3. Run the ltrace program command. A "permission denied" error is expected, because the ltrace command requires read access to the executable file.

      [student@servera ~]$ ltrace program
      Can't open /usr/bin/program: Permission denied
  9. Return to workstation as the student user.

    [student@servera ~]$ exit
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish application-debugging

Revision: rh342-8.4-6dd89bd