Danny Backx wrote:
> [...]
> Question : I currently run "xplore -C -sync" to see things. But this
> pops up an "xterm -C" before dying. Is there a better way ?
Ok, here are some patches against xplore-1.1 which allow you to do
without xplore's -C option, to facilitate testing. I now push back
xplore's I/O redirection as far as possible, and also drain the pipe at
exit s.t. no output gets lost. This will also be included in the next
xplore release.
-- snip snip --
diff -ru xplore-1.1/xplore.c xplore-1.1-new/xplore.c
--- xplore-1.1/xplore.c Thu Aug 23 03:54:48 2001
+++ xplore-1.1-new/xplore.c Tue Aug 28 23:38:21 2001
@@ -124,7 +124,7 @@
void fatal(String msg)
{
- fprintf(stderr_dup?stderr_dup:stderr, "%s: %s\n", progname, msg);
+ fprintf(stderr, "%s: %s\n", progname, msg);
ClearSession();
cleanup();
exit_app(1);
@@ -137,10 +137,67 @@
exit_app(0);
}
+/* drain remaining log output to saved stderr (pilfered from a yet
unreleased
+ xfm version, thanks to Till Straumann!) */
+
+static void log_drain(void)
+{
+ int n;
+ char buf[BUFSIZ];
+
+ /* flush the buffers (to the pipe) */
+ fflush(stdout); fflush(stderr);
+
+ /* now drain the pipe */
+ while ( 0 < (n=read(pipefd[0],buf,BUFSIZ)) )
+ fwrite(buf,sizeof(char),n,stderr_dup);
+
+ fflush(stderr_dup);
+}
+
+/* set up stdout and stderr for capturing in console window or log pane
*/
+
+static void redirect(void)
+{
+ int oldflags, stdout_dup_fd, stderr_dup_fd;
+
+ /* create duplicates of the standard output streams */
+ if ((stdout_dup_fd = dup(fileno(stdout))) == -1 ||
+ !(stdout_dup = fdopen(stdout_dup_fd, "w")))
+ fatal("cannot dup stdout");
+ else if ((stderr_dup_fd = dup(fileno(stderr))) == -1 ||
+ !(stderr_dup = fdopen(stderr_dup_fd, "w")))
+ fatal("cannot dup stderr");
+ oldflags = fcntl(stdout_dup_fd, F_GETFD, 0);
+ fcntl(stdout_dup_fd, F_SETFD, oldflags|FD_CLOEXEC);
+ oldflags = fcntl(stderr_dup_fd, F_GETFD, 0);
+ fcntl(stderr_dup_fd, F_SETFD, oldflags|FD_CLOEXEC);
+
+ if (console) {
+ freopen("/dev/console", "w", stdout);
+ dup2(fileno(stdout), fileno(stderr));
+ } else {
+ if (!(pipefd = (int*)malloc(2*sizeof(int))) || pipe(pipefd) < 0)
+ fatal("error opening pipe");
+ dup2(pipefd[1], fileno(stdout));
+ dup2(fileno(stdout), fileno(stderr));
+ close(pipefd[1]);
+ /* don't let our side of the pipe be inherited by child processes
*/
+ oldflags = fcntl(pipefd[0], F_GETFD, 0);
+ fcntl(pipefd[0], F_SETFD, oldflags|FD_CLOEXEC);
+ /* set to nonblocking read */
+ oldflags = fcntl(pipefd[0], F_GETFL, 0);
+ fcntl(pipefd[0], F_SETFL, oldflags|O_NONBLOCK);
+ /* drain the pipe at exit */
+ atexit(log_drain);
+ }
+}
+
int main(int argc, char **argv)
{
String s, progname = argv[0];
- int oldflags, stdout_dup_fd, stderr_dup_fd;
+
+ stdout_dup = stdout; stderr_dup = stderr;
/* initialize the application: */
@@ -191,34 +248,6 @@
exit(0);
}
- /* create duplicates of the standard output streams */
- if ((stdout_dup_fd = dup(fileno(stdout))) == -1 ||
- !(stdout_dup = fdopen(stdout_dup_fd, "w")))
- fatal("cannot dup stdout");
- else if ((stderr_dup_fd = dup(fileno(stderr))) == -1 ||
- !(stderr_dup = fdopen(stderr_dup_fd, "w")))
- fatal("cannot dup stderr");
- oldflags = fcntl(stdout_dup_fd, F_GETFD, 0);
- fcntl(stdout_dup_fd, F_SETFD, oldflags|FD_CLOEXEC);
- oldflags = fcntl(stderr_dup_fd, F_GETFD, 0);
- fcntl(stderr_dup_fd, F_SETFD, oldflags|FD_CLOEXEC);
-
- /* set up stdout and stderr for capturing in console window or log
pane */
- if (console) {
- freopen("/dev/console", "w", stdout);
- dup2(fileno(stdout), fileno(stderr));
- } else {
- if (!(pipefd = (int*)malloc(2*sizeof(int))) || pipe(pipefd) < 0)
- fatal("error opening pipe");
- dup2(pipefd[1], fileno(stdout));
- dup2(fileno(stdout), fileno(stderr));
- close(pipefd[1]);
- oldflags = fcntl(pipefd[0], F_GETFD, 0);
- fcntl(pipefd[0], F_SETFD, oldflags|FD_CLOEXEC);
- oldflags = fcntl(pipefd[0], F_GETFL, 0);
- fcntl(pipefd[0], F_SETFL, oldflags|O_NONBLOCK);
- }
-
/* other initializations: */
/* install signal handlers first, to avoid zombie processes */
@@ -260,6 +289,7 @@
/* run the application: */
splash_off();
+ redirect();
run_app();
}
-- snip snip --
--
Dr. Albert Gr"af
Email: [EMAIL PROTECTED], [EMAIL PROTECTED]
WWW: http://www.musikwissenschaft.uni-mainz.de/~ag