[DRBD-cvs] r1723 - branches/drbd-0.7/user

svn at svn.drbd.org svn at svn.drbd.org
Mon Jan 17 11:19:53 CET 2005


Author: phil
Date: 2005-01-17 11:19:50 +0100 (Mon, 17 Jan 2005)
New Revision: 1723

Modified:
   branches/drbd-0.7/user/drbdadm_main.c
Log:
I realized that on RHAS3 systems (and probabely all other RedHat
based and related distributions) drbdadm's user dialog
was not displayed in the boot process.
RedHat's rc script redirects all output of init scripts to
the Logfiles exclusively!! 
If drbdadm detects this (by using isatty(stdin)) it prints
a warning and does the user dialog on /dev/console


Modified: branches/drbd-0.7/user/drbdadm_main.c
===================================================================
--- branches/drbd-0.7/user/drbdadm_main.c	2005-01-15 10:03:08 UTC (rev 1722)
+++ branches/drbd-0.7/user/drbdadm_main.c	2005-01-17 10:19:50 UTC (rev 1723)
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/poll.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <getopt.h>
@@ -823,9 +824,26 @@
   struct d_option* opt;
   int rr,wtime,argc,i=0;
   time_t start;
+  int saved_stdin,saved_stdout,fd;
 
   struct sigaction so,sa;
 
+  saved_stdin = -1;
+  if( isatty(fileno(stdin)) == 0 || isatty(fileno(stdout)) == 0 ) {
+    fprintf(stderr,"WARN: stdin/stdout is not a TTY; using /dev/console");
+    fprintf(stdout,"WARN: stdin/stdout is not a TTY; using /dev/console");
+    saved_stdin  = dup(fileno(stdin));
+    if( saved_stdin == -1) perror("dup(stdin)");
+    saved_stdout = dup(fileno(stdout));
+    if( saved_stdin == -1) perror("dup(stdout)");
+    fd = open( "/dev/console", O_RDONLY);
+    if(fd == -1) perror("open('/dev/console, O_RDONLY)");
+    dup2(fd, fileno(stdin) );
+    fd = open( "/dev/console", O_WRONLY);
+    if(fd == -1) perror("open('/dev/console, O_WRONLY)");
+    dup2(fd, fileno(stdout) );
+  }
+
   sa.sa_handler=chld_sig_hand;
   sigemptyset(&sa.sa_mask);
   sa.sa_flags=SA_NOCLDSTOP;
@@ -886,6 +904,11 @@
     printf("\n");
   }
 
+  if( saved_stdin != -1 ) {
+    dup2(saved_stdin,  fileno(stdin ) );
+    dup2(saved_stdout, fileno(stdout) );
+  }
+
   return 0;
 }
 



More information about the drbd-cvs mailing list