- if (openpty (&master_fd, &slave_fd, loop_name, NULL, NULL) < 0)
- {
- syslog(LOG_ERR, "No free pty for loopback");
- die(1);
- }
+ master_fd = -1;
+ for (i = 0; i < 64; ++i) {
+ sprintf(loop_name, "/dev/pty%c%x", 'p' + i / 16, i % 16);
+ master_fd = open(loop_name, O_RDWR, 0);
+ if (master_fd >= 0)
+ break;
+ }
+ if (master_fd < 0) {
+ syslog(LOG_ERR, "No free pty for loopback");
+ die(1);
+ }