return fd;
}
-int send_command(int ttyusb_fd, cmd_t* cmd)
+int send_command(int door_fd, cmd_t* cmd)
{
if(!cmd)
return -1;
int ret;
do {
- ret = write(ttyusb_fd, &c, 1);
+ ret = write(door_fd, &c, 1);
}
while(!ret);
- if(ret > 0)
+ if(ret > 0) {
+ cmd->sent = 1;
return 0;
+ }
return ret;
}
return 0;
}
-int process_ttyusb(int ttyusb_fd, cmd_t **cmd_q)
+int process_door(int door_fd, cmd_t **cmd_q)
{
static char buffer[100];
int ret = 0;
do {
memset(buffer, 0, 100);
- ret = read(ttyusb_fd, buffer, sizeof(buffer));
+ ret = read(door_fd, buffer, sizeof(buffer));
if(!ret)
return 2;
} while (ret == -1 && errno == EINTR);
- log_printf(INFO, "processing data from ttyusb (fd=%d)", ttyusb_fd);
+ log_printf(INFO, "processing data from door (fd=%d)", door_fd);
return 0;
}
-int main_loop(int ttyusb_fd, int cmd_listen_fd)
+int main_loop(int door_fd, int cmd_listen_fd)
{
log_printf(INFO, "entering main loop");
fd_set readfds, tmpfds;
FD_ZERO(&readfds);
- FD_SET(ttyusb_fd, &readfds);
+ FD_SET(door_fd, &readfds);
FD_SET(cmd_listen_fd, &readfds);
- int max_fd = ttyusb_fd > cmd_listen_fd ? ttyusb_fd : cmd_listen_fd;
+ int max_fd = door_fd > cmd_listen_fd ? door_fd : cmd_listen_fd;
cmd_t* cmd_q = NULL;
signal_init();
break;
}
- if(FD_ISSET(ttyusb_fd, &tmpfds)) {
- return_value = process_ttyusb(ttyusb_fd, &cmd_q);
+ if(FD_ISSET(door_fd, &tmpfds)) {
+ return_value = process_door(door_fd, &cmd_q);
if(return_value)
break;
- FD_CLR(ttyusb_fd, &tmpfds);
+ FD_CLR(door_fd, &tmpfds);
}
if(FD_ISSET(cmd_listen_fd, &tmpfds)) {
break;
if(cmd_q && !cmd_q->sent)
- send_command(ttyusb_fd, cmd_q);
+ send_command(door_fd, cmd_q);
}
}
}
fclose(pid_file);
}
- int ttyusb_fd = open(opt.ttyusb_dev_, O_RDWR);
- if(ttyusb_fd < 0) {
- log_printf(ERROR, "unable to open %s: %s", opt.ttyusb_dev_, strerror(errno));
+ int door_fd = open(opt.door_dev_, O_RDWR);
+ if(door_fd < 0) {
+ log_printf(ERROR, "unable to open %s: %s", opt.door_dev_, strerror(errno));
options_clear(&opt);
log_close();
exit(-1);
int cmd_listen_fd = init_command_socket(opt.command_sock_);
if(cmd_listen_fd < 0) {
- close(ttyusb_fd);
+ close(door_fd);
options_clear(&opt);
log_close();
exit(-1);
}
- ret = main_loop(ttyusb_fd, cmd_listen_fd);
+ ret = main_loop(door_fd, cmd_listen_fd);
close(cmd_listen_fd);
- close(ttyusb_fd);
+ close(door_fd);
if(!ret)
log_printf(NOTICE, "normal shutdown");
else if(ret < 0)
log_printf(NOTICE, "shutdown after error");
else if(ret == 2)
- log_printf(ERROR, "shutdown after %s read error", opt.ttyusb_dev_);
+ log_printf(ERROR, "shutdown after %s read error", opt.door_dev_);
else
log_printf(NOTICE, "shutdown after signal");
PARSE_STRING_PARAM("-C","--chroot", opt->chroot_dir_)
PARSE_STRING_PARAM("-P","--write-pid", opt->pid_file_)
PARSE_STRING_LIST("-L","--log", opt->log_targets_)
- PARSE_STRING_PARAM("-d","--device", opt->ttyusb_dev_)
+ PARSE_STRING_PARAM("-d","--device", opt->door_dev_)
PARSE_STRING_PARAM("-s","--socket", opt->command_sock_)
else
return i;
opt->pid_file_ = NULL;
string_list_init(&opt->log_targets_);
- opt->ttyusb_dev_ = strdup("/dev/ttyUSB0");
+ opt->door_dev_ = strdup("/dev/ttyUSB0");
opt->command_sock_ = strdup("/var/run/door_daemon");
}
free(opt->pid_file_);
string_list_clear(&opt->log_targets_);
- if(opt->ttyusb_dev_)
- free(opt->ttyusb_dev_);
+ if(opt->door_dev_)
+ free(opt->door_dev_);
if(opt->command_sock_)
free(opt->command_sock_);
}
printf("log_targets: \n");
string_list_print(&opt->log_targets_, " '", "'\n");
- printf("ttyusb_dev: '%s'\n", opt->ttyusb_dev_);
+ printf("door_dev: '%s'\n", opt->door_dev_);
printf("command_sock: '%s'\n", opt->command_sock_);
}