summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-30 15:39:05 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-30 15:39:05 +0100
commitccffe86678210568449c6a6345ae5d6dc20ef104 (patch)
tree2972338c1eebbb8733fc7c0867f21a2dfbf18439
parent134b6f47c67e0a9aeca14d37dd73127c91932c1a (diff)
downloadabrt-ccffe86678210568449c6a6345ae5d6dc20ef104.tar.gz
abrt-ccffe86678210568449c6a6345ae5d6dc20ef104.tar.xz
abrt-ccffe86678210568449c6a6345ae5d6dc20ef104.zip
ccpp hook: reanme it, and add "crash storm protection" (see rhbz#542003)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--.gitignore2
-rw-r--r--abrt.spec2
-rw-r--r--doc/DESIGN4
-rw-r--r--lib/Plugins/Makefile.am4
-rw-r--r--src/Hooks/CCpp.cpp42
-rw-r--r--src/Hooks/Makefile.am8
6 files changed, 46 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index e76499cc..b6f190c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,6 +50,6 @@ src/Daemon/abrtd
src/Gui/abrt.desktop
src/Hooks/abrt_exception_handler.py
src/Hooks/dumpoops
-src/Hooks/hookCCpp
+src/Hooks/abrt-hook-ccpp
src/Hooks/abrt-pyhook-helper
stamp-h1
diff --git a/abrt.spec b/abrt.spec
index cdbd0b65..65cd1b33 100644
--- a/abrt.spec
+++ b/abrt.spec
@@ -311,7 +311,7 @@ fi
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}/plugins/CCpp.conf
%{_libdir}/%{name}/libCCpp.so*
-%{_libexecdir}/hookCCpp
+%{_libexecdir}/abrt-hook-ccpp
#%files plugin-firefox
#%{_libdir}/%{name}/libFirefox.so*
diff --git a/doc/DESIGN b/doc/DESIGN
index 7298b4c8..207904cc 100644
--- a/doc/DESIGN
+++ b/doc/DESIGN
@@ -53,9 +53,9 @@ which processes it according to configuration in /etc/abrt/*.conf.
In order to catch binary crashes, we install a handler for it
in /proc/sys/kernel/core_pattern (by setting it to
-"|/usr/libexec/hookCCpp /var/cache/abrt %p %s %u").
+"|/usr/libexec/abrt-hook-ccpp /var/cache/abrt %p %s %u").
When process dumps core, the dump is written into /var/cache/abrt/DIR.
-After this, hookCCpp spawns "abrt-process -d /var/cache/abrt/DIR"
+After this, abrt-hook-ccpp spawns "abrt-process -d /var/cache/abrt/DIR"
and terminates.
When python program crashes, it invokes internel python subroutine
diff --git a/lib/Plugins/Makefile.am b/lib/Plugins/Makefile.am
index 97da2204..58f1334d 100644
--- a/lib/Plugins/Makefile.am
+++ b/lib/Plugins/Makefile.am
@@ -52,7 +52,7 @@ libCCpp_la_SOURCES = CCpp.cpp CCpp.h
libCCpp_la_LDFLAGS = -avoid-version
libCCpp_la_LIBADD = $(NSS_LIBS)
libCCpp_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils \
- -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" \
+ -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
-DLOCALSTATEDIR='"$(localstatedir)"' \
$(NSS_CFLAGS)
@@ -63,7 +63,7 @@ libCCpp_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils \
#libFirefox_la_LDFLAGS = -avoid-version
#libFirefox_la_LIBADD = $(NSS_LIBS)
#libFirefox_la_CPPFLAGS = -I$(srcdir)/../../inc -I$(srcdir)/../Utils \
-# -DCCPP_HOOK_PATH=\"${libexecdir}/hookCCpp\" \
+# -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \
# -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
# -DLOCALSTATEDIR='"$(localstatedir)"' \
# $(NSS_CFLAGS)
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index 78a24711..ea616860 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -190,6 +190,9 @@ static int daemon_is_ok()
int main(int argc, char** argv)
{
+ int fd;
+ struct stat sb;
+
const char* program_name = argv[0];
if (argc < 4)
{
@@ -238,7 +241,7 @@ int main(int argc, char** argv)
{
error_msg_and_die("can't read /proc/%u/exe link", (int)pid);
}
- if (strstr(executable, "/hookCCpp"))
+ if (strstr(executable, "/abrt-hook-ccpp"))
{
error_msg_and_die("pid %u is '%s', not dumping it to avoid recursion",
(int)pid, executable);
@@ -246,12 +249,40 @@ int main(int argc, char** argv)
char path[PATH_MAX];
+ /* Check /var/cache/abrt/last-ccpp marker, do not dump repeated crashes
+ * if they happen too often. Else, write new marker value.
+ */
+ snprintf(path, sizeof(path), "%s/last-ccpp", dddir);
+ fd = open(path, O_RDWR | O_CREAT, 0666);
+ if (fd >= 0)
+ {
+ int sz;
+ fstat(fd, &sb); /* !paranoia. this can't fail. */
+
+ if (sb.st_size != 0 /* if it wasn't created by us just now... */
+ && (unsigned)(time(NULL) - sb.st_mtime) < 20 /* and is relatively new [is 20 sec ok?] */
+ ) {
+ sz = read(fd, path, sizeof(path)-1); /* (ab)using path as scratch buf */
+ if (sz > 0)
+ {
+ path[sz] = '\0';
+ if (strcmp(executable, path) == 0)
+ error_msg_and_die("not dumping repeating crash in '%s'", executable);
+ }
+ lseek(fd, 0, SEEK_SET);
+ }
+ sz = write(fd, executable, strlen(executable));
+ if (sz >= 0)
+ ftruncate(fd, sz);
+ close(fd);
+ }
+
if (strstr(executable, "/abrtd"))
{
/* If abrtd crashes, we don't want to create a _directory_,
* since that can make new copy of abrtd to process it,
* and maybe crash again...
- * On the contrary, mere files are ignored by abrtd.
+ * Unlike dirs, mere files are ignored by abrtd.
*/
snprintf(path, sizeof(path), "%s/abrtd-coredump", dddir);
core_fd = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -263,7 +294,7 @@ int main(int argc, char** argv)
* but it does not log file name */
error_msg_and_die("error saving coredump to %s", path);
}
- log("saved core dump of pid %u to %s (%llu bytes)", (int)pid, path, (long long)size);
+ log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)size);
return 0;
}
@@ -306,9 +337,9 @@ int main(int argc, char** argv)
}
lseek(core_fd, 0, SEEK_SET);
/* note: core_fd is still open, we may use it later to copy core to user's dir */
+ log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)size);
free(executable);
free(cmdline);
- log("saved core dump of pid %u to %s (%llu bytes)", (int)pid, path, (long long)size);
path[len] = '\0'; /* path now contains directory name */
/* We close dumpdir before we start catering for crash storm case.
@@ -430,7 +461,7 @@ int main(int argc, char** argv)
/* Mimic "core.PID" if requested */
char core_basename[sizeof("core.%u") + sizeof(int)*3] = "core";
char buf[] = "0\n";
- int fd = open("/proc/sys/kernel/core_uses_pid", O_RDONLY);
+ fd = open("/proc/sys/kernel/core_uses_pid", O_RDONLY);
if (fd >= 0)
{
read(fd, buf, sizeof(buf));
@@ -475,7 +506,6 @@ int main(int argc, char** argv)
/* Do not O_TRUNC: if later checks fail, we do not want to have file already modified here */
errno = 0;
int usercore_fd = open(core_basename, O_WRONLY | O_CREAT | O_NOFOLLOW, 0600); /* kernel makes 0600 too */
- struct stat sb;
if (usercore_fd < 0
|| fstat(usercore_fd, &sb) != 0
|| !S_ISREG(sb.st_mode)
diff --git a/src/Hooks/Makefile.am b/src/Hooks/Makefile.am
index c643b248..21569570 100644
--- a/src/Hooks/Makefile.am
+++ b/src/Hooks/Makefile.am
@@ -1,17 +1,17 @@
-libexec_PROGRAMS = hookCCpp
+libexec_PROGRAMS = abrt-hook-ccpp
bin_PROGRAMS = dumpoops abrt-pyhook-helper
# CCpp
-hookCCpp_SOURCES = \
+abrt_hook_ccpp_SOURCES = \
CCpp.cpp
-hookCCpp_CPPFLAGS = \
+abrt_hook_ccpp_CPPFLAGS = \
-I$(srcdir)/../../inc \
-I$(srcdir)/../../lib/Utils \
-DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
-DCONF_DIR=\"$(CONF_DIR)\" \
-DVAR_RUN=\"$(VAR_RUN)\" \
-D_GNU_SOURCE
-hookCCpp_LDADD = \
+abrt_hook_ccpp_LDADD = \
../../lib/Utils/libABRTUtils.la
# dumpoops