Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

core_set_process_path(3C)

Name

core_get_process_content, core_set_process_content

core_get_process_path, core_set_process_path - fine granined per process core file control

Synopsis

#include <corectl.h>
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);

Description

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

CC_CONTENT_STACK

Dump process stack.

CC_CONTENT_HEAP

Dump process HEAP.

CC_CONTENT_SHFILE

Dump file-backed shared mappings.

CC_CONTENT_SHANON

Dump anonymous shared mappings.

CC_CONTENT_TEXT

Dump read/exec file mappings.

CC_CONTENT_DATA

Dump writable mappings.

CC_CONTENT_RODATA

Dump read-only mappings.

CC_CONTENT_ANON

Dump anonymous mappings (MAP_ANON).

CC_CONTENT_SHM

Dump System V shared memory.

CC_CONTENT_ISM

Dump intimate shared memory.

CC_CONTENT_DISM

Dump dynamic intimate shared memory.

CC_CONTENT_CTF

Dump CTF data.

CC_CONTENT_SYMTAB

Dump symbol table.

CC_CONTENT_OSM

Dump optimized shared memory.

CC_CONTENT_PRUNE

Prune enabled (memcntl).

CC_CONTENT_ALL

Dump all.

CC_CONTENT_NONE

Dump none.

Return Values

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.

Errors

core_set_process_content(), core_set_process_content(), core_set_process_content(), core_set_process_content() functions will fail if:

EINVAL

Invalid path

ENOSUP

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).

ESRCH

No such process

EPERM

Insufficent permissions to inspect process

core_set_process_content() function will fail if:

ENAMETOOLONG

Filename exeeds system limits.

Examples

Example 1 Example of core_get_process_content() and core_set_process_content().

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;
}

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

See Also

coreadm(8), memcntl(2), pmap(1)

Notes

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..