4

On Ubuntu 12.04, open a new text file and write:

#include <stdlib.h>

int main()
{
    abort();
    return 0;
}

Now run:

g++ yourfile.cpp

Then run the executable, which will core dump:

./a.out

Now check the mtime of the file:

-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core

Now run the executable again:

./a.out

Now check the mtime again:

-rw-r----- 1 xxxxx xxxxx 228K 2012-10-01 19:20:20.752136399 -0500 core

It's the same! Why doesn't a fresh core overwrite the old one? When rebuilding this causes gdb to complain the core is older than the executable.

Just to be sure it wasn't a permissioning problem, I tried this in a fresh directory in /tmp and ran chmod -R 777 **/* inside. Running the executable twice still didn't produce a new core O_o Also, ulimit -c reports 800000000, more than enough for a core this size.

I also tried running a clean bash with env - bash --noprofile --norc and still running the binary doesn't update the mtime of the core unless I delete it first.

Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165

2 Answers2

6

If you refer to https://bugs.launchpad.net/ubuntu/+source/apport/+bug/160999 this is a bug in Ubuntu using O_EXCL to open the file, preventing it from overwriting an existing core.

Mark B
  • 95,107
  • 10
  • 109
  • 188
2

The core(5) man page lists certain conditions under which a core file is not [re-]written. You probably meet one of those conditions. Please read carefully that man page.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • All of those conditions prevent writing, but not rewriting. I don't see how just rm'ing the file would change any of the situations they list... if I can make the file I obviously have permissions, I'm not making hard links to the core so there can't be more than one, file system isn't full, directory obviously exists, since the core is the same size as before can't be ulimits, have to have read permission for the binary otherwise how am I running, and it's not setuid... – Joseph Garvin Oct 01 '12 at 20:36
  • I've updated my post with details on eliminated possibilities. – Joseph Garvin Oct 02 '12 at 00:16
  • OK, and now I have a reproducible example ;) – Joseph Garvin Oct 02 '12 at 00:22