Mercurial > octave
annotate src/main.in.cc @ 28218:8619dc0d3749
maint: merge stable to default.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 14 Apr 2020 11:10:14 -0700 |
parents | 49a0d90cd2a3 |
children | 0fc400f15e35 |
rev | line source |
---|---|
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 // %NO_EDIT_WARNING% |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // Copyright (C) 2012-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
25 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
26 //////////////////////////////////////////////////////////////////////// |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 // NOTE: This program is supposed to be a small wrapper that exists |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 // primarily to give up the controlling TTY and then exec Octave with |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 // its GUI. It may also execute Octave without the GUI or the command |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 // line version of Octave that is not linked with GUI libraries. So |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 // that it remains small, it should NOT depend on or be linked with |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 // liboctave or libinterp. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21440
diff
changeset
|
35 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21286
diff
changeset
|
36 # include "config.h" |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include <cstdlib> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include <cstring> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include <algorithm> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include <iostream> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include <string> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
21927
6f62bd248919
use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents:
21921
diff
changeset
|
46 #include "fcntl-wrappers.h" |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
47 #include "signal-wrappers.h" |
21927
6f62bd248919
use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents:
21921
diff
changeset
|
48 #include "unistd-wrappers.h" |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
49 #include "wait-wrappers.h" |
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
50 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21440
diff
changeset
|
51 #if ! defined (OCTAVE_VERSION) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
52 # define OCTAVE_VERSION %OCTAVE_VERSION% |
18152
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
53 #endif |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
54 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21440
diff
changeset
|
55 #if ! defined (OCTAVE_ARCHLIBDIR) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
56 # define OCTAVE_ARCHLIBDIR %OCTAVE_ARCHLIBDIR% |
18163
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
57 #endif |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
58 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21440
diff
changeset
|
59 #if ! defined (OCTAVE_BINDIR) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
60 # define OCTAVE_BINDIR %OCTAVE_BINDIR% |
18152
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
61 #endif |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
62 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21440
diff
changeset
|
63 #if ! defined (OCTAVE_PREFIX) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
20945
diff
changeset
|
64 # define OCTAVE_PREFIX %OCTAVE_PREFIX% |
18152
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
65 #endif |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
66 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
67 #if ! defined (OCTAVE_EXEC_PREFIX) |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
68 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX% |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
69 #endif |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
70 |
19785
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
71 #include "display-available.h" |
18360
f1ee47866e6b
use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents:
18163
diff
changeset
|
72 #include "shared-fcns.h" |
17782
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
73 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
74 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 // Forward signals to the GUI process. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 static pid_t gui_pid = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
80 static int caught_signal = -1; |
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
81 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 static void |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 gui_driver_sig_handler (int sig) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 if (gui_pid > 0) |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
86 caught_signal = sig; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
89 static void |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
90 gui_driver_set_signal_handler (const char *signame, |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
91 octave_sig_handler *handler) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 { |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
93 octave_set_signal_handler_by_name (signame, handler, false); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 static void |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 install_signal_handlers (void) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 { |
24520
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
99 // FIXME: do we need to handle and forward all the signals that Octave |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
100 // handles, or is it sufficient to only forward things like SIGINT, |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
101 // SIGBREAK, SIGABRT, SIGQUIT, and possibly a few others? |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
102 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
103 gui_driver_set_signal_handler ("SIGINT", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
104 gui_driver_set_signal_handler ("SIGBREAK", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
105 gui_driver_set_signal_handler ("SIGABRT", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
106 gui_driver_set_signal_handler ("SIGALRM", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
107 gui_driver_set_signal_handler ("SIGBUS", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 // SIGCHLD |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 // SIGCLD |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 // SIGCONT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
113 gui_driver_set_signal_handler ("SIGEMT", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
114 gui_driver_set_signal_handler ("SIGFPE", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
115 gui_driver_set_signal_handler ("SIGHUP", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
116 gui_driver_set_signal_handler ("SIGILL", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 // SIGINFO |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 // SIGINT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
121 gui_driver_set_signal_handler ("SIGIOT", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
122 gui_driver_set_signal_handler ("SIGLOST", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
123 gui_driver_set_signal_handler ("SIGPIPE", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
124 gui_driver_set_signal_handler ("SIGPOLL", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 // SIGPROF |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 // SIGPWR |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
129 gui_driver_set_signal_handler ("SIGQUIT", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
130 gui_driver_set_signal_handler ("SIGSEGV", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 // SIGSTOP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
134 gui_driver_set_signal_handler ("SIGSYS", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
135 gui_driver_set_signal_handler ("SIGTERM", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
136 gui_driver_set_signal_handler ("SIGTRAP", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 // SIGTSTP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 // SIGTTIN |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 // SIGTTOU |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 // SIGURG |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
143 gui_driver_set_signal_handler ("SIGUSR1", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
144 gui_driver_set_signal_handler ("SIGUSR2", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
145 gui_driver_set_signal_handler ("SIGVTALRM", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
146 gui_driver_set_signal_handler ("SIGIO", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 // SIGWINCH |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
150 gui_driver_set_signal_handler ("SIGXCPU", gui_driver_sig_handler); |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
151 gui_driver_set_signal_handler ("SIGXFSZ", gui_driver_sig_handler); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 |
17813
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
154 #endif |
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
155 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 static std::string |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 get_octave_bindir (void) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 // Accept value from the environment literally, but substitute |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 // OCTAVE_HOME in the configuration value OCTAVE_BINDIR in case Octave |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 // has been relocated to some installation directory other than the |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 // one originally configured. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 std::string obd = octave_getenv ("OCTAVE_BINDIR"); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 |
27934
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
166 return obd.empty () ? prepend_octave_exec_home (std::string (OCTAVE_BINDIR)) |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
167 : obd; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 |
18163
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
170 static std::string |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
171 get_octave_archlibdir (void) |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
172 { |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
173 // Accept value from the environment literally, but substitute |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
174 // OCTAVE_HOME in the configuration value OCTAVE_ARCHLIBDIR in case |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
175 // Octave has been relocated to some installation directory other than |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
176 // the one originally configured. |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
177 |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
178 std::string dir = octave_getenv ("OCTAVE_ARCHLIBDIR"); |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
179 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
180 return dir.empty () ? prepend_octave_exec_home (std::string (OCTAVE_ARCHLIBDIR)) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19785
diff
changeset
|
181 : dir; |
18163
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
182 } |
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
183 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 static int |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 octave_exec (const std::string& file, char **argv) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 { |
21949
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
187 int status = octave_execv_wrapper (file.c_str (), argv); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 |
21949
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
189 std::cerr << argv[0] << ": failed to exec '" << file << "'" << std::endl; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 |
21949
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
191 return status; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 static char * |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 strsave (const char *s) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 if (! s) |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23767
diff
changeset
|
198 return nullptr; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 int len = strlen (s); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 char *tmp = new char [len+1]; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
202 tmp = strcpy (tmp, s); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 return tmp; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
206 int |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 main (int argc, char **argv) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 int retval = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
210 |
24898
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
211 bool start_gui = false; |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
212 bool gui_libs = true; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
213 |
23712
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
214 set_octave_home (); |
b95c430c0649
revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
215 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 std::string octave_bindir = get_octave_bindir (); |
18163
65e4e0569ed4
install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents:
18152
diff
changeset
|
217 std::string octave_archlibdir = get_octave_archlibdir (); |
21284
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
218 std::string octave_cli |
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
219 = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION; |
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
220 std::string octave_gui = octave_archlibdir + dir_sep_char + "octave-gui"; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 |
21374
1487a68a496a
untangle configuration of OpenGL, FLTK, and Qt (bug #47263)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
222 #if defined (HAVE_OCTAVE_QT_GUI) |
18164
eb51f47d9dee
maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
diff
changeset
|
223 // The Octave version number is already embedded in the |
eb51f47d9dee
maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
diff
changeset
|
224 // octave_archlibdir directory name so we don't need to append it to |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
225 // the octave-gui filename. |
18164
eb51f47d9dee
maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
diff
changeset
|
226 |
21284
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
227 std::string file = octave_gui; |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
228 #else |
21284
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
229 std::string file = octave_cli; |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
230 #endif |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 |
21440
062c65569ad7
avoid some address-sanitizer leak warnings (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21374
diff
changeset
|
232 // Declaring new_argv static avoids leak warnings when using GCC's |
062c65569ad7
avoid some address-sanitizer leak warnings (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21374
diff
changeset
|
233 // --address-sanitizer option. |
062c65569ad7
avoid some address-sanitizer leak warnings (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21374
diff
changeset
|
234 static char **new_argv = new char * [argc + 1]; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 |
17959
1329866151be
[Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17865
diff
changeset
|
236 int k = 1; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
238 bool warn_display = true; |
21783
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
239 bool no_display = false; |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
240 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 for (int i = 1; i < argc; i++) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 { |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
243 if (! strcmp (argv[i], "--no-gui-libs")) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 // Run the version of Octave that is not linked with any GUI |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 // libraries. It may not be possible to do plotting or any |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 // ui* calls, but it will be a little faster to start and |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 // require less memory. Don't pass the --no-gui-libs option |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 // on as that option is not recognized by Octave. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
251 gui_libs = false; |
21284
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
252 file = octave_cli; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 else if (! strcmp (argv[i], "--no-gui")) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 // If we see this option, then we can just exec octave; we |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 // don't have to create a child process and wait for it to |
18152
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
258 // exit. But do exec "octave-gui", not "octave-cli", because |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
259 // even if the --no-gui option is given, we may be asked to do |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
260 // some plotting or ui* calls. |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 |
18014
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
262 start_gui = false; |
6df05f2fd354
maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents:
18008
diff
changeset
|
263 new_argv[k++] = argv[i]; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 } |
25187
9bb58f9580f4
restore proper handling of the --force-gui option (bug #53536)
Mike Miller <mtmiller@octave.org>
parents:
25068
diff
changeset
|
265 else if (! strcmp (argv[i], "--gui") || ! strcmp (argv[i], "--force-gui")) |
24898
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
266 { |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
267 // If we see this option, then we fork and exec octave with |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
268 // the --gui option, while continuing to handle signals in the |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
269 // terminal. |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
270 |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
271 start_gui = true; |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
272 new_argv[k++] = argv[i]; |
91331c76d9c1
invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
273 } |
23767
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
274 else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet")) |
18010
dc58d4810de6
main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents:
18007
diff
changeset
|
275 { |
dc58d4810de6
main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents:
18007
diff
changeset
|
276 warn_display = false; |
dc58d4810de6
main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents:
18007
diff
changeset
|
277 new_argv[k++] = argv[i]; |
dc58d4810de6
main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents:
18007
diff
changeset
|
278 } |
23767
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
279 else if (! strcmp (argv[i], "--no-window-system")) |
21783
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
280 { |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
281 no_display = true; |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
282 new_argv[k++] = argv[i]; |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
283 } |
23767
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
284 else if (strlen (argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] != '-') |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
285 { |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
286 // Handle all single-letter command line options here; they may |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
287 // occur alone or may be aggregated into a single argument. |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
288 |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
289 size_t len = strlen (argv[i]); |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
290 |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
291 for (size_t j = 1; j < len; j++) |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
292 switch (argv[i][j]) |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
293 { |
27934
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
294 case 'W': |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
295 no_display = true; |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
296 break; |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
297 case 'q': |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
298 warn_display = false; |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
299 break; |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
300 default: |
49a0d90cd2a3
maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
301 break; |
23767
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
302 } |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
303 |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
304 new_argv[k++] = argv[i]; |
2387ce427601
improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents:
23712
diff
changeset
|
305 } |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
307 new_argv[k++] = argv[i]; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
308 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
309 |
25068
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
310 // At this point, gui_libs and start_gui are just about options, not |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
311 // the environment. Exit if they don't make sense. |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
312 |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
313 if (start_gui) |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
314 { |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
315 if (! gui_libs) |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
316 { |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
317 std::cerr << "octave: conflicting options: --no-gui-libs and --gui" |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
318 << std::endl; |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
319 return 1; |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
320 } |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
321 |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
322 #if ! defined (HAVE_OCTAVE_QT_GUI) |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
323 std::cerr << "octave: GUI features missing or disabled in this build" |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
324 << std::endl; |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
325 return 1; |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
326 #endif |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
327 } |
53440f9bffba
disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
328 |
23796
4f12819a634f
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23767
diff
changeset
|
329 new_argv[k] = nullptr; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
330 |
21783
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
331 if (no_display) |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
332 { |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
333 start_gui = false; |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
334 gui_libs = false; |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
335 |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
336 file = octave_cli; |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
337 } |
58a4c5633efd
Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
338 else if (gui_libs || start_gui) |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
339 { |
19785
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
340 int dpy_avail; |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
341 |
19785
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
342 const char *display_check_err_msg = display_available (&dpy_avail); |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
343 |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
344 if (! dpy_avail) |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
345 { |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
346 start_gui = false; |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
347 gui_libs = false; |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
348 |
21284
1bbd799ac7c7
Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents:
19861
diff
changeset
|
349 file = octave_cli; |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
350 |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
351 if (warn_display) |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
352 { |
19785
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
353 if (! display_check_err_msg) |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
354 display_check_err_msg = "graphical display unavailable"; |
299fe39163a2
avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
355 |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
356 std::cerr << "octave: " << display_check_err_msg << std::endl; |
18052
0c4a2e95c768
Correct typo in error message when no DISPLAY var set.
Rik <rik@octave.org>
parents:
18012
diff
changeset
|
357 std::cerr << "octave: disabling GUI features" << std::endl; |
17994
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
358 } |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
359 } |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
360 } |
a99b7d656a6c
start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents:
17959
diff
changeset
|
361 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
362 #if defined (OCTAVE_USE_WINDOWS_API) |
18152
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
363 file += ".exe"; |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
364 #endif |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
365 |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
366 new_argv[0] = strsave (file.c_str ()); |
91a3858ef8cf
invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents:
18052
diff
changeset
|
367 |
24520
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
368 // The Octave interpreter may be multithreaded. If so, we attempt to |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
369 // ensure that signals are delivered to the main interpreter thread |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
370 // and no others by blocking signals before we exec the Octave |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
371 // interpreter executable. When that process starts, it will unblock |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
372 // signals in the main interpreter thread. When running the GUI as a |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
373 // subprocess, we also unblock signals that the parent process handles |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
374 // so we can forward them to the child. |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
375 |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
376 octave_block_async_signals (); |
26826
20881d195d20
fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
377 octave_block_signal_by_name ("SIGTSTP"); |
24520
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
378 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
379 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API) |
17813
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
380 |
23194
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
381 if (gui_libs && start_gui) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 { |
23194
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
383 // Fork and exec when starting the GUI so that we will call |
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
384 // setsid to give up the controlling terminal (if any) and so that |
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
385 // the GUI process will be in a separate process group. |
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
386 // |
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
387 // The GUI process must be in a separate process group so that we |
23196
b93e1d29790e
* main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents:
23194
diff
changeset
|
388 // can send an interrupt signal to all child processes when |
b93e1d29790e
* main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents:
23194
diff
changeset
|
389 // interrupting the interpreter. See also bug #49609 and the |
b93e1d29790e
* main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents:
23194
diff
changeset
|
390 // function pthread_thread_manager::interrupt in the file |
b93e1d29790e
* main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents:
23194
diff
changeset
|
391 // libgui/src/thread-manager.cc. |
23194
c897282f1ec8
always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
392 |
21927
6f62bd248919
use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents:
21921
diff
changeset
|
393 gui_pid = octave_fork_wrapper (); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
394 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 if (gui_pid < 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 std::cerr << "octave: fork failed!" << std::endl; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
399 retval = 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 else if (gui_pid == 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
402 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 // Child. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 |
21927
6f62bd248919
use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents:
21921
diff
changeset
|
405 if (octave_setsid_wrapper () < 0) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 std::cerr << "octave: error calling setsid!" << std::endl; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 retval = 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 } |
18722
f8203daed9d4
Abort Octave GUI if setsid() fails after fork().
Rik <rik@octave.org>
parents:
18361
diff
changeset
|
411 else |
f8203daed9d4
Abort Octave GUI if setsid() fails after fork().
Rik <rik@octave.org>
parents:
18361
diff
changeset
|
412 retval = octave_exec (file, new_argv); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 { |
18007
25b6fbe82827
Make the CLI the default for the 3.8 release.
Rik <rik@octave.org>
parents:
18006
diff
changeset
|
416 // Parent. Forward signals to child while waiting for it to exit. |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 |
24520
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
418 install_signal_handlers (); |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
419 |
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
420 octave_unblock_async_signals (); |
26826
20881d195d20
fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
421 octave_unblock_signal_by_name ("SIGTSTP"); |
24520
c5c11b07598a
refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents:
24163
diff
changeset
|
422 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 int status; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
424 |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
425 while (true) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 { |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
427 octave_waitpid_wrapper (gui_pid, &status, 0); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
429 if (caught_signal > 0) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 { |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
431 int sig = caught_signal; |
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
432 |
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
433 caught_signal = -1; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21927
diff
changeset
|
435 octave_kill_wrapper (gui_pid, sig); |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
436 } |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
437 else if (octave_wifexited_wrapper (status)) |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
438 { |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
439 retval = octave_wexitstatus_wrapper (status); |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
440 break; |
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
441 } |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
442 else if (octave_wifsignaled_wrapper (status)) |
17865
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
443 { |
dde06c2ac6c6
improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents:
17814
diff
changeset
|
444 std::cerr << "octave exited with signal " |
21921
ecfcc8527661
hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents:
21783
diff
changeset
|
445 << octave_wtermsig_wrapper (status) << std::endl; |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
446 break; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 } |
17801
0b81d65d3c49
only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents:
17789
diff
changeset
|
451 else |
21949
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
452 { |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
453 retval = octave_exec (file, new_argv); |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
454 |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
455 if (retval < 0) |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
456 std::cerr << argv[0] << ": " << std::strerror (errno) << std::endl; |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
457 } |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 |
17813
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
459 #else |
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
460 |
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
461 retval = octave_exec (file, new_argv); |
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
462 |
21949
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
463 if (retval < 0) |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
464 std::cerr << argv[0] << ": " << std::strerror (errno) << std::endl; |
baeffde5c87d
fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents:
21944
diff
changeset
|
465 |
17813
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
466 #endif |
0a887758d1cc
fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents:
17805
diff
changeset
|
467 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 return retval; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 } |