aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@suse.de>2006-10-01 02:29:28 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-01 03:39:33 -0400
commitd025c9db7f31fc0554ce7fb2dfc78d35a77f3487 (patch)
tree5da0a10cbc4b1a5cd5f04d7af2df334352df3728 /fs/exec.c
parente239ca540594cff00adcce163dc332b27015d8e5 (diff)
[PATCH] Support piping into commands in /proc/sys/kernel/core_pattern
Using the infrastructure created in previous patches implement support to pipe core dumps into programs. This is done by overloading the existing core_pattern sysctl with a new syntax: |program When the first character of the pattern is a '|' the kernel will instead threat the rest of the pattern as a command to run. The core dump will be written to the standard input of that program instead of to a file. This is useful for having automatic core dump analysis without filling up disks. The program can do some simple analysis and save only a summary of the core dump. The core dump proces will run with the privileges and in the name space of the process that caused the core dump. I also increased the core pattern size to 128 bytes so that longer command lines fit. Most of the changes comes from allowing core dumps without seeks. They are fairly straight forward though. One small incompatibility is that if someone had a core pattern previously that started with '|' they will get suddenly new behaviour. I think that's unlikely to be a real problem though. Additional background: > Very nice, do you happen to have a program that can accept this kind of > input for crash dumps? I'm guessing that the embedded people will > really want this functionality. I had a cheesy demo/prototype. Basically it wrote the dump to a file again, ran gdb on it to get a backtrace and wrote the summary to a shared directory. Then there was a simple CGI script to generate a "top 10" crashes HTML listing. Unfortunately this still had the disadvantage to needing full disk space for a dump except for deleting it afterwards (in fact it was worse because over the pipe holes didn't work so if you have a holey address map it would require more space). Fortunately gdb seems to be happy to handle /proc/pid/fd/xxx input pipes as cores (at least it worked with zsh's =(cat core) syntax), so it would be likely possible to do it without temporary space with a simple wrapper that calls it in the right way. I ran out of time before doing that though. The demo prototype scripts weren't very good. If there is really interest I can dig them out (they are currently on a laptop disk on the desk with the laptop itself being in service), but I would recommend to rewrite them for any serious application of this and fix the disk space problem. Also to be really useful it should probably find a way to automatically fetch the debuginfos (I cheated and just installed them in advance). If nobody else does it I can probably do the rewrite myself again at some point. My hope at some point was that desktops would support it in their builtin crash reporters, but at least the KDE people I talked too seemed to be happy with their user space only solution. Alan sayeth: I don't believe that piping as such as neccessarily the right model, but the ability to intercept and processes core dumps from user space is asked for by many enterprise users as well. They want to know about, capture, analyse and process core dumps, often centrally and in automated form. [akpm@osdl.org: loff_t != unsigned long] Signed-off-by: Andi Kleen <ak@suse.de> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 0db3fc3c5f0f..6270f8f20a63 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -58,7 +58,7 @@
58#endif 58#endif
59 59
60int core_uses_pid; 60int core_uses_pid;
61char core_pattern[65] = "core"; 61char core_pattern[128] = "core";
62int suid_dumpable = 0; 62int suid_dumpable = 0;
63 63
64EXPORT_SYMBOL(suid_dumpable); 64EXPORT_SYMBOL(suid_dumpable);
@@ -1463,6 +1463,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1463 int retval = 0; 1463 int retval = 0;
1464 int fsuid = current->fsuid; 1464 int fsuid = current->fsuid;
1465 int flag = 0; 1465 int flag = 0;
1466 int ispipe = 0;
1466 1467
1467 binfmt = current->binfmt; 1468 binfmt = current->binfmt;
1468 if (!binfmt || !binfmt->core_dump) 1469 if (!binfmt || !binfmt->core_dump)
@@ -1504,22 +1505,34 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1504 lock_kernel(); 1505 lock_kernel();
1505 format_corename(corename, core_pattern, signr); 1506 format_corename(corename, core_pattern, signr);
1506 unlock_kernel(); 1507 unlock_kernel();
1507 file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, 0600); 1508 if (corename[0] == '|') {
1509 /* SIGPIPE can happen, but it's just never processed */
1510 if(call_usermodehelper_pipe(corename+1, NULL, NULL, &file)) {
1511 printk(KERN_INFO "Core dump to %s pipe failed\n",
1512 corename);
1513 goto fail_unlock;
1514 }
1515 ispipe = 1;
1516 } else
1517 file = filp_open(corename,
1518 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE, 0600);
1508 if (IS_ERR(file)) 1519 if (IS_ERR(file))
1509 goto fail_unlock; 1520 goto fail_unlock;
1510 inode = file->f_dentry->d_inode; 1521 inode = file->f_dentry->d_inode;
1511 if (inode->i_nlink > 1) 1522 if (inode->i_nlink > 1)
1512 goto close_fail; /* multiple links - don't dump */ 1523 goto close_fail; /* multiple links - don't dump */
1513 if (d_unhashed(file->f_dentry)) 1524 if (!ispipe && d_unhashed(file->f_dentry))
1514 goto close_fail; 1525 goto close_fail;
1515 1526
1516 if (!S_ISREG(inode->i_mode)) 1527 /* AK: actually i see no reason to not allow this for named pipes etc.,
1528 but keep the previous behaviour for now. */
1529 if (!ispipe && !S_ISREG(inode->i_mode))
1517 goto close_fail; 1530 goto close_fail;
1518 if (!file->f_op) 1531 if (!file->f_op)
1519 goto close_fail; 1532 goto close_fail;
1520 if (!file->f_op->write) 1533 if (!file->f_op->write)
1521 goto close_fail; 1534 goto close_fail;
1522 if (do_truncate(file->f_dentry, 0, 0, file) != 0) 1535 if (!ispipe && do_truncate(file->f_dentry, 0, 0, file) != 0)
1523 goto close_fail; 1536 goto close_fail;
1524 1537
1525 retval = binfmt->core_dump(signr, regs, file); 1538 retval = binfmt->core_dump(signr, regs, file);