slcanpty: probe stdin capabilities at startup
/dev/null returns EOF therefore select() finishes immediately. Now EOF is probed on start. Other /dev/null as stdin workarounds: - lscanpty ... < /dev/ptmx (dirty but works) - cat </dev/null | slcanpty ... (doesn't work for me and even the patch is "disabled" then) Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/1/head
parent
d469336649
commit
c05267faca
31
slcanpty.c
31
slcanpty.c
|
|
@ -64,7 +64,7 @@ static int asc2nibble(char c)
|
||||||
|
|
||||||
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
/* read data from pty, send CAN frames to CAN socket and answer commands */
|
||||||
int pty2can(int pty, int socket, struct can_filter *fi,
|
int pty2can(int pty, int socket, struct can_filter *fi,
|
||||||
int *is_open, int *tstamp)
|
int *is_open, int *tstamp)
|
||||||
{
|
{
|
||||||
int nbytes;
|
int nbytes;
|
||||||
char cmd;
|
char cmd;
|
||||||
|
|
@ -386,6 +386,27 @@ int can2pty(int pty, int socket, int *tstamp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int check_select_stdin(void)
|
||||||
|
{
|
||||||
|
fd_set rdfs;
|
||||||
|
struct timeval timeout;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
FD_ZERO(&rdfs);
|
||||||
|
FD_SET(0, &rdfs);
|
||||||
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
|
ret = select(1, &rdfs, NULL, NULL, &timeout);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
return 0; /* not selectable */
|
||||||
|
|
||||||
|
if (ret > 0 && getchar() == EOF)
|
||||||
|
return 0; /* EOF, eg. /dev/null */
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -395,6 +416,7 @@ int main(int argc, char **argv)
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
struct termios topts;
|
struct termios topts;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
int select_stdin = 0;
|
||||||
int running = 1;
|
int running = 1;
|
||||||
int tstamp = 0;
|
int tstamp = 0;
|
||||||
int is_open = 0;
|
int is_open = 0;
|
||||||
|
|
@ -416,6 +438,8 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select_stdin = check_select_stdin();
|
||||||
|
|
||||||
/* open pty */
|
/* open pty */
|
||||||
p = open(argv[1], O_RDWR);
|
p = open(argv[1], O_RDWR);
|
||||||
if (p < 0) {
|
if (p < 0) {
|
||||||
|
|
@ -489,7 +513,10 @@ int main(int argc, char **argv)
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|
||||||
FD_ZERO(&rdfs);
|
FD_ZERO(&rdfs);
|
||||||
FD_SET(0, &rdfs);
|
|
||||||
|
if (select_stdin)
|
||||||
|
FD_SET(0, &rdfs);
|
||||||
|
|
||||||
FD_SET(p, &rdfs);
|
FD_SET(p, &rdfs);
|
||||||
FD_SET(s, &rdfs);
|
FD_SET(s, &rdfs);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue