Skip to content

Commit 2c4dbb4

Browse files
committed
Only keep the latest 10 core dumps and remove the rest
1 parent dd22bb5 commit 2c4dbb4

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

bin/kano-feedback-coredump

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,49 @@
22

33
# kano-feedback-coredump
44
#
5-
# Copyright (C) 2014, 2015 Kano Computing Ltd.
6-
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
7-
#
8-
# This script is called everytime a program segfaults
9-
# It is setup via sysctl kernel.core_pattern by using a pipe symbol
5+
# Copyright (C) 2014-2019 Kano Computing Ltd.
6+
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
107
#
8+
# This script is called everytime a program segfaults and runs with sudo.
9+
# It is setup via sysctl kernel.core_pattern by using a pipe symbol.
10+
1111

1212
procname=$1
1313
killsig=$2
1414
uid=$3
1515
gid=$4
1616
unixtime=$5
1717

18+
latest=10
1819
core_dump_dir="/var/tmp"
1920
core_dump_file="$core_dump_dir/core-$procname-$killsig-$uid-$gid-$unixtime.dump"
2021

22+
2123
function save_core_dump()
2224
{
23-
# save the coredump coming through stdin to a gzipped file
24-
cat < /dev/stdin | gzip -c - > $1.gz
25+
# Path to the core.dump file to save as a .gz archive.
26+
core_dump_file=$1
27+
28+
# Save the coredump coming through stdin to a gzipped file.
29+
cat < /dev/stdin | gzip -c - > $core_dump_file.gz
2530
}
2631

2732
function remove_old_dumps()
2833
{
29-
# remove core dump files older than 5 days
30-
find $core_dump_dir/* -mtime +5 -exec rm {} \;
34+
# Directory where core dumps are to be trimmed from.
35+
core_dump_dir=$1
36+
# Number of latest core dumps to keep.
37+
latest_count=$2
38+
39+
# Only keep the latest coredumps and delete all older ones.
40+
find $core_dump_dir -maxdepth 1 -name "*.dump*" -type f -printf "%Ts\t$core_dump_dir/%P\n" | \
41+
sort --numeric-sort | \
42+
head --lines -$latest_count | \
43+
cut --fields 2- | \
44+
xargs rm -rf
3145
}
3246

47+
3348
save_core_dump $core_dump_file
34-
remove_old_dumps
49+
remove_old_dumps $core_dump_dir $latest
3550
exit 0

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
kano-feedback (4.3.3-0) unstable; urgency=low
2+
3+
* Keep only the latest 10 core dumps on the system
4+
5+
-- Team Kano <dev@kano.me> Wed, 23 Oct 2019 14:38:00 +0100
6+
17
kano-feedback (4.3.2-0) unstable; urgency=low
28

39
* Prevent users without parental consent from sending PII in text inputs

0 commit comments

Comments
 (0)