Add status command
This commit is contained in:
parent
42eba25c9b
commit
3d4cbecc9b
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
# C++ generated headers
|
||||
*.gch
|
||||
|
||||
# IDE-specific
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
@ -54,6 +54,9 @@ int main(int argc, char** args)
|
||||
else if (arg == "debug")
|
||||
comfortable_swipe::service::debug();
|
||||
|
||||
else if (arg == "status")
|
||||
comfortable_swipe::service::status();
|
||||
|
||||
else /* if (arg == "help") */
|
||||
comfortable_swipe::service::help();
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "service/help.cpp"
|
||||
#include "service/restart.cpp"
|
||||
#include "service/start.cpp"
|
||||
#include "service/status.cpp"
|
||||
#include "service/stop.cpp"
|
||||
#include "util/autostart_filename.cpp"
|
||||
#include "util/conf_filename.cpp"
|
||||
|
||||
@ -54,6 +54,7 @@ extern "C"
|
||||
void help();
|
||||
void restart();
|
||||
void start();
|
||||
void status();
|
||||
void stop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ namespace comfortable_swipe::service
|
||||
std::puts("buffer - parses output of libinput debug-events");
|
||||
std::puts("help - shows the help dialog");
|
||||
std::puts("debug - logs raw output from input events taken from libinput");
|
||||
std::puts("status - checks status of program and autostart");
|
||||
std::puts("");
|
||||
std::printf("Configuration file can be found in %s\n", conf_filename());
|
||||
}
|
||||
|
||||
58
lib/service/status.cpp
Normal file
58
lib/service/status.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef __COMFORTABLE_SWIPE__service_status__
|
||||
#define __COMFORTABLE_SWIPE__service_status__
|
||||
|
||||
/*
|
||||
Comfortable Swipe
|
||||
by Rico Tiongson
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../index.hpp"
|
||||
#include <stdexcept> // std::runtime_error
|
||||
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
||||
#include <memory> // std::unique_ptr
|
||||
#include <array> // std::array
|
||||
#include <cstdlib> // std::atoi
|
||||
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||
|
||||
namespace comfortable_swipe::service
|
||||
{
|
||||
/**
|
||||
* Restarts the comfortable-swipe service.
|
||||
*/
|
||||
void status()
|
||||
{
|
||||
// check if comfortable-swipe is running
|
||||
bool running = false;
|
||||
std::array<char, 128> buffer;
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
||||
if (pipe && !std::feof(pipe.get()) && std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
|
||||
{
|
||||
int pid = std::atoi(buffer.data());
|
||||
if (pid != getpid())
|
||||
running = true;
|
||||
}
|
||||
|
||||
// check if autostart is on
|
||||
auto autostart_f = comfortable_swipe::util::autostart_filename();
|
||||
bool autostart_on = access(autostart_f, F_OK) != -1;
|
||||
|
||||
// print status
|
||||
std::printf("program is %s\n", running ? "ON" : "OFF");
|
||||
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
||||
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <unistd.h> // popen, pclose, getpid
|
||||
#include <memory> // std::unique_ptr
|
||||
#include <array> // std::array
|
||||
#include <cstdlib> // std::atoi
|
||||
#include <cstdio> // FILE, std::feof, std::fgets
|
||||
|
||||
namespace comfortable_swipe::service
|
||||
|
||||
Loading…
Reference in New Issue
Block a user