Hello,
I caught discussion about select() somewhere - monitored file-descriptor
should be in non blocking mode to be sure, that IO on it not block (even
the select() returns it can do IO). Descriptor ptymaster already was in
non blocking mode, but stdin & stdout not. Attached patch:
    * do set non blocking operation mode for stdin & stdout
    * adds static modifier for local functions.
Regards
-- 
Zito
30a31
> #include <string.h>
91c92
< void tty_atexit(void)
---
> static void tty_atexit(void)
115c116
< void ringbuf_init(struct ring_buffer *b, char *buf, size_t size)
---
> static void ringbuf_init(struct ring_buffer *b, char *buf, size_t size)
122c123
< int ringbuf_isempty(struct ring_buffer *b)
---
> static int ringbuf_isempty(struct ring_buffer *b)
127c128
< size_t ringbuf_space(struct ring_buffer *b)
---
> static size_t ringbuf_space(struct ring_buffer *b)
136c137
< size_t ringbuf_chunk_size(struct ring_buffer *b)
---
> static size_t ringbuf_chunk_size(struct ring_buffer *b)
145c146
< ssize_t ringbuf_read(struct ring_buffer *b, int fd)
---
> static ssize_t ringbuf_read(struct ring_buffer *b, int fd)
157c158
< ssize_t ringbuf_write(struct ring_buffer *b, int fd)
---
> static ssize_t ringbuf_write(struct ring_buffer *b, int fd)
169c170,187
< void sigchld_handler(int asig __attribute__ ((unused)))
---
> static void setfd_nonblock(int fd)
> {
> 	int fsflags = fcntl(fd, F_GETFL);
> 
> 	if (fsflags < 0) {
> 		fprintf(stderr, "fcntl(%d, F_GETFL): %s\n",
> 				fd, strerror(errno));
> 		exit(EX_IOERR);
> 	}
> 
> 	if (fcntl(STDIN_FILENO, F_SETFL, fsflags | O_NONBLOCK) < 0) {
> 		fprintf(stderr, "fcntl(%d, F_SETFL, ... | O_NONBLOCK): %s\n",
> 				fd, strerror(errno));
> 		exit(EX_IOERR);
> 	}
> }
> 
> static void sigchld_handler(int asig __attribute__ ((unused)))
180d197
< 	int retval = 0;
247c264
< 	 * Read current file descriptor flags, preparing to do non blocking reads
---
> 	 * Non blocking mode for all file descriptors.
249,259c266,268
< 	retval = fcntl(pty_master, F_GETFL);
< 	if (retval < 0) {
< 		perror("fcntl(pty_master, F_GETFL)");
< 		exit(EX_IOERR);
< 	}
< 
< 	/* Set the connection to be non-blocking */
< 	if (fcntl(pty_master, F_SETFL, retval | O_NONBLOCK) < 0) {
< 		perror("fcntl(pty_master, F_SETFL, ... | O_NONBLOCK)");
< 		exit(1);
< 	}
---
> 	setfd_nonblock(pty_master);
> 	setfd_nonblock(STDIN_FILENO);
> 	setfd_nonblock(STDOUT_FILENO);

Reply via email to