]>
Dogcows Code - chaz/openbox/blob - util/epist/main.cc
c7c1a768663c2349db7902e1a46d18d6c465f228
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
31 # include <sys/types.h>
33 #endif // HAVE_UNISTD_H
37 #endif // HAVE_SIGNAL_H
39 #ifdef HAVE_SYS_SIGNAL_H
40 # include <sys/signal.h>
41 #endif // HAVE_SYS_SIGNAL_H
45 #endif // HAVE_LIBGEN_H
53 bool _shutdown
= false;
55 char *_display_name
= 0;
56 Display
*_display
= 0;
59 static void signalhandler(int sig
)
60 #else // HAVE_SIGACTION
61 static RETSIGTYPE
signalhandler(int sig
)
62 #endif // HAVE_SIGACTION
66 cout
<< "Segmentation fault. Aborting and dumping core.\n";
69 cout
<< "Restarting on request.\n";
70 execvp(_argv
[0], _argv
);
71 execvp(basename(_argv
[0]), _argv
);
75 #ifndef HAVE_SIGACTION
76 // assume broken, braindead sysv signal semantics
77 signal(sig
, (RETSIGTYPE (*)(int)) signalhandler
);
78 #endif // HAVE_SIGACTION
82 int main(int, char **argv
) {
86 struct sigaction action
;
88 action
.sa_handler
= signalhandler
;
89 action
.sa_mask
= sigset_t();
90 action
.sa_flags
= SA_NOCLDSTOP
| SA_NODEFER
;
92 sigaction(SIGPIPE
, &action
, NULL
);
93 sigaction(SIGSEGV
, &action
, NULL
);
94 sigaction(SIGFPE
, &action
, NULL
);
95 sigaction(SIGTERM
, &action
, NULL
);
96 sigaction(SIGINT
, &action
, NULL
);
97 sigaction(SIGHUP
, &action
, NULL
);
98 #else // !HAVE_SIGACTION
99 signal(SIGPIPE
, (RETSIGTYPE (*)(int)) signalhandler
);
100 signal(SIGSEGV
, (RETSIGTYPE (*)(int)) signalhandler
);
101 signal(SIGFPE
, (RETSIGTYPE (*)(int)) signalhandler
);
102 signal(SIGTERM
, (RETSIGTYPE (*)(int)) signalhandler
);
103 signal(SIGINT
, (RETSIGTYPE (*)(int)) signalhandler
);
104 signal(SIGHUP
, (RETSIGTYPE (*)(int)) signalhandler
);
105 #endif // HAVE_SIGACTION
107 _display
= XOpenDisplay(_display_name
);
109 cout
<< "Connection to X server '" << _display_name
<< "' failed.\n";
113 while (! _shutdown
) {
117 XCloseDisplay(_display
);
This page took 0.037438 seconds and 4 git commands to generate.