Skip to content

Enable core dumps on Raspbian

Erik Baauw edited this page Dec 15, 2020 · 11 revisions

In the rare case that deCONZ crashes, a core dump file will help in analysing the cause. Unfortunately, Raspbian has disabled core dumps by default. This page explains how to enable them.

1. Create /etc/security/limits.d/core.conf

$ sudo -i
# cat > /etc/security/limits.d/core.conf <<+++
root       hard        core        unlimited
root       soft        core        unlimited
*          hard        core        unlimited
*	   soft        core        unlimited
+++

2. Edit /etc/systemd/system.conf

Change the line

#DefaultLimitCORE=

to

DefaultLimitCORE=infinity

3. Create /etc/sysctl.d/core.conf

# cat > /etc/sysctl.d/core.conf <<+++
kernel.core_pattern = /var/lib/coredumps/core-%e-sig%s-user%u-group%g-pid%p-time%t
kernel.core_uses_pid = 1
fs.suid_dumpable = 2
+++

4. Create /var/lib/coredumps

# mkdir /var/lib/coredumps
# chmod 1777 /var/lib/coredumps
# ls -ld /var/lib/coredumps
drwxrwxrwt 2 root root 4096 Sep 23 15:39 /var/lib/coredumps/

5. Reboot

# shutdown -r now

6. Check ulimit

$ ulimit -c
unlimited

7. Test

Find out the process ID of the deCONZ service:

$ sudo systemctl status deconz-gui
● deconz-gui.service - deCONZ: ZigBee gateway -- GUI/REST API
   Loaded: loaded (/lib/systemd/system/deconz-gui.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/deconz-gui.service.d
           └─override.conf
   Active: active (running) since Sun 2018-09-23 16:28:11 CEST; 19s ago
 Main PID: 17835 (deCONZ)
   CGroup: /system.slice/deconz-gui.service
           ├─17835 /usr/bin/deCONZ --http-port=80 --dbg-info=2 --dbg-aps=2 --dbg-error=1
           ├─17858 dbus-launch --autolaunch 36338e1dca924dbd9a2413fc1346afd5 --binary-syntax --close-stderr
           └─17859 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
[...]

Notice the Main PID, 17835 in this example. Send an abort (signal 6) to the deCONZ service using the main PID:

$ sudo kill -6 17835

Check that the service stops and that a core dump file is created:

$ sudo systemctl status deconz-gui
● deconz-gui.service - deCONZ: ZigBee gateway -- GUI/REST API
   Loaded: loaded (/lib/systemd/system/deconz-gui.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/deconz-gui.service.d
           └─override.conf
   Active: deactivating (stop-sigterm) (Result: core-dump) since Sun 2018-09-23 16:30:59 CEST; 2s ago
  Process: 17835 ExecStart=/usr/bin/deCONZ $DECONZ_OPTS (code=dumped, signal=ABRT)
 Main PID: 17835 (code=dumped, signal=ABRT)
   CGroup: /system.slice/deconz-gui.service
           └─17858 dbus-launch --autolaunch 36338e1dca924dbd9a2413fc1346afd5 --binary-syntax --close-stderr

[...]
$ ls -l /var/lib/coredumps/
total 18064
drwxrwxrwt  2 root root      4096 Sep 23 16:30 ./
drwxr-xr-x 45 root root      4096 Apr 25 19:18 ../
-rw-------  1 pi   pi   121974784 Sep 23 16:30 core-deCONZ-sig6-user1000-group1000-pid17835-time1537713059

Before sending or attaching a core dump file, please compress it:

$ gzip /var/lib/coredumps/core-deCONZ-sig6-user1000-group1000-pid17835-time1537713059 
$ ls -l /var/lib/coredumps/
total 2360
drwxrwxrwt  2 root root    4096 Sep 23 16:36 ./
drwxr-xr-x 45 root root    4096 Apr 25 19:18 ../
-rw-------  1 pi   pi   2407701 Sep 23 16:30 core-deCONZ-sig6-user1000-group1000-pid17835-time1537713059.gz

8. Obtaining a Stack Trace

To obtain a stack trace, run gdb and issue the bt command at the (gdb) prompt:

$ gdb /usr/bin/deCONZ /var/lib/coredumps/core-deCONZ-sig6-user1000-group1000-pid17835-time1537713059
...
(gdb) bt
...
Clone this wiki locally