diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-11-05 19:41:00 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-11-05 19:41:00 +0100 |
commit | 3904a7581776cffc7ddaf4adbfbea8a57ab1adaa (patch) | |
tree | 1486f847e812662d63647fc8ebacc2971b105340 /udevd.c | |
parent | 57d782bf1e8313e65579a8faa9671a8e5ffecb2f (diff) |
udevd: disable OOM
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'udevd.c')
-rw-r--r-- | udevd.c | 49 |
1 files changed, 29 insertions, 20 deletions
@@ -814,7 +814,7 @@ static int init_uevent_netlink_sock(void) int main(int argc, char *argv[], char *envp[]) { int retval; - int devnull; + int fd; struct sigaction act; fd_set readfds; const char *value; @@ -824,20 +824,20 @@ int main(int argc, char *argv[], char *envp[]) int rc = 0; /* redirect std fd's, if the kernel forks us, we don't have them at all */ - devnull = open("/dev/null", O_RDWR); - if (devnull >= 0) { - if (devnull != STDIN_FILENO) - dup2(devnull, STDIN_FILENO); - if (devnull != STDOUT_FILENO) - dup2(devnull, STDOUT_FILENO); - if (devnull != STDERR_FILENO) - dup2(devnull, STDERR_FILENO); - if (devnull > STDERR_FILENO) - close(devnull); + fd = open("/dev/null", O_RDWR); + if (fd >= 0) { + if (fd != STDIN_FILENO) + dup2(fd, STDIN_FILENO); + if (fd != STDOUT_FILENO) + dup2(fd, STDOUT_FILENO); + if (fd != STDERR_FILENO) + dup2(fd, STDERR_FILENO); + if (fd > STDERR_FILENO) + close(fd); } logging_init("udevd"); - if (devnull < 0) + if (fd < 0) err("fatal, could not open /dev/null"); udev_init_config(); @@ -889,13 +889,6 @@ int main(int argc, char *argv[], char *envp[]) switch (pid) { case 0: dbg("daemonized fork running"); - - /* become session leader */ - sid = setsid(); - dbg("our session is %d", sid); - - chdir("/"); - umask(umask(077) | 022); break; case -1: err("fork of daemon failed"); @@ -907,9 +900,25 @@ int main(int argc, char *argv[], char *envp[]) } } - /* set a reasonable scheduling priority for the daemon */ + /* set scheduling priority for the daemon */ setpriority(PRIO_PROCESS, 0, UDEVD_PRIORITY); + chdir("/"); + umask(077); + + /* become session leader */ + sid = setsid(); + dbg("our session is %d", sid); + + /* OOM_DISABLE == -17 */ + fd = open("/proc/self/oom_adj", O_RDWR); + if (fd < 0) + err("error disabling OOM"); + else { + write(fd, "-17", 3); + close(fd); + } + /* setup signal handler pipe */ retval = pipe(signal_pipe); if (retval < 0) { |