FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 05-11-2011, 05:44 PM
Ankit Jain
 
Default multipathd: Disassociate from /dev/console when daemonizing

Currently, multipathd redirects stdout/stderr to /dev/console,
to be able to show error messages when all else fails.

This patch redirects them to /dev/null instead, to make it a
well behaving daemon. This corresponds to FATE request
https://fate.novell.com/310684 .

This is based on -
git://git.kernel.org/pub/scm/linux/storage/multipath-tools/

----
commit a3dd997d1b0b55a934103e0b28648003675743e3
Author: Ankit Jain <jankit@suse.de>
Date: Wed May 11 22:18:33 2011 +0530

multipathd: Disassociate from /dev/console

When daemonizing, redirect stdout/stderr to /dev/null
instead of /dev/console. Also, chdir("/") before the redirection,
so that any error can be reported.
FATE#310684.

diff --git a/multipathd/main.c b/multipathd/main.c
index e8eee9e..cb77c82 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1540,7 +1540,7 @@ static int
daemonize(void)
{
int pid;
- int in_fd, out_fd;
+ int dev_null_fd;

if( (pid = fork()) < 0){
fprintf(stderr, "Failed first fork : %s
", strerror(errno));
@@ -1556,31 +1556,24 @@ daemonize(void)
else if (pid != 0)
_exit(0);

- in_fd = open("/dev/null", O_RDONLY);
- if (in_fd < 0){
- fprintf(stderr, "cannot open /dev/null for input : %s
",
- strerror(errno));
- _exit(0);
- }
- out_fd = open("/dev/console", O_WRONLY);
- if (out_fd < 0){
- fprintf(stderr, "cannot open /dev/console for output : %s
",
+ if (chdir("/") < 0)
+ fprintf(stderr, "cannot chdir to '/', continuing
");
+
+ dev_null_fd = open("/dev/null", O_RDWR);
+ if (dev_null_fd < 0){
+ fprintf(stderr, "cannot open /dev/null for input & output : %s
",
strerror(errno));
_exit(0);
}

close(STDIN_FILENO);
- dup(in_fd);
+ dup(dev_null_fd);
close(STDOUT_FILENO);
- dup(out_fd);
+ dup(dev_null_fd);
close(STDERR_FILENO);
- dup(out_fd);
-
- close(in_fd);
- close(out_fd);
- if (chdir("/") < 0)
- fprintf(stderr, "cannot chdir to '/', continuing
");
+ dup(dev_null_fd);

+ close(dev_null_fd);
return 0;
}


--
Ankit Jain
SUSE Labs

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 05:10 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org