Any way to control core file location?

If we build an application and run tests, the application might core-dump is a crashing bug has been introduced. I would like to optionally override the core pattern/location so that I can look for core files after execution and at least generate a call stack dump. The pattern on the base linux image seems to be
|/usr/share/apport/apport %p %s %c %d %P but I get permission denied when I try to change it by writing to /proc/sys/kernel/core_pattern. Is there any way I can get access to core files if/when my application crashes. To complicate things further, I’m actually running my tests in a docker container on this host, but my understanding is that docker inherits the host behavior in this regard since they are running in the same kernel.

Naturally, you need to write a system-wide setting with sudo. If you are in docker, you may need to place it to a directory mounted with -v to be able to access it on the host.

If that doesn’t help, please link to your build to give more details on what’s happening.

I agree, sudo is required for this setting, but I still get permission denied, e.g.:

https://travis-ci.org/mellery451/rippled/jobs/543202564

The full set of commands are:

mkdir -p -m 0777 ${TRAVIS_BUILD_DIR}/cores
sudo echo "${TRAVIS_BUILD_DIR}/cores/%e.%p" > /proc/sys/kernel/core_pattern
docker run \
    -t --env-file /tmp/co.env \
    -v ${TRAVIS_HOME}:${TRAVIS_HOME} \
    -w ${TRAVIS_BUILD_DIR} \
    --ulimit "core=-1" \
    $DOCKER_IMAGE \
    /bin/bash -c 'bin/ci/ubuntu/build-and-test.sh'

…so the core pattern setting happen in travis host, not the container (but it should be used by the container since it runs in the same kernel, I assume)

Redirection happens in the non-elevated bash here. The linked question uses tricks like tee, sysctl and bash -c for a reason.

1 Like

derp - you’re exactly right…non elevated redir was my issue.

Imprint