[feature-systemd] Fix autostart errors by handling Environment variables

This commit is contained in:
Rico Tiongson 2017-11-13 23:58:05 +08:00
parent 3969b69e12
commit f797290174
3 changed files with 31 additions and 8 deletions

View File

@ -48,6 +48,8 @@ fi
# install with g++ # install with g++
echo "Installing..." echo "Installing..."
echo "
Install $(date)" >> .log
echo "Running g++" >> .log echo "Running g++" >> .log
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM >> .log 2>> .log || exec echo "Installation aborted" g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM >> .log 2>> .log || exec echo "Installation aborted"
@ -56,10 +58,13 @@ SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service"
echo "[Unit] echo "[Unit]
Description=Comfortable 3 or 4 finger gestures Description=Comfortable 3 or 4 finger gestures
After=display-manager.service
[Service] [Service]
Environment=DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY Environment=DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY
ExecStart=/bin/sh -c '/usr/bin/stdbuf -oL -eL /usr/bin/libinput-debug-events | $PROGRAM buffer' ExecStart=$PROGRAM exec
Restart=always
RestartSec=2
[Install] [Install]
WantedBy=multi-user.target" \ WantedBy=multi-user.target" \

View File

@ -66,9 +66,10 @@ namespace service {
void buffer(); void buffer();
void start(); void start();
void stop(); void stop();
void status();
void restart(); void restart();
void autostart();
void help(); void help();
void exec();
} }
/* MAIN DRIVER FUNCTION */ /* MAIN DRIVER FUNCTION */
@ -79,8 +80,10 @@ int main(int argc, char** args) {
// select based on argument // select based on argument
if (arg == "start") service::start(); if (arg == "start") service::start();
else if (arg == "stop") service::stop(); else if (arg == "stop") service::stop();
else if (arg == "status") service::status();
else if (arg == "restart") service::restart(); else if (arg == "restart") service::restart();
else if (arg == "buffer") service::buffer(); else if (arg == "buffer") service::buffer();
else if (arg == "exec") service::exec();
else service::help(); else service::help();
} else { } else {
service::help(); service::help();
@ -192,6 +195,10 @@ namespace service {
} }
namespace service { namespace service {
void exec() {
sleep(1);
exit(system("/usr/bin/stdbuf -oL -eL /usr/bin/libinput-debug-events 2>&1 | " PROGRAM " buffer"));
}
// parses output from libinput-debug-events // parses output from libinput-debug-events
void buffer() { void buffer() {
// check first if $user // check first if $user
@ -216,6 +223,11 @@ namespace service {
config["down4"].c_str() config["down4"].c_str()
); );
while (getline(cin, sentence)) { while (getline(cin, sentence)) {
// exit on core dump
if (sentence.find("Segmentation fault") != string::npos)
exit(EXIT_FAILURE);
if (sentence.find("Error") != string::npos)
exit(EXIT_FAILURE);
auto data = sentence.data(); auto data = sentence.data();
cmatch matches; cmatch matches;
if (regex_match(data, matches, gesture_begin)) { if (regex_match(data, matches, gesture_begin)) {
@ -244,22 +256,27 @@ namespace service {
} }
// starts service // starts service
void start() { void start() {
int x = system("systemctl start comfortable-swipe.service"); exit(system("systemctl start comfortable-swipe.service"));
} }
// stops service // stops service
void stop() { void stop() {
int x = system("systemctl stop comfortable-swipe.service"); exit(system("systemctl stop comfortable-swipe.service"));
}
// shows the status of the program
void status() {
exit(system("systemctl status comfortable-swipe.service"));
} }
// stops then starts service // stops then starts service
void restart() { void restart() {
int x = system("systemctl restart comfortable-swipe.service"); exit(system("systemctl restart comfortable-swipe.service"));
} }
// shows help // shows help
void help() { void help() {
puts("comfortable-swipe [start|stop|restart|buffer|help]"); puts("comfortable-swipe [start|stop|status|restart|buffer|help]");
puts(""); puts("");
puts("start - starts 3/4-finger gesture service"); puts("start - starts 3/4-finger gesture service");
puts("stop - stops 3/4-finger gesture service"); puts("stop - stops 3/4-finger gesture service");
puts("status - shows the status of the program");
puts("restart - stops then starts 3/4-finger gesture service"); puts("restart - stops then starts 3/4-finger gesture service");
puts("buffer - parses output of libinput-debug-events"); puts("buffer - parses output of libinput-debug-events");
puts("help - shows the help dialog"); puts("help - shows the help dialog");

View File

@ -4,7 +4,8 @@ if [ $(id -u) != "0" ]; then
exit $? exit $?
fi fi
echo "Uninstalling..." echo "Uninstalling..."
echo "Uninstall $(date)" >> .log echo "
Uninstall $(date)" >> .log
# stop service # stop service
systemctl stop comfortable-swipe.service >> .log 2>> .log systemctl stop comfortable-swipe.service >> .log 2>> .log