increase RLIMIT_CORE (generate a coredump)

This commit is contained in:
Leonardo Hernández Hernández 2022-10-05 23:07:13 -05:00 committed by Leonardo Hernández Hernández
parent 4b8c1bf31e
commit 4b35e3b000
No known key found for this signature in database
GPG key ID: E538897EE11B9624

9
dwl.c
View file

@ -8,6 +8,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
@ -321,6 +322,8 @@ static void zoom(const Arg *arg);
/* variables */
static const char broken[] = "broken";
static struct rlimit oldrlimit;
static struct rlimit newrlimit;
static const char *cursor_image = "left_ptr";
static pid_t child_pid = -1;
static int locked;
@ -1971,6 +1974,7 @@ run(char *startup_cmd)
if ((child_pid = fork()) < 0)
die("startup: fork:");
if (child_pid == 0) {
setrlimit(RLIMIT_CORE, &oldrlimit);
dup2(piperw[0], STDIN_FILENO);
close(piperw[0]);
close(piperw[1]);
@ -2313,6 +2317,7 @@ void
spawn(const Arg *arg)
{
if (fork() == 0) {
setrlimit(RLIMIT_CORE, &oldrlimit);
dup2(STDERR_FILENO, STDOUT_FILENO);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
@ -2793,6 +2798,10 @@ main(int argc, char *argv[])
char *startup_cmd = NULL;
int c;
getrlimit(RLIMIT_CORE, &oldrlimit);
newrlimit.rlim_cur = newrlimit.rlim_max = oldrlimit.rlim_max;
setrlimit(RLIMIT_CORE, &newrlimit);
while ((c = getopt(argc, argv, "s:hv")) != -1) {
if (c == 's')
startup_cmd = optarg;