summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-09-15 20:46:23 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-09-15 20:46:23 -0500
commit34a301ab0c026b79e84d164ed44088dfaec00c15 (patch)
tree79bab31301b25d44e1c17c6bfb03d5bffdc96898
parent5714610dffbf32ac48caacf68677a40b4b0f722e (diff)
downloadtde-34a301ab0c026b79e84d164ed44088dfaec00c15.tar.gz
tde-34a301ab0c026b79e84d164ed44088dfaec00c15.zip
Make tsak a bit more robust
-rw-r--r--experimental/tsak/main.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/experimental/tsak/main.cpp b/experimental/tsak/main.cpp
index d7ba23b25..0cbfa3751 100644
--- a/experimental/tsak/main.cpp
+++ b/experimental/tsak/main.cpp
@@ -49,7 +49,7 @@ int mPipe_fd_out;
struct sigaction usr_action;
sigset_t block_mask;
-char *keycode[256] =
+const char *keycode[256] =
{
"", "<esc>", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "0", "−", "=", "<backspace>", "<tab>", "q", "w", "e", "r",
@@ -144,7 +144,6 @@ void tearDownPipe()
void setupPipe()
{
-
/* Create the FIFOs if they do not exist */
umask(0);
mkdir(FIFO_DIR,0644);
@@ -158,11 +157,21 @@ void setupPipe()
}
}
-void handle_sigterm (int sig)
+class PipeHandler
+{
+public:
+ PipeHandler();
+ ~PipeHandler();
+};
+
+PipeHandler::PipeHandler()
+{
+ setupPipe();
+}
+
+PipeHandler::~PipeHandler()
{
tearDownPipe();
- exit(0);
- return;
}
int main (int argc, char *argv[])
@@ -176,15 +185,9 @@ int main (int argc, char *argv[])
bool alt_down = false;
bool hide_event = false;
- // Initialize signal handlers
- sigfillset(&block_mask);
- usr_action.sa_handler = handle_sigterm;
- usr_action.sa_mask = block_mask;
- usr_action.sa_flags = 0;
- sigaction(SIGTERM, &usr_action, NULL);
+ // Create the output pipe
+ PipeHandler controlpipe;
- atexit(tearDownPipe);
-
if ((getuid ()) != 0) {
printf ("You are not root! This WILL NOT WORK!\nDO NOT attempt to bypass security restrictions, e.g. by changing keyboard permissions or owner, if you want the SAK system to remain secure...\n");
return 5;
@@ -230,9 +233,6 @@ int main (int argc, char *argv[])
fprintf(stderr, "Failed to grab exclusive input device lock");
return 1;
}
-
- // Create the output pipe
- setupPipe();
while (1) {
@@ -276,7 +276,5 @@ int main (int argc, char *argv[])
}
}
- tearDownPipe();
-
return 0;
}