Be able to run as a daemon and add mouse acceleration

This commit is contained in:
dschmenk 2013-05-23 13:52:08 -07:00
parent 3a3d5efe3f
commit fae3f98490

View File

@ -379,7 +379,7 @@ void sendrelxy(int fd, int x, int y)
void prlog(char *str) void prlog(char *str)
{ {
if (!isdaemon) if (!isdaemon)
fprintf(stderr, str); printf(str);
} }
void main(int argc, char **argv) void main(int argc, char **argv)
{ {
@ -389,6 +389,39 @@ void main(int argc, char **argv)
int i, lastbtn; int i, lastbtn;
int a2fd, kbdfd, moufd; int a2fd, kbdfd, moufd;
/*
* Are we running as a isdaemon?
*/
if ((argc > 1)/* && (strcmp(argv[1], "--daemon") == 8)*/)
{
pid_t pid, sid; /* our process ID and Session ID */
pid = fork(); /* fork off the parent process */
if (pid < 0)
die("a2pid: fork() failure");
/*
* If we got a good PID, then
* we can exit the parent process
*/
if (pid > 0)
exit(EXIT_SUCCESS);
umask(0); /* change the file mode mask */
/*
* Open any logs here
*/
sid = setsid(); /* create a new SID for the child process */
if (sid < 0)
die("a2pid: setsid() failure");
if ((chdir("/")) < 0) /* change the current working directory */
die("a2pid: chdir() failure");
/*
* Close out the standard file descriptors
*/
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
isdaemon = TRUE;
}
/* /*
* Create keyboard input device * Create keyboard input device
*/ */
@ -487,43 +520,11 @@ void main(int argc, char **argv)
prlog("a2pid: Connected.\n"); prlog("a2pid: Connected.\n");
a2event[0] = 0x81; /* acknowledge */ a2event[0] = 0x81; /* acknowledge */
write(a2fd, a2event, 1); write(a2fd, a2event, 1);
tcflush(a2fd, TCIFLUSH);
} }
else else
stop = TRUE; stop = TRUE;
} }
/*
* Are we running as a isdaemon?
*/
if ((argc > 1)/* && (strcmp(argv[1], "--daemon") == 8)*/)
{
pid_t pid, sid; /* our process ID and Session ID */
pid = fork(); /* fork off the parent process */
if (pid < 0)
die("a2pid: fork() failure");
/*
* If we got a good PID, then
* we can exit the parent process
*/
if (pid > 0)
exit(EXIT_SUCCESS);
umask(0); /* change the file mode mask */
/*
* Open any logs here
*/
sid = setsid(); /* create a new SID for the child process */
if (sid < 0)
die("a2pid: setsid() failure");
if ((chdir("/")) < 0) /* change the current working directory */
die("a2pid: chdir() failure");
/*
* Close out the standard file descriptors
*/
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
isdaemon = TRUE;
}
/* /*
* Event loop * Event loop
*/ */
@ -531,6 +532,7 @@ void main(int argc, char **argv)
{ {
if (read(a2fd, a2event, 3) == 3) if (read(a2fd, a2event, 3) == 3)
{ {
// printf("a2pi: [0x%02X] [0x%02X] [0x%02X] ", a2event[0], a2event[1], a2event[2]);
switch (a2event[0]) switch (a2event[0])
{ {
case 0x80: /* sync */ case 0x80: /* sync */