core_get_process_content, core_set_process_content
core_get_process_path, core_set_process_path - fine granined per process core file control
int core_set_process_content(const core_content_t *content, pid_t pid);
int core_get_process_content(core_content_t *content, pid_t pid);
int core_set_process_path(const char *buf, size_t bufsize, pid_t pid);
int core_get_process_path(char *buf, size_t bufsize, pid_t pid);
These functions provide fine grained control of process core dump contents. coreadm(8) should be used to set global options for core dump content.
The core_get_process_content() function gets the current state of the contents of the segments that would be contained in a core dump of this process.
The core_set_process_content() function sets the contents of the segments what will be contained in a core dump of this process.
The core_get_process_path() function gets the current path which points to the location that a process's core file will be written.
The core_set_process_path() function sets the current path which points to the location that a process's core file will be written.
core_content_t may be one of the following
Dump process stack.
Dump process HEAP.
Dump file-backed shared mappings.
Dump anonymous shared mappings.
Dump read/exec file mappings.
Dump writable mappings.
Dump read-only mappings.
Dump anonymous mappings (MAP_ANON).
Dump System V shared memory.
Dump intimate shared memory.
Dump dynamic intimate shared memory.
Dump CTF data.
Dump symbol table.
Dump optimized shared memory.
Prune enabled (memcntl).
Dump all.
Dump none.
Upon successful completion, core_set_process_content(), core_set_process_content(), core_set_process_content() and core_set_process_content() return 0 if successful. Otherwise, the functions return a non-zero errno to indicate the error.
core_set_process_content(), core_set_process_content(), core_set_process_content(), core_set_process_content() functions will fail if:
Invalid path
Privileged user tries to enable writing core file in a set-id process, but set-id core files global property is not enabled. See coreadm(8).
No such process
Insufficent permissions to inspect process
core_set_process_content() function will fail if:
Filename exeeds system limits.
The following example code shows the use o core_get_process_content() to obtain a processes core file status information and core_set_process_content() to specify core file content.
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sysmacros.h> #include <sys/corectl.h> struct _cc_content { int cc_type; char *cc_str; }; static struct _cc_content cc_types[] = { { CC_CONTENT_STACK, "STACK"}, { CC_CONTENT_HEAP, "HEAP"}, { CC_CONTENT_SHFILE, "SHFILE"}, { CC_CONTENT_SHANON, "SHANON"}, { CC_CONTENT_TEXT, "TEXT"}, { CC_CONTENT_DATA, "DATA"}, { CC_CONTENT_RODATA, "RODATA"}, { CC_CONTENT_ANON, "ANON"}, { CC_CONTENT_SHM, "SHM"}, { CC_CONTENT_ISM, "ISM"}, { CC_CONTENT_DISM, "DISM"}, { CC_CONTENT_CTF, "CTF"}, { CC_CONTENT_SYMTAB, "SYMTAB"}, { CC_CONTENT_OSM, "OSM"}, { CC_CONTENT_PRUNE, "PRUNE"}, }; static void show_dump_segments (pid_t pid) { core_content_t content; if (core_get_process_content (&content, pid)) perror ("core_get_process_content failed"); if (content == CC_CONTENT_DEFAULT) printf("Core file content to dump is the default\n\t"); else printf("Core file contents to dump modified from default\n\t"); for (int i=0; i < ARRAYi++LEN(cc_types);i++) { if (content & cc_types[i].cc_type) printf("%s ", cc_types[i].cc_str); } printf("\n\n"); } int main (int argc, char **argv) { int shmid; void *shm; core_content_t core_content_mask = CC_CONTENT_DEFAULT; pid_t me = getpid(); if (core_set_process_content (&core_content_mask, me)) perror ("core_set_process_content failed"); show_dump_segments(me); /* Mask off unwanted sections */ core_content_mask &= ~(CC_CONTENT_SHM |CC_CONTENT_ISM | CC_CONTENT_DISM | CC_CONTENT_OSM ); if (core_set_process_content (&core_content_mask, me)) perror ("core_set_process_content failed"); show_dump_segments(me); /* allocate ISM */ if ((shmid = shmget (5678, 1024 * 1024 * 64, IPC_CREAT | 0666)) < 0) { perror ("shmget"); exit (1); } /* Attach the segment to our data space. */ if ((shm = shmat (shmid, NULL, SHM_SHARE_MMU)) == (char *) -1) { perror ("shmat"); exit (1); } printf ("Force a SEGV to produce a corefile\n"); ((char *) shm)[-1] = 0; }
See attributes(7) for descriptions of the following attributes:
|
coreadm(8), memcntl(2), pmap(1)
When applicable, the use of the coreadm utility in preference to these functions, is advised. These interfaces exist to allow per-process control over core file details..