summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-12-16 19:22:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-12-16 19:22:00 +0100
commit687be490d8092842f9a016132a4204023d9b8d6e (patch)
treef1953ad62401710566487ed7f490f39a08effca6
parent716a4ffceeb0c47d24cb00a186fd7c7e3f40992f (diff)
downloadabrt-687be490d8092842f9a016132a4204023d9b8d6e.tar.gz
abrt-687be490d8092842f9a016132a4204023d9b8d6e.tar.xz
abrt-687be490d8092842f9a016132a4204023d9b8d6e.zip
src/Hooks/CCpp.cpp: use and honour %c (core limit size).
Makes MakeCompatCore = yes much more frielndly - now users with ulimit -c 0 won't get unwanted coredumps. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--lib/Plugins/CCpp.cpp2
-rw-r--r--src/Hooks/CCpp.cpp171
2 files changed, 99 insertions, 74 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 15b47072..99c1c770 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -37,7 +37,7 @@
using namespace std;
#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern"
-#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u"
+#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u %c"
#define FILENAME_COREDUMP "coredump"
#define FILENAME_BACKTRACE "backtrace"
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index e38c4f75..7a348e5d 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -194,19 +194,26 @@ int main(int argc, char** argv)
struct stat sb;
const char* program_name = argv[0];
- if (argc < 4)
+ if (argc < 5)
{
- error_msg_and_die("Usage: %s: <dddir> <pid> <signal> <uid>", program_name);
+ error_msg_and_die("Usage: %s: DUMPDIR PID SIGNO UID CORE_SIZE_LIMIT", program_name);
}
openlog("abrt", 0, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
+ errno = 0;
const char* dddir = argv[1];
pid_t pid = xatoi_u(argv[2]);
const char* signal_str = argv[3];
int signal_no = xatoi_u(argv[3]);
uid_t uid = xatoi_u(argv[4]);
+ off_t ulimit_c = strtoull(argv[5], NULL, 10);
+ off_t core_size = 0;
+ if (errno || pid <= 0 || ulimit_c < 0)
+ {
+ error_msg_and_die("pid '%s' or limit '%s' is bogus", argv[2], argv[5]);
+ }
if (signal_no != SIGQUIT
&& signal_no != SIGILL
&& signal_no != SIGABRT
@@ -216,10 +223,6 @@ int main(int argc, char** argv)
/* not an error, exit silently */
return 0;
}
- if (pid <= 0)
- {
- error_msg_and_die("pid '%s' is bogus", argv[2]);
- }
char *user_pwd = get_cwd(pid); /* may be NULL on error */
@@ -248,6 +251,65 @@ int main(int argc, char** argv)
(int)pid, executable);
}
+ /* Parse abrt.conf and plugins/CCpp.conf */
+ unsigned setting_MaxCrashReportsSize = 0;
+ bool setting_MakeCompatCore = false;
+ bool abrt_conf = true;
+ FILE *fp = fopen(CONF_DIR"/abrt.conf", "r");
+ if (fp)
+ {
+ char line[256];
+ while (1)
+ {
+ if (fgets(line, sizeof(line), fp) == NULL)
+ {
+ /* Next .conf file plz */
+ if (abrt_conf)
+ {
+ abrt_conf = false;
+ fp = fopen(CONF_DIR"/plugins/CCpp.conf", "r");
+ if (fp)
+ continue;
+ }
+ break;
+ }
+
+ unsigned len = strlen(line);
+ if (len > 0 && line[len-1] == '\n')
+ line[--len] = '\0';
+ const char *p = skip_whitespace(line);
+#undef DIRECTIVE
+#define DIRECTIVE "MaxCrashReportsSize"
+ if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)
+ {
+ p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
+ if (*p != '=')
+ continue;
+ p = skip_whitespace(p + 1);
+ if (isdigit(*p))
+ /* x1.25: go a bit up, so that usual in-daemon trimming
+ * kicks in first, and we don't "fight" with it. */
+ setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4;
+ continue;
+ }
+#undef DIRECTIVE
+#define DIRECTIVE "MakeCompatCore"
+ if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)
+ {
+ p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
+ if (*p != '=')
+ continue;
+ p = skip_whitespace(p + 1);
+ setting_MakeCompatCore = string_to_bool(p);
+ continue;
+ }
+#undef DIRECTIVE
+ /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */
+ }
+ fclose(fp);
+ }
+
+
char path[PATH_MAX];
/* Check /var/cache/abrt/last-ccpp marker, do not dump repeated crashes
@@ -268,7 +330,12 @@ int main(int argc, char** argv)
{
path[sz] = '\0';
if (strcmp(executable, path) == 0)
- error_msg_and_die("not dumping repeating crash in '%s'", executable);
+ {
+ error_msg("not dumping repeating crash in '%s'", executable);
+ if (setting_MakeCompatCore)
+ goto create_user_core;
+ return 1;
+ }
}
lseek(fd, 0, SEEK_SET);
}
@@ -287,15 +354,15 @@ int main(int argc, char** argv)
*/
snprintf(path, sizeof(path), "%s/abrtd-coredump", dddir);
core_fd = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- off_t size = copyfd_eof(STDIN_FILENO, core_fd);
- if (size < 0 || close(core_fd) != 0)
+ core_size = copyfd_eof(STDIN_FILENO, core_fd);
+ if (core_size < 0 || close(core_fd) != 0)
{
unlink(path);
/* copyfd_eof logs the error including errno string,
* but it does not log file name */
error_msg_and_die("error saving coredump to %s", path);
}
- log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)size);
+ log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)core_size);
return 0;
}
@@ -326,8 +393,8 @@ int main(int argc, char** argv)
dd.Close();
perror_msg_and_die("can't open '%s'", path);
}
- off_t size = copyfd_eof(STDIN_FILENO, core_fd);
- if (size < 0 || fsync(core_fd) != 0)
+ core_size = copyfd_eof(STDIN_FILENO, core_fd);
+ if (core_size < 0 || fsync(core_fd) != 0)
{
unlink(path);
dd.Delete();
@@ -338,7 +405,7 @@ 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);
+ log("saved core dump of pid %u (%s) to %s (%llu bytes)", (int)pid, executable, path, (long long)core_size);
free(executable);
free(cmdline);
path[len] = '\0'; /* path now contains directory name */
@@ -351,64 +418,6 @@ int main(int argc, char** argv)
*/
dd.Close();
- /* Parse abrt.conf and plugins/CCpp.conf */
- unsigned setting_MaxCrashReportsSize = 0;
- bool setting_MakeCompatCore = false;
- bool abrt_conf = true;
- FILE *fp = fopen(CONF_DIR"/abrt.conf", "r");
- if (fp)
- {
- char line[256];
- while (1)
- {
- if (fgets(line, sizeof(line), fp) == NULL)
- {
- /* Next .conf file plz */
- if (abrt_conf)
- {
- abrt_conf = false;
- fp = fopen(CONF_DIR"/plugins/CCpp.conf", "r");
- if (fp)
- continue;
- }
- break;
- }
-
- unsigned len = strlen(line);
- if (len > 0 && line[len-1] == '\n')
- line[--len] = '\0';
- const char *p = skip_whitespace(line);
-#undef DIRECTIVE
-#define DIRECTIVE "MaxCrashReportsSize"
- if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)
- {
- p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
- if (*p != '=')
- continue;
- p = skip_whitespace(p + 1);
- if (isdigit(*p))
- /* x1.25: go a bit up, so that usual in-daemon trimming
- * kicks in first, and we don't "fight" with it. */
- setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4;
- continue;
- }
-#undef DIRECTIVE
-#define DIRECTIVE "MakeCompatCore"
- if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)
- {
- p = skip_whitespace(p + sizeof(DIRECTIVE)-1);
- if (*p != '=')
- continue;
- p = skip_whitespace(p + 1);
- setting_MakeCompatCore = string_to_bool(p);
- continue;
- }
-#undef DIRECTIVE
- /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */
- }
- fclose(fp);
- }
-
/* rhbz#539551: "abrt going crazy when crashing process is respawned".
* Do we want to protect against or ameliorate this? How? Ideas:
* (1) nice ourself?
@@ -448,7 +457,12 @@ int main(int argc, char** argv)
error_msg_and_die("%s", e.what());
}
+
create_user_core:
+ /* note: core_size may be == 0 ("unknown") */
+ if (core_size > ulimit_c || ulimit_c == 0)
+ return 0;
+
/* Write a core file for user */
struct passwd* pw = getpwuid(uid);
@@ -521,8 +535,10 @@ int main(int argc, char** argv)
perror_msg_and_die("%s/%s is not a regular file with link count 1", user_pwd, core_basename);
}
+ /* Note: we do not copy more than ulimit_c */
+ off_t size;
if (ftruncate(usercore_fd, 0) != 0
- || copyfd_eof(core_fd, usercore_fd) < 0
+ || (size = copyfd_size(core_fd, usercore_fd, ulimit_c)) < 0
|| close(usercore_fd) != 0
) {
/* perror first, otherwise unlink may trash errno */
@@ -530,7 +546,16 @@ int main(int argc, char** argv)
unlink(core_basename);
return 1;
}
- log("saved core dump of pid %u to %s/%s", (int)pid, user_pwd, core_basename);
+ if (size == ulimit_c && size != core_size)
+ {
+ /* We copied exactly ulimit_c bytes (and it doesn't accidentally match
+ * core_size (imagine exactly 1MB coredump with "ulimit -c 1M" - that'd be ok)),
+ * it means that core is larger than ulimit_c. Abort and delete the dump.
+ */
+ unlink(core_basename);
+ return 1;
+ }
+ log("saved core dump of pid %u to %s/%s (%llu bytes)", (int)pid, user_pwd, core_basename, (long long)size);
return 0;
}