Technical article 105187

tcgetattr(S) fails with "Invalid argument" (errno = EINVAL) on OpenServer 5.0.0

OpenServer 5.0.0

Written · Last revised

Problem

I am porting a program from SCO Open Server Release 3.0 (or SCO UNIX System V/386 Release 3.2 Version 4.2) to SCO OpenServer Release 5.0.0. This program makes use of STREAMS-based pseudo-terminals (ptmx(M)).

On SCO Open Server Release 3.0 based systems, this program executed
correctly.  On SCO OpenServer Release 5.0.0, however, the system call
tcgetattr(S) fails with the error message "Invalid argument"
 (errno(S) set to EINVAL).

The example program below demonstrates this problem:

/*
 *   cc pts.c -o pts
 */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stropts.h>
#include <termios.h>
#define PTY_MASTER "/dev/ptmx"
int pty_master ()
{
        int master_fd;

if ((master_fd = open (PTY_MASTER, O_RDWR)) < 0) { perror ("open master"); return(-1); }

        return (master_fd);
}

int pty_slave (int master_fd) { int slave_fd; char *slavename; struct termios termios;

if (grantpt (master_fd) < 0) { close(master_fd); perror ("grantpt"); return(-1); }

if (unlockpt (master_fd) < 0) { close(master_fd); perror ("unlockpt"); return(-1); }

slavename = ptsname (master_fd); if (slavename == NULL) { close(master_fd); perror ("ptsname"); return(-1); }

printf ("Slavename: %s\n", slavename);

slave_fd = open (slavename, O_RDWR); if (slave_fd < 0) { close(master_fd); perror ("open slave"); return(-1); }

if (ioctl (slave_fd, I_PUSH, "ptem") == -1) { close(master_fd); perror ("ptem"); return(-1); }

if (ioctl (slave_fd, I_PUSH, "ldterm") == -1) { close(master_fd); perror ("ldterm"); return(-1); }

if ((tcgetattr (slave_fd, &termios)) == -1)
        perror ("tcgetattr");
        return (slave_fd);
}
void main (void)
{
        int master_fd, slave_fd, childpid;

master_fd = pty_master(); if (master_fd < 0) { fprintf(stderr, "cannot open master pty"); exit(-1); }

if ((childpid = fork ()) < 0) { fprintf(stderr, "cannot fork"); exit(-1); }

if (childpid == 0)
{
        slave_fd = pty_slave (master_fd);
        if (slave_fd < 0)
        {
                fprintf(stderr,"cannot open slave pty");
                exit(-1);
        }
                close(master_fd);
                printf("Child: pausing...\n"); fflush(stdout);
                pause ();
        }
        else
        {
                printf("Parent: pausing...\n"); fflush(stdout);
                pause ();
        }
        exit(0);
}

Cause

The streams, ldterm and ptem drivers do not correctly support the ioctl(S) used within the tcgetattr(S) routine.

Solution

This problem has been reported to SCO Engineering and is scheduled to be corrected in a future release of SCO OpenServer.

From the Xinuos technical article database, record 105187. Reproduced with permission. The original is at www.sco.com/ta/105187, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.