This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 201733
Collapse All | Expand All

(-)a/dlight.nativeexecution/tools/PtySupport/src/error.c (-1 / +7 lines)
Lines 1-15 Link Here
1
#include "error.h"
1
#include "error.h"
2
2
3
extern const char* progname;
4
3
/*
5
/*
4
 * Print a message and return to caller.
6
 * Print a message and return to caller.
5
 * Caller specifies "errnoflag".
7
 * Caller specifies "errnoflag".
6
 */
8
 */
7
static void err_doit(int errnoflag, int error, const char *fmt, va_list ap) {
9
static void err_doit(int errnoflag, int error, const char *fmt, va_list ap) {
8
    char buf[MAXLINE];
10
    char buf[MAXLINE];
9
    vsnprintf(buf, MAXLINE, fmt, ap);
11
12
    snprintf(buf, MAXLINE, "%s: ", progname);
13
    vsnprintf(buf + strlen(buf), MAXLINE, fmt, ap);
14
10
    if (errnoflag) {
15
    if (errnoflag) {
11
        snprintf(buf + strlen(buf), MAXLINE - strlen(buf), ": %s", strerror(error));
16
        snprintf(buf + strlen(buf), MAXLINE - strlen(buf), ": %s", strerror(error));
12
    }
17
    }
18
13
    strcat(buf, "\n");
19
    strcat(buf, "\n");
14
    fflush(stdout); /* in case stdout and stderr are the same */
20
    fflush(stdout); /* in case stdout and stderr are the same */
15
    fputs(buf, stderr);
21
    fputs(buf, stderr);
(-)a/dlight.nativeexecution/tools/PtySupport/src/loop.c (-22 / +24 lines)
Lines 1-4 Link Here
1
#include "loop.h"
1
#include "loop.h"
2
#include "error.h"
2
#include <poll.h>
3
#include <poll.h>
3
#include <sys/termios.h>
4
#include <sys/termios.h>
4
#include <stdio.h>
5
#include <stdio.h>
Lines 26-40 Link Here
26
        FD_SET(master_fd, &read_set);
27
        FD_SET(master_fd, &read_set);
27
        select_result = select(master_fd + 1, &read_set, NULL, NULL, NULL);
28
        select_result = select(master_fd + 1, &read_set, NULL, NULL, NULL);
28
29
30
        // interrupted select is ignored - see CR 7086177
31
        if (select_result == -1 && errno == EINTR) {
32
            continue;
33
        }
34
        
29
        if (select_result == -1) {
35
        if (select_result == -1) {
30
            printf("ERROR: poll failed\n");
36
            err_sys("poll failed\n");
31
            exit(1);
32
        }
37
        }
33
38
34
        if (FD_ISSET(STDIN_FILENO, &read_set)) {
39
        if (FD_ISSET(STDIN_FILENO, &read_set)) {
35
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
40
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
36
                printf("ERROR: read from stdin failed\n");
41
                err_sys("read from stdin failed\n");
37
                exit(1);
38
            }
42
            }
39
43
40
            if (n == 0) {
44
            if (n == 0) {
Lines 42-56 Link Here
42
            }
46
            }
43
47
44
            if (write(master_fd, buf, n) == -1) {
48
            if (write(master_fd, buf, n) == -1) {
45
                printf("ERROR: write to master failed\n");
49
                err_sys("write to master failed\n");
46
                exit(1);
47
            }
50
            }
48
        }
51
        }
49
52
50
        if (FD_ISSET(master_fd, &read_set)) {
53
        if (FD_ISSET(master_fd, &read_set)) {
51
            if ((n = read(master_fd, buf, BUFSIZ)) == -1) {
54
            if ((n = read(master_fd, buf, BUFSIZ)) == -1) {
52
                printf("ERROR: read from master failed\n");
55
                err_sys("read from master failed\n");
53
                exit(1);
54
            }
56
            }
55
57
56
            if (n == 0) {
58
            if (n == 0) {
Lines 58-69 Link Here
58
            }
60
            }
59
61
60
            if (write(STDOUT_FILENO, buf, n) == -1) {
62
            if (write(STDOUT_FILENO, buf, n) == -1) {
61
                printf("ERROR: write to stdout failed\n");
63
                err_sys("write to stdout failed\n");
62
                exit(1);
64
                exit(1);
63
            }
65
            }
64
        }
66
        }
65
    }
67
    }
66
    
68
67
    return 0;
69
    return 0;
68
}
70
}
69
71
Lines 86-100 Link Here
86
    for (;;) {
88
    for (;;) {
87
        poll_result = poll((struct pollfd*) & fds, 2, INFTIM);
89
        poll_result = poll((struct pollfd*) & fds, 2, INFTIM);
88
90
91
        // interrupted poll is ignored - see CR 7086177
92
        if (poll_result == -1 && errno == EINTR) {
93
            continue;
94
        }
95
89
        if (poll_result == -1) {
96
        if (poll_result == -1) {
90
            printf("ERROR: poll failed\n");
97
            err_sys("poll() failed in main_loop");
91
            exit(1);
92
        }
98
        }
93
99
94
        if (fds[0].revents & POLLIN) {
100
        if (fds[0].revents & POLLIN) {
95
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
101
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
96
                printf("ERROR: read from stdin failed\n");
102
                err_sys("read from stdin failed");
97
                exit(1);
98
            }
103
            }
99
104
100
            if (n == 0) {
105
            if (n == 0) {
Lines 109-123 Link Here
109
            }
114
            }
110
115
111
            if (writen(master_fd, buf, n) == -1) {
116
            if (writen(master_fd, buf, n) == -1) {
112
                printf("ERROR: write to master failed\n");
117
                err_sys("write to master failed\n");
113
                exit(1);
114
            }
118
            }
115
        }
119
        }
116
120
117
        if (fds[1].revents & POLLIN) {
121
        if (fds[1].revents & POLLIN) {
118
            if ((n = read(master_fd, buf, BUFSIZ)) == -1) {
122
            if ((n = read(master_fd, buf, BUFSIZ)) == -1) {
119
                printf("ERROR: read from master failed\n");
123
                err_sys("read from master failed\n");
120
                exit(1);
121
            }
124
            }
122
125
123
            if (n == 0) {
126
            if (n == 0) {
Lines 125-132 Link Here
125
            }
128
            }
126
129
127
            if (writen(STDOUT_FILENO, buf, n) == -1) {
130
            if (writen(STDOUT_FILENO, buf, n) == -1) {
128
                printf("ERROR: write to stdout failed\n");
131
                err_sys("write to stdout failed\n");
129
                exit(1);
130
            }
132
            }
131
        }
133
        }
132
134
Lines 145-151 Link Here
145
            return 1;
147
            return 1;
146
        }
148
        }
147
    }
149
    }
148
    
150
149
    return 0;
151
    return 0;
150
}
152
}
151
#endif
153
#endif
Lines 154-160 Link Here
154
    const char *pos = ptr;
156
    const char *pos = ptr;
155
    size_t nleft = n;
157
    size_t nleft = n;
156
    ssize_t nwritten;
158
    ssize_t nwritten;
157
    
159
158
    while (nleft > 0) {
160
    while (nleft > 0) {
159
        if ((nwritten = write(fd, pos, nleft)) < 0) {
161
        if ((nwritten = write(fd, pos, nleft)) < 0) {
160
            if (nleft == n)
162
            if (nleft == n)
(-)a/dlight.nativeexecution/tools/PtySupport/src/pty.c (-4 / +8 lines)
Lines 2-8 Link Here
2
 * File:   pty_start.c
2
 * File:   pty_start.c
3
 * Author: ak119685
3
 * Author: ak119685
4
 *
4
 *
5
 * Created on 22 Апрель 2010 г., 12:32
5
 * Created on 22 ?????? 2010 ?., 12:32
6
 */
6
 */
7
7
8
#include "pty_fork.h"
8
#include "pty_fork.h"
Lines 15-26 Link Here
15
#include <signal.h>
15
#include <signal.h>
16
#include <fcntl.h>
16
#include <fcntl.h>
17
17
18
#include <libgen.h>
19
18
#if defined __CYGWIN__ && !defined WCONTINUED
20
#if defined __CYGWIN__ && !defined WCONTINUED
19
//added for compatibility with cygwin 1.5
21
//added for compatibility with cygwin 1.5
20
#define WCONTINUED 0
22
#define WCONTINUED 0
21
#endif
23
#endif
22
24
23
static void set_noecho(int);
25
static void set_noecho(int);
26
const char* progname;
24
27
25
/*
28
/*
26
 * 
29
 * 
Lines 39-58 Link Here
39
    int idx;
42
    int idx;
40
    int nopt = 1;
43
    int nopt = 1;
41
44
45
    progname = basename(argv[0]);
46
42
    for (idx = 1; idx < argc; idx++) {
47
    for (idx = 1; idx < argc; idx++) {
43
        if (argv[idx][0] == '-') {
48
        if (argv[idx][0] == '-') {
44
            if (strcmp(argv[idx], "-p") == 0) {
49
            if (strcmp(argv[idx], "-p") == 0) {
45
                idx++;
50
                idx++;
46
                if (argv[idx] == NULL || argv[idx][0] == '\0') {
51
                if (argv[idx] == NULL || argv[idx][0] == '\0') {
47
                    printf("ERROR missing pty after -p\n");
52
                    err_quit("missing pty after -p\n");
48
                    exit(-1);
49
                }
53
                }
50
                pty = argv[idx];
54
                pty = argv[idx];
51
                nopt += 2;
55
                nopt += 2;
52
            } else if (strcmp(argv[idx], "--env") == 0) {
56
            } else if (strcmp(argv[idx], "--env") == 0) {
53
                idx++;
57
                idx++;
54
                if (argv[idx] == NULL || argv[idx][0] == '\0') {
58
                if (argv[idx] == NULL || argv[idx][0] == '\0') {
55
                    printf("ERROR missing variable=value pair after --env\n");
59
                    err_quit("missing variable=value pair after --env\n");
56
                    exit(-1);
60
                    exit(-1);
57
                }
61
                }
58
62
(-)a/dlight.nativeexecution/tools/pty_open.c (-47 / +20 lines)
Lines 50-67 Link Here
50
50
51
#if !defined __APPLE__ && !defined __CYGWIN__
51
#if !defined __APPLE__ && !defined __CYGWIN__
52
#include <stropts.h>
52
#include <stropts.h>
53
#include <sys/stream.h>
54
#include <sys/termios.h>
55
#else
53
#else
56
#include <sys/select.h>
54
#include <sys/select.h>
57
#include <sys/ioctl.h>
58
#endif
55
#endif
59
56
60
#include <stdio.h>
57
#include <stdio.h>
61
#include <stdlib.h>
58
#include <stdlib.h>
62
#include <unistd.h>
59
#include <unistd.h>
63
#include <fcntl.h>
60
#include <fcntl.h>
61
#include <errno.h>
64
#include <poll.h>
62
#include <poll.h>
63
#include <errno.h>
65
64
66
static int ptm_open(void) {
65
static int ptm_open(void) {
67
    int masterfd;
66
    int masterfd;
Lines 182-196 Link Here
182
    ssize_t n;
181
    ssize_t n;
183
    char buf[BUFSIZ];
182
    char buf[BUFSIZ];
184
    struct pollfd fds[2];
183
    struct pollfd fds[2];
185
    char control_buf [BUFSIZ];
186
    char data_buf [BUFSIZ];
187
    int flags;
188
    struct strbuf control;
189
    struct strbuf data;
190
    struct iocblk *ioc;
191
    struct termios *term;
192
    unsigned char msg_type;
193
194
184
195
    fds[0].fd = STDIN_FILENO;
185
    fds[0].fd = STDIN_FILENO;
196
    fds[0].events = POLLIN;
186
    fds[0].events = POLLIN;
Lines 199-218 Link Here
199
    fds[1].events = POLLIN;
189
    fds[1].events = POLLIN;
200
    fds[1].revents = 0;
190
    fds[1].revents = 0;
201
191
202
203
    control.buf = control_buf;
204
    control.maxlen = BUFSIZ;
205
    data.buf = data_buf;
206
    data.maxlen = BUFSIZ;
207
208
209
    int poll_result;
192
    int poll_result;
210
193
211
    for (;;) {
194
    for (;;) {
212
        poll_result = poll((struct pollfd*) & fds, 2, /*INFTIM*/ -1);
195
        poll_result = poll((struct pollfd*) & fds, 2, /*INFTIM*/ -1);
213
196
197
        // interrupted poll is ignored - see CR 7086177
198
        if (poll_result == -1 && errno == EINTR) {
199
            continue;
200
        }
201
214
        if (poll_result == -1) {
202
        if (poll_result == -1) {
215
            printf("ERROR: poll failed\n");
203
            printf("pty_open: poll() failed in main_loop: %s\n", strerror(errno));
216
            exit(1);
204
            exit(1);
217
        }
205
        }
218
206
Lines 222-228 Link Here
222
210
223
        if (fds[0].revents & POLLIN) {
211
        if (fds[0].revents & POLLIN) {
224
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
212
            if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) {
225
                printf("ERROR: read from stdin failed\n");
213
                printf("pty_open: read from stdin failed: %s\n", strerror(errno));
226
                exit(1);
214
                exit(1);
227
            }
215
            }
228
216
Lines 231-268 Link Here
231
            }
219
            }
232
220
233
            if (write(master_fd, buf, n) == -1) {
221
            if (write(master_fd, buf, n) == -1) {
234
                printf("ERROR: write to master failed\n");
222
                printf("pty_open: write to master failed: %s\n", strerror(errno));
235
                exit(1);
223
                exit(1);
236
            }
224
            }
237
        }
225
        }
238
226
239
        if (fds[1].revents & POLLIN) {
227
        if (fds[1].revents & POLLIN) {
240
            if ((n = getmsg(master_fd, &control, &data, &flags)) == -1) {
228
            if ((n = read(master_fd, buf, BUFSIZ)) == -1) {
241
                printf("ERROR: getmsg from master failed\n");
229
                printf("pty_open: read from master failed: %s\n", strerror(errno));
242
                exit(1);
230
                exit(1);
243
            }
231
            }
244
232
245
            msg_type = control.buf[0];
233
            if (n == 0) {
246
234
                break;
247
            switch (msg_type) {
248
                case M_DATA:
249
                    if (write(STDOUT_FILENO, data.buf, data.len) == -1) {
250
                        printf("ERROR: write to stdout failed\n");
251
                        exit(1);
252
                    }
253
                case M_IOCTL:
254
                    ioc = (struct iocblk*) &data.buf[0];
255
                    switch (ioc->ioc_cmd) {
256
                        case TCSBRK:
257
                            goto out;
258
                    }
259
            }
235
            }
260
236
261
237
            if (write(STDOUT_FILENO, buf, n) == -1) {
238
                printf("pty_open: write to stdout failed: %s\n", strerror(errno));
239
                exit(1);
240
            }
262
        }
241
        }
263
    }
242
    }
264
out:
265
    ;
266
}
243
}
267
#endif
244
#endif
268
245
Lines 272-278 Link Here
272
    char* name;
249
    char* name;
273
250
274
    if ((master_fd = ptm_open()) == -1) {
251
    if ((master_fd = ptm_open()) == -1) {
275
        printf("ERROR: ptm_open() failed\n");
252
        printf("pty_open: ptm_open() failed: %s\n", strerror(errno));
276
        exit(1);
253
        exit(1);
277
    }
254
    }
278
255
Lines 283-289 Link Here
283
260
284
    // open slave to setup line discipline...
261
    // open slave to setup line discipline...
285
    if ((slave_fd = pts_open(master_fd)) == -1) {
262
    if ((slave_fd = pts_open(master_fd)) == -1) {
286
        printf("ERROR: cannot open PTY slave\n");
263
        printf("pty_open: cannot open PTY slave: %s\n", strerror(errno));
287
        exit(1);
264
        exit(1);
288
    }
265
    }
289
266
Lines 291-300 Link Here
291
    printf("TTY: %s\n\n", name);
268
    printf("TTY: %s\n\n", name);
292
    fflush(stdout);
269
    fflush(stdout);
293
270
294
#if defined _XOPEN_STREAMS && _XOPEN_STREAMS != -1
295
    ioctl(master_fd, I_PUSH, "pckt");
296
#endif
297
    
298
    loop(master_fd);
271
    loop(master_fd);
299
272
300
    return (EXIT_SUCCESS);
273
    return (EXIT_SUCCESS);

Return to bug 201733