# HG changeset patch # Parent 8bd783f18b985286bbfdbb83385692a004b7e613 diff -r 8bd783f18b98 dlight.nativeexecution/tools/PtySupport/src/error.c --- a/dlight.nativeexecution/tools/PtySupport/src/error.c Wed Sep 07 20:47:05 2011 +0400 +++ b/dlight.nativeexecution/tools/PtySupport/src/error.c Thu Sep 15 12:49:23 2011 +0400 @@ -1,15 +1,21 @@ #include "error.h" +extern const char* progname; + /* * Print a message and return to caller. * Caller specifies "errnoflag". */ static void err_doit(int errnoflag, int error, const char *fmt, va_list ap) { char buf[MAXLINE]; - vsnprintf(buf, MAXLINE, fmt, ap); + + snprintf(buf, MAXLINE, "%s: ", progname); + vsnprintf(buf + strlen(buf), MAXLINE, fmt, ap); + if (errnoflag) { snprintf(buf + strlen(buf), MAXLINE - strlen(buf), ": %s", strerror(error)); } + strcat(buf, "\n"); fflush(stdout); /* in case stdout and stderr are the same */ fputs(buf, stderr); diff -r 8bd783f18b98 dlight.nativeexecution/tools/PtySupport/src/loop.c --- a/dlight.nativeexecution/tools/PtySupport/src/loop.c Wed Sep 07 20:47:05 2011 +0400 +++ b/dlight.nativeexecution/tools/PtySupport/src/loop.c Thu Sep 15 12:49:23 2011 +0400 @@ -1,4 +1,5 @@ #include "loop.h" +#include "error.h" #include #include #include @@ -26,15 +27,18 @@ FD_SET(master_fd, &read_set); select_result = select(master_fd + 1, &read_set, NULL, NULL, NULL); + // interrupted select is ignored - see CR 7086177 + if (select_result == -1 && errno == EINTR) { + continue; + } + if (select_result == -1) { - printf("ERROR: poll failed\n"); - exit(1); + err_sys("poll failed\n"); } if (FD_ISSET(STDIN_FILENO, &read_set)) { if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { - printf("ERROR: read from stdin failed\n"); - exit(1); + err_sys("read from stdin failed\n"); } if (n == 0) { @@ -42,15 +46,13 @@ } if (write(master_fd, buf, n) == -1) { - printf("ERROR: write to master failed\n"); - exit(1); + err_sys("write to master failed\n"); } } if (FD_ISSET(master_fd, &read_set)) { if ((n = read(master_fd, buf, BUFSIZ)) == -1) { - printf("ERROR: read from master failed\n"); - exit(1); + err_sys("read from master failed\n"); } if (n == 0) { @@ -58,12 +60,12 @@ } if (write(STDOUT_FILENO, buf, n) == -1) { - printf("ERROR: write to stdout failed\n"); + err_sys("write to stdout failed\n"); exit(1); } } } - + return 0; } @@ -86,15 +88,18 @@ for (;;) { poll_result = poll((struct pollfd*) & fds, 2, INFTIM); + // interrupted poll is ignored - see CR 7086177 + if (poll_result == -1 && errno == EINTR) { + continue; + } + if (poll_result == -1) { - printf("ERROR: poll failed\n"); - exit(1); + err_sys("poll() failed in main_loop"); } if (fds[0].revents & POLLIN) { if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { - printf("ERROR: read from stdin failed\n"); - exit(1); + err_sys("read from stdin failed"); } if (n == 0) { @@ -109,15 +114,13 @@ } if (writen(master_fd, buf, n) == -1) { - printf("ERROR: write to master failed\n"); - exit(1); + err_sys("write to master failed\n"); } } if (fds[1].revents & POLLIN) { if ((n = read(master_fd, buf, BUFSIZ)) == -1) { - printf("ERROR: read from master failed\n"); - exit(1); + err_sys("read from master failed\n"); } if (n == 0) { @@ -125,8 +128,7 @@ } if (writen(STDOUT_FILENO, buf, n) == -1) { - printf("ERROR: write to stdout failed\n"); - exit(1); + err_sys("write to stdout failed\n"); } } @@ -145,7 +147,7 @@ return 1; } } - + return 0; } #endif @@ -154,7 +156,7 @@ const char *pos = ptr; size_t nleft = n; ssize_t nwritten; - + while (nleft > 0) { if ((nwritten = write(fd, pos, nleft)) < 0) { if (nleft == n) diff -r 8bd783f18b98 dlight.nativeexecution/tools/PtySupport/src/pty.c --- a/dlight.nativeexecution/tools/PtySupport/src/pty.c Wed Sep 07 20:47:05 2011 +0400 +++ b/dlight.nativeexecution/tools/PtySupport/src/pty.c Thu Sep 15 12:49:23 2011 +0400 @@ -2,7 +2,7 @@ * File: pty_start.c * Author: ak119685 * - * Created on 22 Апрель 2010 г., 12:32 + * Created on 22 ?????? 2010 ?., 12:32 */ #include "pty_fork.h" @@ -15,12 +15,15 @@ #include #include +#include + #if defined __CYGWIN__ && !defined WCONTINUED //added for compatibility with cygwin 1.5 #define WCONTINUED 0 #endif static void set_noecho(int); +const char* progname; /* * @@ -39,20 +42,21 @@ int idx; int nopt = 1; + progname = basename(argv[0]); + for (idx = 1; idx < argc; idx++) { if (argv[idx][0] == '-') { if (strcmp(argv[idx], "-p") == 0) { idx++; if (argv[idx] == NULL || argv[idx][0] == '\0') { - printf("ERROR missing pty after -p\n"); - exit(-1); + err_quit("missing pty after -p\n"); } pty = argv[idx]; nopt += 2; } else if (strcmp(argv[idx], "--env") == 0) { idx++; if (argv[idx] == NULL || argv[idx][0] == '\0') { - printf("ERROR missing variable=value pair after --env\n"); + err_quit("missing variable=value pair after --env\n"); exit(-1); } diff -r 8bd783f18b98 dlight.nativeexecution/tools/pty_open.c --- a/dlight.nativeexecution/tools/pty_open.c Wed Sep 07 20:47:05 2011 +0400 +++ b/dlight.nativeexecution/tools/pty_open.c Thu Sep 15 12:49:23 2011 +0400 @@ -50,18 +50,17 @@ #if !defined __APPLE__ && !defined __CYGWIN__ #include -#include -#include #else #include -#include #endif #include #include #include #include +#include #include +#include static int ptm_open(void) { int masterfd; @@ -182,15 +181,6 @@ ssize_t n; char buf[BUFSIZ]; struct pollfd fds[2]; - char control_buf [BUFSIZ]; - char data_buf [BUFSIZ]; - int flags; - struct strbuf control; - struct strbuf data; - struct iocblk *ioc; - struct termios *term; - unsigned char msg_type; - fds[0].fd = STDIN_FILENO; fds[0].events = POLLIN; @@ -199,20 +189,18 @@ fds[1].events = POLLIN; fds[1].revents = 0; - - control.buf = control_buf; - control.maxlen = BUFSIZ; - data.buf = data_buf; - data.maxlen = BUFSIZ; - - int poll_result; for (;;) { poll_result = poll((struct pollfd*) & fds, 2, /*INFTIM*/ -1); + // interrupted poll is ignored - see CR 7086177 + if (poll_result == -1 && errno == EINTR) { + continue; + } + if (poll_result == -1) { - printf("ERROR: poll failed\n"); + printf("pty_open: poll() failed in main_loop: %s\n", strerror(errno)); exit(1); } @@ -222,7 +210,7 @@ if (fds[0].revents & POLLIN) { if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { - printf("ERROR: read from stdin failed\n"); + printf("pty_open: read from stdin failed: %s\n", strerror(errno)); exit(1); } @@ -231,38 +219,27 @@ } if (write(master_fd, buf, n) == -1) { - printf("ERROR: write to master failed\n"); + printf("pty_open: write to master failed: %s\n", strerror(errno)); exit(1); } } if (fds[1].revents & POLLIN) { - if ((n = getmsg(master_fd, &control, &data, &flags)) == -1) { - printf("ERROR: getmsg from master failed\n"); + if ((n = read(master_fd, buf, BUFSIZ)) == -1) { + printf("pty_open: read from master failed: %s\n", strerror(errno)); exit(1); } - msg_type = control.buf[0]; - - switch (msg_type) { - case M_DATA: - if (write(STDOUT_FILENO, data.buf, data.len) == -1) { - printf("ERROR: write to stdout failed\n"); - exit(1); - } - case M_IOCTL: - ioc = (struct iocblk*) &data.buf[0]; - switch (ioc->ioc_cmd) { - case TCSBRK: - goto out; - } + if (n == 0) { + break; } - + if (write(STDOUT_FILENO, buf, n) == -1) { + printf("pty_open: write to stdout failed: %s\n", strerror(errno)); + exit(1); + } } } -out: - ; } #endif @@ -272,7 +249,7 @@ char* name; if ((master_fd = ptm_open()) == -1) { - printf("ERROR: ptm_open() failed\n"); + printf("pty_open: ptm_open() failed: %s\n", strerror(errno)); exit(1); } @@ -283,7 +260,7 @@ // open slave to setup line discipline... if ((slave_fd = pts_open(master_fd)) == -1) { - printf("ERROR: cannot open PTY slave\n"); + printf("pty_open: cannot open PTY slave: %s\n", strerror(errno)); exit(1); } @@ -291,10 +268,6 @@ printf("TTY: %s\n\n", name); fflush(stdout); -#if defined _XOPEN_STREAMS && _XOPEN_STREAMS != -1 - ioctl(master_fd, I_PUSH, "pckt"); -#endif - loop(master_fd); return (EXIT_SUCCESS);