1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-30 06:25:25 +03:00

udevd: disable OOM

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
Kay Sievers 2005-11-05 19:41:00 +01:00
parent 57d782bf1e
commit 3904a75817

49
udevd.c
View File

@ -814,7 +814,7 @@ static int init_uevent_netlink_sock(void)
int main(int argc, char *argv[], char *envp[]) int main(int argc, char *argv[], char *envp[])
{ {
int retval; int retval;
int devnull; int fd;
struct sigaction act; struct sigaction act;
fd_set readfds; fd_set readfds;
const char *value; const char *value;
@ -824,20 +824,20 @@ int main(int argc, char *argv[], char *envp[])
int rc = 0; int rc = 0;
/* redirect std fd's, if the kernel forks us, we don't have them at all */ /* redirect std fd's, if the kernel forks us, we don't have them at all */
devnull = open("/dev/null", O_RDWR); fd = open("/dev/null", O_RDWR);
if (devnull >= 0) { if (fd >= 0) {
if (devnull != STDIN_FILENO) if (fd != STDIN_FILENO)
dup2(devnull, STDIN_FILENO); dup2(fd, STDIN_FILENO);
if (devnull != STDOUT_FILENO) if (fd != STDOUT_FILENO)
dup2(devnull, STDOUT_FILENO); dup2(fd, STDOUT_FILENO);
if (devnull != STDERR_FILENO) if (fd != STDERR_FILENO)
dup2(devnull, STDERR_FILENO); dup2(fd, STDERR_FILENO);
if (devnull > STDERR_FILENO) if (fd > STDERR_FILENO)
close(devnull); close(fd);
} }
logging_init("udevd"); logging_init("udevd");
if (devnull < 0) if (fd < 0)
err("fatal, could not open /dev/null"); err("fatal, could not open /dev/null");
udev_init_config(); udev_init_config();
@ -889,13 +889,6 @@ int main(int argc, char *argv[], char *envp[])
switch (pid) { switch (pid) {
case 0: case 0:
dbg("daemonized fork running"); dbg("daemonized fork running");
/* become session leader */
sid = setsid();
dbg("our session is %d", sid);
chdir("/");
umask(umask(077) | 022);
break; break;
case -1: case -1:
err("fork of daemon failed"); 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); 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 */ /* setup signal handler pipe */
retval = pipe(signal_pipe); retval = pipe(signal_pipe);
if (retval < 0) { if (retval < 0) {