]>
Dogcows Code - chaz/openbox/blob - util/epist/main.cc
7c7d58407053c95ffc1f8a4fea5a0f54c27047f5
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // main.cc for Epistory - a key handler for NETWM/EWMH window managers.
3 // Copyright (c) 2002 - 2002 Ben Jansens <ben at orodu.net>
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
24 # include "../../config.h"
25 #endif // HAVE_CONFIG_H
29 # include <sys/types.h>
31 #endif // HAVE_UNISTD_H
35 #endif // HAVE_SIGNAL_H
37 #ifdef HAVE_SYS_SIGNAL_H
38 # include <sys/signal.h>
39 #endif // HAVE_SYS_SIGNAL_H
43 #endif // HAVE_LIBGEN_H
51 bool _shutdown
= false;
55 static void signalhandler(int sig
)
56 #else // HAVE_SIGACTION
57 static RETSIGTYPE
signalhandler(int sig
)
58 #endif // HAVE_SIGACTION
62 cout
<< "Segmentation fault. Aborting and dumping core.\n";
65 cout
<< "Restarting on request.\n";
66 execvp(_argv
[0], _argv
);
67 execvp(basename(_argv
[0]), _argv
);
71 #ifndef HAVE_SIGACTION
72 // assume broken, braindead sysv signal semantics
73 signal(sig
, (RETSIGTYPE (*)(int)) signalhandler
);
74 #endif // HAVE_SIGACTION
77 int main(int, char **argv
) {
81 struct sigaction action
;
83 action
.sa_handler
= signalhandler
;
84 action
.sa_mask
= sigset_t();
85 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
87 sigaction(SIGPIPE
, &action
, NULL
);
88 sigaction(SIGSEGV
, &action
, NULL
);
89 sigaction(SIGFPE
, &action
, NULL
);
90 sigaction(SIGTERM
, &action
, NULL
);
91 sigaction(SIGINT
, &action
, NULL
);
92 sigaction(SIGHUP
, &action
, NULL
);
93 #else // !HAVE_SIGACTION
94 signal(SIGPIPE
, (RETSIGTYPE (*)(int)) signalhandler
);
95 signal(SIGSEGV
, (RETSIGTYPE (*)(int)) signalhandler
);
96 signal(SIGFPE
, (RETSIGTYPE (*)(int)) signalhandler
);
97 signal(SIGTERM
, (RETSIGTYPE (*)(int)) signalhandler
);
98 signal(SIGINT
, (RETSIGTYPE (*)(int)) signalhandler
);
99 signal(SIGHUP
, (RETSIGTYPE (*)(int)) signalhandler
);
100 #endif // HAVE_SIGACTION
102 while (! _shutdown
) {
This page took 0.035476 seconds and 3 git commands to generate.