comparison terminal.c @ 832:0433fdd9ba66

Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
author Michael Pavone <pavone@retrodev.com>
date Mon, 19 Oct 2015 19:16:28 -0700
parents 792be135d3af
children 794ba17f0716
comparison
equal deleted inserted replaced
831:079eb395ddd1 832:0433fdd9ba66
15 kill(child, SIGKILL); 15 kill(child, SIGKILL);
16 unlink(INPUT_PATH); 16 unlink(INPUT_PATH);
17 unlink(OUTPUT_PATH); 17 unlink(OUTPUT_PATH);
18 } 18 }
19 19
20 static char init_done;
21
22 void force_no_terminal()
23 {
24 init_done = 1;
25 }
26
20 void init_terminal() 27 void init_terminal()
21 { 28 {
22 static char init_done;
23 if (!init_done) { 29 if (!init_done) {
24 if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) { 30 if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) {
25 #ifndef __APPLE__ 31 #ifndef __APPLE__
26 //check to see if x-terminal-emulator exists, just use xterm if it doesn't 32 //check to see if x-terminal-emulator exists, just use xterm if it doesn't
27 char *term = system("which x-terminal-emulator > /dev/null") ? "xterm" : "x-terminal-emulator"; 33 char *term = system("which x-terminal-emulator > /dev/null") ? "xterm" : "x-terminal-emulator";
30 unlink(INPUT_PATH); 36 unlink(INPUT_PATH);
31 unlink(OUTPUT_PATH); 37 unlink(OUTPUT_PATH);
32 //create FIFOs for talking to helper process in terminal app 38 //create FIFOs for talking to helper process in terminal app
33 mkfifo(INPUT_PATH, 0666); 39 mkfifo(INPUT_PATH, 0666);
34 mkfifo(OUTPUT_PATH, 0666); 40 mkfifo(OUTPUT_PATH, 0666);
35 41
36 //close existing file descriptors 42 //close existing file descriptors
37 close(STDIN_FILENO); 43 close(STDIN_FILENO);
38 close(STDOUT_FILENO); 44 close(STDOUT_FILENO);
39 close(STDERR_FILENO); 45 close(STDERR_FILENO);
40 46
57 if (-1 == dup(STDOUT_FILENO)) { 63 if (-1 == dup(STDOUT_FILENO)) {
58 fatal_error("failed to dup STDOUT to STDERR after terminal fork"); 64 fatal_error("failed to dup STDOUT to STDERR after terminal fork");
59 } 65 }
60 } 66 }
61 } 67 }
62 68
63 init_done = 1; 69 init_done = 1;
64 } 70 }
65 } 71 }