Skip to content

Commit

Permalink
fixed a stupid bug. 1-byte commands were read through the pipe, into an
Browse files Browse the repository at this point in the history
int, with the high order bits uninitialized, leading to bogus commands,
which where silently ignored.



git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spnavcfg@49 ef983eb1-d774-4af8-acfd-baaf7b16a646
  • Loading branch information
jtsiomb committed Oct 19, 2008
1 parent c883191 commit 70f1a3c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions back.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ int backend(int pfd)
int cmd, tmp;

/* get command */
cmd = 0;
if(read(pfd, &cmd, 1) == -1 && errno != EINTR) {
perror("pipe read blew up in my face! wtf");
return -1;
}

switch(cmd) {
case CMD_PING:
printf("got CMD_PING\n");
tmp = (dpid = get_daemon_pid()) != -1;
write(pfd, &tmp, 1);
break;

case CMD_CFG:
printf("got CMD_CFG\n");
{
char *buf = (char*)&cfg;
int sz = sizeof cfg;
Expand All @@ -68,7 +71,9 @@ int backend(int pfd)
break;

case CMD_STARTX:
printf("got CMD_STARTX\n");
case CMD_STOPX:
printf("got CMD_STOPX\n");
if(dpid == -1) {
if((dpid = get_daemon_pid()) == -1) {
return -1;
Expand All @@ -83,6 +88,7 @@ int backend(int pfd)
break;

default:
printf("unknown CMD: %d\n", (int)cmd);
break;
}
}
Expand Down Expand Up @@ -112,6 +118,7 @@ int get_daemon_pid(void)
static int update_cfg(void)
{
if(write_cfg(CFGFILE, &cfg) == -1) {
fprintf(stderr, "failed to update config file\n");
return -1;
}

Expand Down

0 comments on commit 70f1a3c

Please sign in to comment.