mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 01:06:11 +00:00
fork two time, daemon unit
This commit is contained in:
parent
21fc1663ba
commit
f8ea392738
@ -1,6 +1,6 @@
|
||||
p sample_profiles/all_blue
|
||||
p /etc/g810-led/sample_profiles/all_blue
|
||||
w 1000
|
||||
p sample_profiles/all_green
|
||||
p /etc/g810-led/sample_profiles/all_green
|
||||
w 1000
|
||||
p sample_profiles/all_red
|
||||
p /etc/g810-led/sample_profiles/all_red
|
||||
w 1000
|
||||
|
@ -17,16 +17,35 @@ namespace daemonizer {
|
||||
|
||||
void start(char *arg0, std::string scenarioFile) {
|
||||
pid_t pid, sid;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) exit(EXIT_FAILURE);
|
||||
if (pid > 0) exit(EXIT_SUCCESS);
|
||||
sid = setsid();
|
||||
if (sid < 0) exit(EXIT_FAILURE);
|
||||
signal(SIGCHLD,SIG_IGN); /* ignore child */
|
||||
signal(SIGHUP,SIG_IGN); /* ignore child */
|
||||
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) exit(EXIT_FAILURE);
|
||||
if (pid > 0) exit(EXIT_SUCCESS);
|
||||
umask(0);
|
||||
sid = setsid();
|
||||
if (sid < 0) exit(EXIT_FAILURE);
|
||||
if (chdir("/") < 0) exit(EXIT_FAILURE);
|
||||
|
||||
//signal(SIGINT, stop);
|
||||
std::cout<<getpid()<<std::endl;
|
||||
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
signal(SIGCHLD,SIG_IGN); /* ignore child */
|
||||
signal(SIGHUP,SIG_IGN); /* ignore child */
|
||||
signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
|
||||
signal(SIGTTOU,SIG_IGN);
|
||||
signal(SIGTTIN,SIG_IGN);
|
||||
//signal(SIGINT, stop);
|
||||
|
||||
LedKeyboard kbd;
|
||||
kbd.open();
|
||||
while(true){
|
||||
|
@ -2,10 +2,11 @@
|
||||
Description=Logitech G810 Led Scenarios
|
||||
|
||||
[Service]
|
||||
#ExecStart=/usr/bin/g810-led --daemon /etc/g810-led/scenario
|
||||
#ExecSop=kill -2 pid
|
||||
#Type=oneshot
|
||||
#RemainAfterExit=yes
|
||||
ExecStartPre=/usr/bin/cp /etc/g810-led/scenario /tmp/g810-led-scenario
|
||||
ExecStartPre=/usr/bin/chmod 666 /tmp/g810-led-scenario
|
||||
ExecStart=/usr/bin/g810-led --daemon /tmp/g810-led-scenario
|
||||
ExecStopPost=/usr/bin/rm /tmp/g810-led-scenario
|
||||
Type=forking
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
Loading…
Reference in New Issue
Block a user