Cores apparently are not dumped when the using sudo
despite ulimit -c
being set to unlimited. Is there any way around this?
3 Answers
sudo will reset the core dump settings, like it does for a lot of other environment state. You can run the program via a helper that first enables core dumps and then runs the program. Create for example a wrapper /usr/local/bin/coredump
and then chmod +x
:
$ cat /usr/local/bin/coredump
#!/bin/sh
ulimit -c unlimited
exec "$@"
Then
sudo /usr/local/bin/coredump /your/crashing/program
-
I've discovered that even with ulimit -c set to unlimited that, sudo su to root still will not produce a core.– CatskulJul 20, 2011 at 21:01
-
Yes, I've already mentioned what sudo will reset the core dump setting. You have to do "ulimit -c unlimited" after the sudo. Jul 20, 2011 at 21:30
-
That's what I was saying. Sudoing to root using
sudo su
then setting the core limit tounlimited
it still would not produce a core. This is no longer an issue after messing with sysctl, but despite suid_dumpable behavior being well documented, for some reason it doesn't seem to be as consistent in practice.– CatskulJul 20, 2011 at 21:40
Since sudo 1.9.11, coredumps are explicitly disabled by default, as per the man 5 sudoers
manual and this github comment confirming it. Which means that whatever settings you have for ulimit -c
in your shell, or anything in /etc/limits.conf
, /etc/security/limits.conf
and /etc/login.defs
are completely overridden by sudo: ie.
$ ulimit -c
134
$ sudo -u user -- bash -c "ulimit -c"
0
I use this line Defaults rlimit_core=infinity
in /etc/sudoers file (or similar, eg. /etc/sudoers.d/90-coredumpsize) to have sudo do the equivalent of ulimit -c unlimited
while inside sudo.
$ sudo -u user -- bash -c "ulimit -c"
unlimited
But still heed the 2 caveats from Catskul's (accepted)answer!
It seems it can be done using the -s option like:
sudo -s "ulimit -c unlimited; ./segfaultProg"
However 2 caveats:
- You may need to set the
suid_dumpable
parameter withsysctl -w kernel.suid_dumpable=2
- You may need to move an old core out of the way. Apparently there are special rules where it may refuse to write a core if the suid bit is set, and there's already a core there.
See the following for details: