From 55e2966fb382fabc2a0d36b41b9408c4b330e31d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 1 Jan 2009 18:01:42 +0000 Subject: [PATCH] * Modules/Debuggers/ProjectCenter/GNUmakefile * Modules/Debuggers/ProjectCenter/PTYView.h * Modules/Debuggers/ProjectCenter/PTYView.m: Change code to use openpty(...). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@27487 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++ Modules/Debuggers/ProjectCenter/GNUmakefile | 3 + Modules/Debuggers/ProjectCenter/PTYView.h | 1 + Modules/Debuggers/ProjectCenter/PTYView.m | 104 +++++++++++++++++++- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34d7a8d..5ffcfdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-01-01 13:08-EST Gregory John Casamento + + * Modules/Debuggers/ProjectCenter/GNUmakefile + * Modules/Debuggers/ProjectCenter/PTYView.h + * Modules/Debuggers/ProjectCenter/PTYView.m: Change code to use + openpty(...). + 2008-12-31 Sergii Stoian * Framework/PCFileNameIcon.m: diff --git a/Modules/Debuggers/ProjectCenter/GNUmakefile b/Modules/Debuggers/ProjectCenter/GNUmakefile index 8748ba2..08d3d19 100644 --- a/Modules/Debuggers/ProjectCenter/GNUmakefile +++ b/Modules/Debuggers/ProjectCenter/GNUmakefile @@ -48,5 +48,8 @@ ProjectCenter_OBJC_FILES= \ PCDebuggerView.m \ PTYView.m + +ADDITIONAL_NATIVE_LIBS += util + include ../../GNUmakefile.bundles include $(GNUSTEP_MAKEFILES)/bundle.make diff --git a/Modules/Debuggers/ProjectCenter/PTYView.h b/Modules/Debuggers/ProjectCenter/PTYView.h index 6e89130..9f38f07 100644 --- a/Modules/Debuggers/ProjectCenter/PTYView.h +++ b/Modules/Debuggers/ProjectCenter/PTYView.h @@ -30,6 +30,7 @@ NSFileHandle *master_handle; NSFileHandle *slave_handle; NSFileHandle *error_handle; + int master_fd, slave_fd; } - (int)master; diff --git a/Modules/Debuggers/ProjectCenter/PTYView.m b/Modules/Debuggers/ProjectCenter/PTYView.m index d1aee82..9516ebb 100644 --- a/Modules/Debuggers/ProjectCenter/PTYView.m +++ b/Modules/Debuggers/ProjectCenter/PTYView.m @@ -22,15 +22,96 @@ #import -#import #import -#import #import +#import /* for stderr and perror*/ +#import /* for int errno */ +#import +#import +#import +#import +#import +#import +#import + #ifndef NOTIFICATION_CENTER #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter] #endif +#if 0 +int openpty(int *amaster, int *aslave, char *name, const struct termios *termp, const struct winsize *winp) +{ + int fdm, fds; + char *slaveName; + + fdm = open("/dev/ptmx", O_RDWR); /* open master */ + if (fdm == -1) + { + perror("openpty:open(master)"); + return -1; + } + if(grantpt(fdm)) /* grant access to the slave */ + { + perror("openpty:grantpt(master)"); + close(fdm); + return -1; + } + if(unlockpt(fdm)) /* unlock the slave terminal */ + { + perror("openpty:unlockpt(master)"); + close(fdm); + return -1; + } + + slaveName = ptsname(fdm); /* get name of the slave */ + if (slaveName == NULL) + { + perror("openpty:ptsname(master)"); + close(fdm); + return -1; + } + if (name) /* of name ptr not null, copy it name back */ + strcpy(name, slaveName); + + fds = open(slaveName, O_RDWR | O_NOCTTY); /* open slave */ + if (fds == -1) + { + perror("openpty:open(slave)"); + close (fdm); + return -1; + } + + /* ldterm and ttcompat are automatically pushed on the stack on some systems*/ +#ifdef __SOLARIS__ + if (ioctl(fds, I_PUSH, "ptem") == -1) /* pseudo terminal module */ + { + perror("openpty:ioctl(I_PUSH, ptem"); + close(fdm); + close(fds); + return -1; + } + if (ioctl(fds, I_PUSH, "ldterm") == -1) /* ldterm must stay atop ptem */ + { + perror("forkpty:ioctl(I_PUSH, ldterm"); + close(fdm); + close(fds); + return -1; + } +#endif + + /* set terminal parameters if present */ + // if (termp) + // ioctl(fds, TCSETS, termp); + //if (winp) + // ioctl(fds, TIOCSWINSZ, winp); + + *amaster = fdm; + *aslave = fds; + return 0; +} +#endif + @implementation PTYView /** * Instantiate this view. @@ -51,6 +132,7 @@ */ - (int) master { +#if 0 struct stat buff; static char hex[] = "0123456789abcdef"; static char pty[] = "pqrs"; @@ -77,7 +159,17 @@ } } - return(-1); + return(-1); +#else + char *ptyname = NULL; + int fd = 0; + int sl = 0; + if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) == -1) + { + NSLog(@"Call to openpty(...) failed."); + } + return master_fd; +#endif } /** @@ -85,6 +177,7 @@ */ - (int) slave:(int)master_fd { +#if 0 int fd; // change to t, for slave tty. @@ -95,6 +188,9 @@ return(-1); } return(fd); +#else + return slave_fd; +#endif } /** @@ -228,8 +324,6 @@ withArguments: (NSArray *)array logStandardError: (BOOL)logError { - int master_fd, slave_fd; - task = [[NSTask alloc] init]; [task setArguments: array]; [task setCurrentDirectoryPath: directory];