1

I wrote a simple C application (in core_app.c) to process a coredump:

int main(int argc, char *argv[]) {
    FILE *fp = fopen("/tmp/coretest", "w");
    char input[MAX_INPUT];
    // write a coredump to /tmp/coretest
    if (fp != 0) {
        while (fgets(input, MAX_INPUT, stdin)) {
            fputs(input, fp);
        }
        fclose(fp);
    } else {
        perror("[FMon] cannot open file!");
    }

    return EXIT_SUCCESS;
}

and then I set the core_pattern using a systemd service which contains:

[Service]
ExecStart=/bin/sh -c "echo '| core_app' > /proc/sys/kernel/core_pattern"

After a reset the content of the file /proc/sys/kernel/core_pattern is correct. But the syslog shows:

Jan 01 00:19:52 kernel: Core dump to | core_app pipe failed

Anybody knows why the pipe failed? Thanks

  • 2
    have you tried full path? is your core_app has "x" bit? – user996142 Jun 30 '17 at 13:09
  • thanks @user996142! yes, the missing full path was the issue. Do you know how to deal with the specifier conflict between systemd and coredump. If I type ExecStart=/bin/sh -c "echo '| /usr/bin/core_app %e %p %c' > /proc/sys/kernel/core_pattern in the service file, the specifier %p and `%c are subtitute to the service name and service path. – why2 Jun 30 '17 at 14:39
1

The kernel invokes the command declared in core_pattern from the process's current directory. This is a direct kernel invocation, so there is no PATH lookup. Therefore core_app must be an executable file in the process's current directory.

To invoke a particular core_app executable no matter what the process's current directory is, use the full path to core_app, e.g.

echo '|/usr/local/sbin/core_app' >/proc/sys/kernel/core_pattern

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.