summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2020-06-15 09:53:30 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-06-16 11:19:00 +0200
commit15b2cc7c289af9aed896a85b775372d1633fe54b (patch)
tree90e822d9a52a6f5a63c5794f4e0d057318f45d41
parent727ae51a0c02985580dc17c005805a24d4cf6970 (diff)
downloadphp-git-15b2cc7c289af9aed896a85b775372d1633fe54b.tar.gz
Implements an openpty wrapper for solaris based systems
This is only used by proc_open pty support, and as such declared directly there.
-rw-r--r--ext/standard/proc_open.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index ba9fbbaa41..092c506dcf 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -56,6 +56,63 @@ extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
/* Mac OS X (and some BSDs) define `openpty` in <util.h> */
# include <util.h>
# endif
+#elif defined(__sun)
+# include <fcntl.h>
+# include <stropts.h>
+# include <termios.h>
+# define HAVE_OPENPTY 1
+
+/* Solaris/Illumos does not have any openpty implementation */
+int openpty(int *master, int *slave, char *name, struct termios *termp, struct winsize *winp)
+{
+ int fd, sd;
+ const char *slaveid;
+
+ assert(master);
+ assert(slave);
+
+ sd = *master = *slave = -1;
+ fd = open("/dev/ptmx", O_NOCTTY|O_RDWR);
+ if (fd == -1) {
+ return -1;
+ }
+ /* Checking if we can have to the pseudo terminal */
+ if (grantpt(fd) != 0 || unlockpt(fd) != 0) {
+ goto fail;
+ }
+ slaveid = ptsname(fd);
+ if (!slaveid) {
+ goto fail;
+ }
+
+ /* Getting the slave path and pushing pseudo terminal */
+ sd = open(slaveid, O_NOCTTY|O_RDONLY);
+ if (sd == -1 || ioctl(sd, I_PUSH, "ptem") == -1) {
+ goto fail;
+ }
+ if (termp) {
+ if (tcgetattr(sd, termp) < 0) {
+ goto fail;
+ }
+ }
+ if (winp) {
+ if (ioctl(sd, TIOCSWINSZ, winp) == -1) {
+ goto fail;
+ }
+ }
+
+ *slave = sd;
+ *master = fd;
+ return 0;
+fail:
+ if (sd != -1) {
+ close(sd);
+ }
+ if (fd != -1) {
+ close(fd);
+ }
+ return -1;
+}
#endif
#include "proc_open.h"