-4

The manpage of core(5) says one of the reason by which core dump file is not produced is:

A (writable, regular) file with the same name as would be used for the core dump already exists, but there is more than one hard link to that file.

If an existing file with the same name is writable, doesn't that mean it can be overwritten?

How does its number of hard links matter to producing a core dump file?

In following example, I create a file core without any other hard link, it is not overwritten by coredump:

$ ls
$ touch core
$ ls -l
total 0
-rw-rw-r-- 1 t t 0 Dec  3 06:01 core

$ # wait for a minute
$ bash -c "ulimit -c -S; ulimit -S -c 1024; ulimit -c -S; sleep 10"
0
1024
^\bash: line 1:  4071 Quit                    (core dumped) sleep 10
$ ls -l
total 0
-rw-rw-r-- 1 t t 0 Dec  3 06:01 core

Generally without core dump involved, having more than one hardlinks doesn't prevent overwriting, so I am not sure what "but there is more than one hard link to that file" means when core dump is involved (I am here for clarification not for confusing others):

$ ls
test
$ ln test testhl
$ ls -la
total 28
drwxrwxr-x 4 t t 4096 Dec  2 11:29 .
drwxrwxr-x 6 t t 4096 Dec  2 07:49 ..
-rw-rw-r-- 2 t t    4 Nov 26 10:21 test
-rw-rw-r-- 2 t t    4 Nov 26 10:21 testhl
$ echo hello > testhl
$ ls -la
total 28
drwxrwxr-x 4 t t 4096 Dec  2 11:29 .
drwxrwxr-x 6 t t 4096 Dec  2 07:49 ..
-rw-rw-r-- 2 t t    6 Dec  2 11:30 test
-rw-rw-r-- 2 t t    6 Dec  2 11:30 testhl
$ cat test
hello

Thanks.

closed as unclear what you're asking by Stephen Harris, G-Man, sam, RalfFriedl, Christopher Dec 4 '18 at 18:28

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What has test and testhl got to do with "same name as would be used for the core dump"? – Stephen Harris Dec 2 '18 at 16:44
1

If an existing file with the same name is writable, doesn't that mean it can be overwritten?

Yes, that's what writeable means.

Does its number of hard links matter to producing a core dump file in some way? It works fine in the following case without core dump involved, which is the source of my confusion (I am here for clarification not for confusing others):

The answer is included in the quote you mention:

A (writable, regular) file with the same name as would be used for the core dump already exists, but there is more than one hard link to that file.

This means that if these two conditions are met, no core file will be created:

  1. A file with the same name as the core file to be created (usually core) already exists and is writeable.

AND

  1. That file has more than one hard link pointing to it.

So, yes, the number of hard links matters in some way: the manpage says that if there is more than one hard link to the file, then the core file will not be created.

-1

In Ubuntu, core dump is fed to /usr/share/apport/apport by default,

$ sysctl kernel.core_pattern 
kernel.core_pattern = |/usr/share/apport/apport %p %s %c %d %P

In /usr/share/apport/apport, the signal disposition for SIGQUIT is https://bazaar.launchpad.net/~apport-hackers/apport/trunk/view/3194/data/apport#L474

# ignore SIGQUIT (it's usually deliberately generated by users)
if signum == str(int(signal.SIGQUIT)):
    drop_privileges()
    write_user_coredump(pid, cwd, core_ulimit)
    sys.exit(0)

In write_user_coredump(), https://bazaar.launchpad.net/~apport-hackers/apport/trunk/view/3194/data/apport#L181

core_path = os.path.join(cwd, 'core')
try:
    with open('/proc/sys/kernel/core_uses_pid') as f:
        if f.read().strip() != '0':
            core_path += '.' + str(pid)
    core_file = os.open(core_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
except (OSError, IOError):
    return

os.O_CREAT | os.O_EXCL will generate error if a file core already exists. That explains the first half of

A (writable, regular) file with the same name as would be used for the core dump already exists, but there is more than one hard link to that file.

But

  • "writable" in the manpage is very misleading: something "writable" is not in fact writable.

  • still I don't understand what "there is more than one hard link to that file" means. I don't know where in the code the number of hard links will prevent overwriting or matter in somer way.

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