From: Michael Kerrisk <mtk.manpages@googlemail.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>,
Andi Kleen <andi@firstfloor.org>,
linux-man@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Petr Gajdos <pgajdos@suse.cz>,
michael.kerrisk@gmail.com
Subject: core_pattern pipe documentation - draft 2
Date: Mon, 05 May 2008 09:19:16 +0200 [thread overview]
Message-ID: <481EB4F4.8050901@gmail.com> (raw)
In-Reply-To: <cfd18e0f0804251339x2b19dd79o593d836986bf99ee@mail.gmail.com>
Hi Neil,
Below is a revised draft of the text for core_pattern. Would you be willing
check it over?
Cheers,
Michael
Naming of core dump files
By default, a core dump file is named core, but the
/proc/sys/kernel/core_pattern file (since Linux 2.6 and 2.4.21)
can be set to define a template that is used to name core dump
files. The template can contain % specifiers which are substi-
tuted by the following values when a core file is created:
%% a single % character
%p PID of dumped process
%u (numeric) real UID of dumped process
%g (numeric) real GID of dumped process
%s number of signal causing dump
%t time of dump, expressed as seconds since the Epoch
(00:00h, 1 Jan 1970, UTC)
%h hostname (same as 'nodename' returned by uname(2))
%e executable filename (without path prefix)
%c core file size soft resource limit of crashing process
(since Linux 2.6.24)
A single % at the end of the template is dropped from the core
filename, as is the combination of a % followed by any charac-
ter other than those listed above. All other characters in the
template become a literal part of the core filename. The tem-
plate may include '/' characters, which are interpreted as
delimiters for directory names. The maximum size of the
resulting core filename is 128 bytes (64 bytes in kernels
before 2.6.19).
[...]
Piping core dumps to a program
Since kernel 2.6.19, Linux supports an alternate syntax for the
/proc/sys/kernel/core_pattern file. If the first character of
this file is a pipe symbol (|), then the remainder of the line
is interpreted as a program to be executed. Instead of being
written to a disk file, the core dump is given as standard
input to the program. Note the following points:
* The program must be specified using an absolute pathname (or
a pathname relative to the root directory, /), and must
immediately follow the '|' character.
* The process created to run the program runs as user and
group root.
* Command-line arguments can be supplied to the program (since
kernel 2.6.24), delimited by white space (up to a total line
length of 128 bytes).
* The command-line arguments can include any of the % speci-
fiers listed above. For example, to pass the PID of the
process that is being dumped, specify %p in an argument.
[...]
EXAMPLE
The program below can be used to demonstrate the use of the
pipe syntax in the /proc/sys/kernel/core_pattern file. The
following shell session demonstrates the use of this program
(compiled to create an executable named core_pattern_test):
$ cc -o core_pattern_test core_pattern_test.c
$ su
Password:
# echo "|$PWD/core_pattern_test %p UID=%u GID=%g sig=%s" > \
/proc/sys/kernel/core_pattern
# exit
$ sleep 100
type control-backslash
Quit (core dumped)
$ cat core.info
argc=5
argc[0]=</home/mtk/core_pattern_test>
argc[1]=<20575>
argc[2]=<UID=1000>
argc[3]=<GID=100>
argc[4]=<sig=3>
Total bytes in core dump: 282624
The source code of the program is as follows:
/* core_pattern_test.c */
#define _GNU_SOURCE
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUF_SIZE 1024
int
main(int argc, char *argv[])
{
int tot, j;
ssize_t nread;
char buf[BUF_SIZE];
FILE *fp;
char cwd[PATH_MAX];
/* Change our current working directory to that of the
crashing process */
snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
chdir(cwd);
/* Write output to file "core.info" in that directory */
fp = fopen("core.info", "w+");
if (fp == NULL)
exit(EXIT_FAILURE);
/* Display command-line arguments given to core_pattern
pipe program */
fprintf(fp, "argc=%d\n", argc);
for (j = 0; j < argc; j++)
fprintf(fp, "argc[%d]=<%s>\n", j, argv[j]);
/* Count bytes in standard input (the core dump) */
tot = 0;
while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
tot += nread;
fprintf(fp, "Total bytes in core dump: %d\n", tot);
exit(EXIT_SUCCESS);
}
next prev parent reply other threads:[~2008-05-05 7:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-15 21:09 core_pattern piping strangeness Michael Kerrisk
[not found] ` <cfd18e0f0804151411x62080f10y833493db7f1b8cfd@mail.gmail.com>
[not found] ` <48051FBA.60503@firstfloor.org>
2008-04-18 16:53 ` core_pattern pipe documentation Michael Kerrisk
2008-04-23 12:09 ` Michael Kerrisk
2008-04-23 14:59 ` Neil Horman
2008-04-25 13:18 ` Michael Kerrisk
2008-04-25 16:22 ` Neil Horman
2008-04-25 18:13 ` Michael Kerrisk
2008-04-25 18:54 ` Neil Horman
2008-04-25 19:50 ` Michael Kerrisk
2008-04-25 20:05 ` Michael Kerrisk
2008-04-25 20:18 ` Neil Horman
2008-04-25 20:39 ` Michael Kerrisk
2008-05-05 7:19 ` Michael Kerrisk [this message]
2008-05-05 11:29 ` core_pattern pipe documentation - draft 2 Neil Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=481EB4F4.8050901@gmail.com \
--to=mtk.manpages@googlemail.com \
--cc=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=michael.kerrisk@gmail.com \
--cc=nhorman@tuxdriver.com \
--cc=pgajdos@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).