[haiku-commits] haiku: hrev53101 - in src: add-ons/kernel/drivers/tty tests/add-ons/kernel/drivers/tty

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 29 Apr 2019 16:26:29 -0400 (EDT)

hrev53101 adds 2 changesets to branch 'master'
old head: 097bbc7fd28bade702f21c9b4082ffefd0082a62
new head: 62740a49ce83d82417245b7f6650d820c0791d54
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=62740a49ce83+%5E097bbc7fd28b

----------------------------------------------------------------------------

e892b55b25a8: tty: fix TRACE build on x86_64.
  
  Change-Id: Idcfa9bca4a5b450f7a7d2a060809999ee3e3ceaa
  Reviewed-on: https://review.haiku-os.org/c/1416
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

62740a49ce83: tty: add posix open_pt test.
  
  Change-Id: I9a4d927ee693198b8c978f1cb51cf4cc50ca6557
  Reviewed-on: https://review.haiku-os.org/c/1417
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 147 insertions(+), 37 deletions(-)
src/add-ons/kernel/drivers/tty/master.cpp        |  22 ++--
src/add-ons/kernel/drivers/tty/slave.cpp         |  18 ++--
src/add-ons/kernel/drivers/tty/tty.cpp           |  42 ++++----
src/tests/add-ons/kernel/drivers/tty/Jamfile     |   1 +
.../kernel/drivers/tty/posix_openpt_test.cpp     | 101 +++++++++++++++++++

############################################################################

Commit:      e892b55b25a877d6e8c302e85aadcbadf979c80f
URL:         https://git.haiku-os.org/haiku/commit/?id=e892b55b25a8
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Sun Apr 28 19:05:23 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Mon Apr 29 20:26:27 2019 UTC

tty: fix TRACE build on x86_64.

Change-Id: Idcfa9bca4a5b450f7a7d2a060809999ee3e3ceaa
Reviewed-on: https://review.haiku-os.org/c/1416
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/drivers/tty/master.cpp 
b/src/add-ons/kernel/drivers/tty/master.cpp
index b91b61d2cf..476226de1e 100644
--- a/src/add-ons/kernel/drivers/tty/master.cpp
+++ b/src/add-ons/kernel/drivers/tty/master.cpp
@@ -67,7 +67,8 @@ master_open(const char *name, uint32 flags, void **_cookie)
                        return B_ERROR;
        }
 
-       TRACE(("master_open: TTY index = %ld (name = %s)\n", index, name));
+       TRACE(("master_open: TTY index = %" B_PRId32 " (name = %s)\n", index,
+               name));
 
        MutexLocker globalLocker(gGlobalTTYLock);
 
@@ -146,7 +147,8 @@ master_ioctl(void *_cookie, uint32 op, void *buffer, size_t 
length)
 {
        master_cookie *cookie = (master_cookie *)_cookie;
 
-       TRACE(("master_ioctl: cookie %p, op %lu, buffer %p, length %lu\n", 
_cookie, op, buffer, length));
+       TRACE(("master_ioctl: cookie %p, op %" B_PRIu32 ", buffer %p, length 
%lu"
+               "\n", _cookie, op, buffer, length));
 
        return tty_ioctl(cookie, op, buffer, length);
 }
@@ -157,13 +159,13 @@ master_read(void *_cookie, off_t offset, void *buffer, 
size_t *_length)
 {
        master_cookie *cookie = (master_cookie *)_cookie;
 
-       TRACE(("master_read: cookie %p, offset %Ld, buffer %p, length %lu\n",
-               _cookie, offset, buffer, *_length));
+       TRACE(("master_read: cookie %p, offset %" B_PRIdOFF ", buffer %p, 
length "
+               "%lu\n", _cookie, offset, buffer, *_length));
 
        status_t result = tty_input_read(cookie, buffer, _length);
 
-       TRACE(("master_read done: cookie %p, result: %lx, length %lu\n", 
_cookie,
-               result, *_length));
+       TRACE(("master_read done: cookie %p, result: %" B_PRIx32 ", length 
%lu\n",
+               _cookie, result, *_length));
 
        return result;
 }
@@ -174,13 +176,13 @@ master_write(void *_cookie, off_t offset, const void 
*buffer, size_t *_length)
 {
        master_cookie *cookie = (master_cookie *)_cookie;
 
-       TRACE(("master_write: cookie %p, offset %Ld, buffer %p, length %lu\n",
-               _cookie, offset, buffer, *_length));
+       TRACE(("master_write: cookie %p, offset %" B_PRIdOFF ", buffer %p, 
length "
+               "%lu\n", _cookie, offset, buffer, *_length));
 
        status_t result = tty_write_to_tty_master(cookie, buffer, _length);
 
-       TRACE(("master_write done: cookie %p, result: %lx, length %lu\n", 
_cookie,
-               result, *_length));
+       TRACE(("master_write done: cookie %p, result: %" B_PRIx32 ", length 
%lu\n",
+               _cookie, result, *_length));
 
        return result;
 }
diff --git a/src/add-ons/kernel/drivers/tty/slave.cpp 
b/src/add-ons/kernel/drivers/tty/slave.cpp
index 77c6296efd..31f7b96a9a 100644
--- a/src/add-ons/kernel/drivers/tty/slave.cpp
+++ b/src/add-ons/kernel/drivers/tty/slave.cpp
@@ -45,7 +45,8 @@ slave_open(const char *name, uint32 flags, void **_cookie)
                        return B_ERROR;
        }
 
-       TRACE(("slave_open: TTY index = %ld (name = %s)\n", index, name));
+       TRACE(("slave_open: TTY index = %" B_PRId32 " (name = %s)\n", index,
+               name));
 
        MutexLocker globalLocker(gGlobalTTYLock);
 
@@ -161,7 +162,8 @@ slave_ioctl(void *_cookie, uint32 op, void *buffer, size_t 
length)
 {
        slave_cookie *cookie = (slave_cookie *)_cookie;
 
-       TRACE(("slave_ioctl: cookie %p, op %lu, buffer %p, length %lu\n", 
_cookie, op, buffer, length));
+       TRACE(("slave_ioctl: cookie %p, op %" B_PRIu32 ", buffer %p, length 
%lu\n",
+               _cookie, op, buffer, length));
 
        return tty_ioctl(cookie, op, buffer, length);
 }
@@ -172,12 +174,12 @@ slave_read(void *_cookie, off_t offset, void *buffer, 
size_t *_length)
 {
        slave_cookie *cookie = (slave_cookie *)_cookie;
 
-       TRACE(("slave_read: cookie %p, offset %Ld, buffer %p, length %lu\n",
-               _cookie, offset, buffer, *_length));
+       TRACE(("slave_read: cookie %p, offset %" B_PRIdOFF ", buffer %p, length 
"
+               "%lu\n", _cookie, offset, buffer, *_length));
 
        status_t result = tty_input_read(cookie, buffer, _length);
 
-       TRACE(("slave_read done: cookie %p, result %lx, length %lu\n",
+       TRACE(("slave_read done: cookie %p, result %" B_PRIx32 ", length %lu\n",
                _cookie, result, *_length));
 
        return result;
@@ -189,12 +191,12 @@ slave_write(void *_cookie, off_t offset, const void 
*buffer, size_t *_length)
 {
        slave_cookie *cookie = (slave_cookie *)_cookie;
 
-       TRACE(("slave_write: cookie %p, offset %Ld, buffer %p, length %lu\n",
-               _cookie, offset, buffer, *_length));
+       TRACE(("slave_write: cookie %p, offset %" B_PRIdOFF", buffer %p, length 
"
+               "%lu\n", _cookie, offset, buffer, *_length));
 
        status_t result = tty_write_to_tty_slave(cookie, buffer, _length);
 
-       TRACE(("slave_write done: cookie %p, result %lx, length %lu\n",
+       TRACE(("slave_write done: cookie %p, result %" B_PRIx32 ", length 
%lu\n",
                _cookie, result, *_length));
 
        return result;
diff --git a/src/add-ons/kernel/drivers/tty/tty.cpp 
b/src/add-ons/kernel/drivers/tty/tty.cpp
index 02b713daf3..503b40c46e 100644
--- a/src/add-ons/kernel/drivers/tty/tty.cpp
+++ b/src/add-ons/kernel/drivers/tty/tty.cpp
@@ -181,7 +181,7 @@ public:
 
                if (semaphore >= 0) {
                        TRACE(("TTYReference: cookie %p closed, last operation 
done, "
-                               "releasing blocking sem %ld\n", cookie, 
semaphore));
+                               "releasing blocking sem %" B_PRId32 "\n", 
cookie, semaphore));
 
                        release_sem(semaphore);
                }
@@ -430,8 +430,8 @@ RequestOwner::Wait(bool interruptable, bigtime_t timeout)
                        (interruptable ? B_CAN_INTERRUPT : 0) | 
B_RELATIVE_TIMEOUT,
                        timeout);
 
-               TRACE(("%p->RequestOwner::Wait(): condition occurred: %lx\n", 
this,
-                       error));
+               TRACE(("%p->RequestOwner::Wait(): condition occurred: %" 
B_PRIx32 "\n",
+                       this, error));
 
                // remove the condition variable
                locker.Lock();
@@ -485,7 +485,8 @@ RequestOwner::Notify(Request* request)
 void
 RequestOwner::NotifyError(Request* request, status_t error)
 {
-       TRACE(("%p->RequestOwner::NotifyError(%p, %lx)\n", this, request, 
error));
+       TRACE(("%p->RequestOwner::NotifyError(%p, %" B_PRIx32 ")\n", this, 
request,
+               error));
 
        if (fError == B_OK) {
                fError = error;
@@ -1033,7 +1034,7 @@ tty_close_cookie(struct tty_cookie* cookie)
        // critical code
        if (unblock) {
                TRACE(("tty_close_cookie(): cookie %p, there're still pending "
-                       "operations, acquire blocking sem %ld\n", cookie,
+                       "operations, acquire blocking sem %" B_PRId32 "\n", 
cookie,
                        cookie->blocking_semaphore));
 
                acquire_sem(cookie->blocking_semaphore);
@@ -1599,7 +1600,8 @@ tty_ioctl(tty_cookie* cookie, uint32 op, void* buffer, 
size_t length)
        if (!ttyReference.IsLocked())
                return B_FILE_ERROR;
 
-       TRACE(("tty_ioctl: tty %p, op %lu, buffer %p, length %lu\n", tty, op, 
buffer, length));
+       TRACE(("tty_ioctl: tty %p, op %" B_PRIu32 ", buffer %p, length %"
+               B_PRIuSIZE "\n", tty, op, buffer, length));
        MutexLocker locker(tty->lock);
 
        // values marked BeOS are non-standard codes we support for legacy apps
@@ -1623,9 +1625,10 @@ tty_ioctl(tty_cookie* cookie, uint32 op, void* buffer, 
size_t length)
                case TCSETA:
                case TCSETAW:
                case TCSETAF:
-                       TRACE(("tty: set attributes (iflag = %lx, oflag = %lx, "
-                               "cflag = %lx, lflag = %lx)\n", 
tty->settings->termios.c_iflag,
-                               tty->settings->termios.c_oflag, 
tty->settings->termios.c_cflag,
+                       TRACE(("tty: set attributes (iflag = %" B_PRIx32 ", 
oflag = %"
+                               B_PRIx32 ", cflag = %" B_PRIx32 ", lflag = %" 
B_PRIx32 ")\n",
+                               tty->settings->termios.c_iflag, 
tty->settings->termios.c_oflag,
+                               tty->settings->termios.c_cflag,
                                tty->settings->termios.c_lflag));
 
                        return user_memcpy(&tty->settings->termios, buffer,
@@ -1804,7 +1807,7 @@ tty_ioctl(tty_cookie* cookie, uint32 op, void* buffer, 
size_t length)
                        break;
        }
 
-       TRACE(("tty: unsupported opcode %lu\n", op));
+       TRACE(("tty: unsupported opcode %" B_PRIu32 "\n", op));
        return B_BAD_VALUE;
 }
 
@@ -1822,7 +1825,8 @@ tty_input_read(tty_cookie* cookie, void* _buffer, size_t* 
_length)
        bigtime_t interCharTimeout = 0;
        size_t bytesNeeded = 1;
 
-       TRACE(("tty_input_read(tty = %p, length = %lu, mode = %lu)\n", tty, 
length, mode));
+       TRACE(("tty_input_read(tty = %p, length = %lu, mode = %" B_PRIu32 ")\n",
+               tty, length, mode));
 
        if (length == 0)
                return B_OK;
@@ -1841,8 +1845,8 @@ tty_input_read(tty_cookie* cookie, void* _buffer, size_t* 
_length)
                        // Non-blocking mode. Handle VMIN and VTIME.
                        bytesNeeded = tty->settings->termios.c_cc[VMIN];
                        bigtime_t vtime = tty->settings->termios.c_cc[VTIME] * 
100000;
-                       TRACE(("tty_input_read: icanon vmin %lu, vtime 
%Ldus\n", bytesNeeded,
-                               vtime));
+                       TRACE(("tty_input_read: icanon vmin %lu, vtime %" 
B_PRIdBIGTIME
+                               "us\n", bytesNeeded, vtime));
 
                        if (bytesNeeded == 0) {
                                // In this case VTIME specifies a relative 
total timeout. We
@@ -1865,8 +1869,8 @@ tty_input_read(tty_cookie* cookie, void* _buffer, size_t* 
_length)
        *_length = 0;
 
        do {
-               TRACE(("tty_input_read: AcquireReader(%Ldus, %ld)\n", timeout,
-                       bytesNeeded));
+               TRACE(("tty_input_read: AcquireReader(%" B_PRIdBIGTIME "us, 
%ld)\n",
+                       timeout, bytesNeeded));
                status = locker.AcquireReader(timeout, bytesNeeded);
                if (status != B_OK)
                        break;
@@ -1989,8 +1993,8 @@ tty_select(tty_cookie* cookie, uint8 event, uint32 ref, 
selectsync* sync)
 {
        struct tty* tty = cookie->tty;
 
-       TRACE(("tty_select(cookie = %p, event = %u, ref = %lu, sync = %p)\n",
-               cookie, event, ref, sync));
+       TRACE(("tty_select(cookie = %p, event = %u, ref = %" B_PRIu32 ", sync = 
"
+               "%p)\n", cookie, event, ref, sync));
 
        // we don't support all kinds of events
        if (event < B_SELECT_READ || event > B_SELECT_ERROR)
@@ -2017,8 +2021,8 @@ tty_select(tty_cookie* cookie, uint8 event, uint32 ref, 
selectsync* sync)
        // add the event to the TTY's pool
        status_t error = add_select_sync_pool_entry(&tty->select_pool, sync, 
event);
        if (error != B_OK) {
-               TRACE(("tty_select() done: add_select_sync_pool_entry() failed: 
%lx\n",
-                       error));
+               TRACE(("tty_select() done: add_select_sync_pool_entry() failed: 
%"
+                       B_PRIx32 "\n", error));
 
                return error;
        }

############################################################################

Revision:    hrev53101
Commit:      62740a49ce83d82417245b7f6650d820c0791d54
URL:         https://git.haiku-os.org/haiku/commit/?id=62740a49ce83
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Sun Apr 28 19:31:33 2019 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Mon Apr 29 20:26:27 2019 UTC

tty: add posix open_pt test.

Change-Id: I9a4d927ee693198b8c978f1cb51cf4cc50ca6557
Reviewed-on: https://review.haiku-os.org/c/1417
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/tests/add-ons/kernel/drivers/tty/Jamfile 
b/src/tests/add-ons/kernel/drivers/tty/Jamfile
index 9a54b96651..7b28f46272 100644
--- a/src/tests/add-ons/kernel/drivers/tty/Jamfile
+++ b/src/tests/add-ons/kernel/drivers/tty/Jamfile
@@ -3,4 +3,5 @@ SubDir HAIKU_TOP src tests add-ons kernel drivers tty ;
 UsePrivateHeaders [ FDirName kernel ] ;
 
 SimpleTest tty-test : tty-test.cpp : libroot.so [ TargetLibstdc++ ] ;
+SimpleTest posix_openpt_test : posix_openpt_test.cpp : libroot.so ;
 
diff --git a/src/tests/add-ons/kernel/drivers/tty/posix_openpt_test.cpp 
b/src/tests/add-ons/kernel/drivers/tty/posix_openpt_test.cpp
new file mode 100644
index 0000000000..4103dcdb06
--- /dev/null
+++ b/src/tests/add-ons/kernel/drivers/tty/posix_openpt_test.cpp
@@ -0,0 +1,101 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <signal.h>
+
+void die(const char *ptr, ...)
+{
+       va_list vlist;
+       va_start(vlist, ptr);
+       char ch;
+
+       while ((ch = *ptr++) != '\0') {
+               if (ch == '%' && *ptr != '\0') {
+                       ch = *ptr++;
+                       switch(ch) {
+                       case 'd': printf("%d", va_arg(vlist, int)); break;
+                       case 'e': printf("%e", va_arg(vlist, double)); break;
+                       case 'c': printf("%c", va_arg(vlist, int)); break;
+                       case 's': printf("%s", va_arg(vlist, char *)); break;
+                       default: va_end(vlist);exit(1);
+
+                       }
+
+               } else
+                       printf("%c", ch);
+
+
+       }
+
+       va_end(vlist);
+       exit(1);
+}
+
+
+int main()
+{
+       int pid;
+       int ptm;
+       int pts;
+       char *ptr;
+       char *program_name[2] = { (char*)"/bin/uname", NULL};
+       char buf[512];
+       int n;
+
+       if ((ptm = posix_openpt(O_RDWR)) == -1) {
+               die("posix_openpt error: %s\n", strerror(errno));
+       }
+       if (grantpt(ptm) == -1) {
+               die("grantpt error: %s\n", strerror(errno));
+       }
+       if (unlockpt(ptm) == -1) {
+               die("unlockpt error: %s\n", strerror(errno));
+       }
+
+       pid = fork();
+       if (pid < 0) {
+               die("fork error: %s\n", strerror(errno));
+       } else if (pid == 0) { // child
+               if (setsid() == (pid_t)-1) {
+                       die("setsid() error: %s\n", strerror(errno));
+               }
+               if ((ptr = (char *) ptsname(ptm)) == NULL) {
+                       die("ptsname error: %s\n", strerror(errno));
+               }
+               if ((pts = open(ptr, O_RDWR)) < 0) {
+                       die("open of slave failed: %a\n", strerror(errno));
+               }
+               close(ptm);
+
+               if (dup2(pts, STDIN_FILENO) != STDIN_FILENO
+                       || dup2(pts, STDOUT_FILENO) != STDOUT_FILENO
+                       || dup2(pts, STDERR_FILENO) != STDERR_FILENO) {
+                       die("error doing dup's : %s\n", strerror(errno));
+               }
+
+               if (execve(*program_name, program_name , NULL) == -1) {
+                       die("execve error: %s\n", strerror(errno));
+               }
+               exit(1);
+       } else { // parent
+               if (dup2(ptm, STDIN_FILENO) != STDIN_FILENO) {
+                       die("dup2 of parent failed");
+               }
+               while (1) {
+                       n = read(ptm, buf, 511);
+                       if (n <= 0) {
+                               break;
+                       }
+                       write(STDOUT_FILENO, buf, n);
+               }
+       }
+       return 0;
+}
+


Other related posts:

  • » [haiku-commits] haiku: hrev53101 - in src: add-ons/kernel/drivers/tty tests/add-ons/kernel/drivers/tty - waddlesplash