# 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 Wed Sep 14 17:42:46 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 Wed Sep 14 17:42:46 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 Wed Sep 14 17:42:46 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); }