Print this page
3910 t_look(3NSL) should never return T_ERROR

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/bnu/interface.c
          +++ new/usr/src/cmd/bnu/interface.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright 2014 Gary Mills
  23   24   * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30      -
  31      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  32      -/*      interface( label )
  33      -        provide alternate definitions for the I/O functions through global
  34      -        interfaces.
  35      -*/
       31 +/*
       32 + *      interface(label)
       33 + *      provide alternate definitions for the I/O functions through global
       34 + *      interfaces.
       35 + */
  36   36  #include        "uucp.h"
  37   37  
  38   38  #ifdef TLI
  39   39  #include        <tiuser.h>
  40   40  char *t_alloc();
  41   41  int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis();
  42   42  int t_getinfo(), t_getstate(), t_look(), t_rcv(), t_snd(), t_sync(), t_unbind();
  43   43  #endif /*  TLI  */
  44   44  
  45   45  #ifdef DATAKIT
↓ open down ↓ 8 lines elided ↑ open up ↑
  54   54  #if defined(__STDC__)
  55   55  extern int      ioctl(int, int, ...);
  56   56  #else
  57   57  extern int      ioctl();
  58   58  #endif
  59   59  static int      usetup(), uteardown();
  60   60  
  61   61  GLOBAL ssize_t  (*Read)() = read,
  62   62          (*Write)() = write;
  63   63  #if defined(__STDC__)
  64      -GLOBAL int      (*Ioctl)(int,int,...) = ioctl,
       64 +GLOBAL int      (*Ioctl)(int, int, ...) = ioctl,
  65   65  #else
  66   66  GLOBAL int      (*Ioctl)() = ioctl,
  67   67  #endif
  68   68          (*Setup)() = usetup,
  69   69          (*Teardown)() = uteardown;
  70   70  
  71   71  #ifdef TLI
  72   72  EXTERN void tfaillog(), show_tlook();
  73   73  static ssize_t  tread(), twrite();      /* TLI i/o */
  74   74  #ifdef __STDC__
  75   75  static int      tioctl(int, int, ...),
  76   76  #else
  77   77  static int      tioctl(),               /* TLI i/o control */
  78   78  #endif
  79      -                tsetup(),               /* TLI setup without streams module */
  80      -                tssetup(),              /* TLI setup with streams module */
  81      -                tteardown();            /* TLI teardown, works with either setup
  82      -                                        */
       79 +                tsetup(),       /* TLI setup without streams module */
       80 +                tssetup(),      /* TLI setup with streams module */
       81 +                tteardown();    /* TLI teardown, works with either setup */
  83   82  #endif /*  TLI  */
  84      -/*      The IN_label in Interface[] imply different caller routines:
  85      -        e.g. tlicall().
  86      -        If so, the names here and the names in callers.c must match.
  87      -*/
       83 +/*
       84 + *      The IN_label in Interface[] imply different caller routines:
       85 + *      e.g. tlicall().
       86 + *      If so, the names here and the names in callers.c must match.
       87 + */
  88   88  
  89   89  static
  90      -  struct Interface {
       90 +struct Interface {
  91   91          char    *IN_label;              /* interface name */
  92   92          ssize_t (*IN_read)();           /* read function */
  93   93          ssize_t (*IN_write)();          /* write function */
  94   94  #ifdef __STDC__
  95      -        int     (*IN_ioctl)(int,int,...);
       95 +        int     (*IN_ioctl)(int, int, ...);
  96   96  #else
  97   97          int     (*IN_ioctl)();          /* ioctl function */
  98   98  #endif
  99      -        int     (*IN_setup)();          /* setup function, called before first
 100      -                                        i/o operation */
 101      -        int     (*IN_teardown)();       /* teardown function, called after last
 102      -                                        i/o operation */
       99 +        int     (*IN_setup)();          /* setup function, called before */
      100 +                                        /* first i/o operation */
      101 +        int     (*IN_teardown)();       /* teardown function, called after */
      102 +                                        /* last i/o operation */
 103  103  } Interface[] = {
 104  104                          /* vanilla UNIX */
 105  105                  { "UNIX", read, write, ioctl, usetup, uteardown },
 106  106  #ifdef TCP
 107  107                          /* TCP over sockets or UNET */
 108  108                  { "TCP", read, write, ioctl, usetup, uteardown },
 109  109  #endif /* TCP */
 110  110  #ifdef SYTEK
 111  111                          /* Sytek network */
 112  112                  { "Sytek", read, write, ioctl, usetup, uteardown },
↓ open down ↓ 12 lines elided ↑ open up ↑
 125  125  #ifdef TLIS
 126  126                          /* AT&T Transport Interface Library WITH streams */
 127  127                  { "TLIS", read, write, tioctl, tssetup, uteardown },
 128  128  #endif /*  TLIS  */
 129  129  #endif /*  TLI  */
 130  130  #ifdef DATAKIT
 131  131                  { "DK", read, write, ioctl, dksetup, dkteardown },
 132  132  #endif /* DATAKIT */
 133  133  #ifdef UNET
 134  134                  { "Unetserver", read, write, ioctl, usetup, uteardown },
 135      -#endif          
      135 +#endif
 136  136                  { 0, 0, 0, 0, 0, 0 }
 137  137          };
 138  138  
 139  139  
 140  140  GLOBAL int
 141  141  interface(label)
 142  142  char    *label;
 143  143  {
 144  144          register int    i;
 145  145  
 146      -        for ( i = 0;  Interface[i].IN_label;  ++i ) {
 147      -                if( !strcmp( Interface[i].IN_label, label ) ) {
      146 +        for (i = 0;  Interface[i].IN_label;  ++i) {
      147 +                if (0 == strcmp(Interface[i].IN_label, label)) {
 148  148                          Read = Interface[i].IN_read;
 149  149                          Write = Interface[i].IN_write;
 150  150                          Ioctl = Interface[i].IN_ioctl;
 151  151                          Setup = Interface[i].IN_setup;
 152  152                          Teardown = Interface[i].IN_teardown;
 153  153                          DEBUG(5, "set interface %s\n", label);
 154      -                        return( 0 );
      154 +                        return (0);
 155  155                  }
 156  156          }
 157      -        return( FAIL );
      157 +        return (FAIL);
 158  158  }
 159  159  
 160  160  /*
 161  161   *      usetup - vanilla unix setup routine
 162  162   */
 163  163  static int
 164      -usetup( role, fdreadp, fdwritep )
      164 +usetup(role, fdreadp, fdwritep)
 165  165  int     *fdreadp, *fdwritep;
 166  166  {
 167      -        if ( role == SLAVE )
      167 +        if (role == SLAVE)
 168  168          {
 169  169                  *fdreadp = 0;
 170  170                  *fdwritep = 1;
 171  171                  /* 2 has been re-opened to RMTDEBUG in main() */
 172  172          }
 173      -        return(SUCCESS);
      173 +        return (SUCCESS);
 174  174  }
 175  175  
 176  176  /*
 177  177   *      uteardown - vanilla unix teardown routine
 178  178   */
 179  179  static int
 180      -uteardown( role, fdread, fdwrite )
      180 +uteardown(role, fdread, fdwrite)
 181  181  {
 182  182          int ret;
 183  183          char *ttyn;
 184  184  
 185  185          if (role == SLAVE) {
 186  186                  ret = restline();
 187  187                  DEBUG(4, "ret restline - %d\n", ret);
 188  188                  if (fdread != -1)
 189  189                          sethup(fdread);
 190  190          }
 191  191          if (fdread != -1) {
 192  192                  ttyn = ttyname(fdread);
 193  193                  if (ttyn != NULL && Dev_mode != 0)
 194  194                          chmod(ttyn, Dev_mode);  /* can fail, but who cares? */
 195  195                  (void) close(fdread);
 196  196                  (void) close(fdwrite);
 197  197          }
 198      -        return(SUCCESS);
      198 +        return (SUCCESS);
 199  199  }
 200  200  
 201  201  #ifdef DATAKIT
 202  202  /*
 203  203   *      dksetup - DATAKIT setup routine
 204  204   *
 205  205   * Put line in block mode.
 206  206   */
 207  207  
 208  208  static int
 209      -dksetup (role, fdreadp, fdwritep)
      209 +dksetup(role, fdreadp, fdwritep)
 210  210  
 211  211  int     role;
 212      -int *   fdreadp;
 213      -int *   fdwritep;
      212 +int     *fdreadp;
      213 +int     *fdwritep;
 214  214  
 215  215  {
 216  216          static short dkrmode[3] = { DKR_BLOCK | DKR_TIME, 0, 0 };
 217  217          int     ret;
 218  218  
 219  219          (void) usetup(role, fdreadp, fdwritep);
 220      -        if((ret = (*Ioctl)(*fdreadp, DIOCRMODE, dkrmode)) < 0) {
      220 +        if ((ret = (*Ioctl)(*fdreadp, DIOCRMODE, dkrmode)) < 0) {
 221  221                  DEBUG(4, "dksetup: failed to set block mode. ret=%d,\n", ret);
 222  222                  DEBUG(4, "read fd=%d, ", *fdreadp);
 223  223                  DEBUG(4, "errno=%d\n", errno);
 224      -                return(FAIL);
      224 +                return (FAIL);
 225  225          }
 226      -        return(SUCCESS);
      226 +        return (SUCCESS);
 227  227  }
 228  228  
 229  229  /*
 230  230   *      dkteardown  -  DATAKIT teardown routine
 231  231   */
 232  232  static int
 233      -dkteardown( role, fdread, fdwrite )
      233 +dkteardown(role, fdread, fdwrite)
 234  234  int     role, fdread, fdwrite;
 235  235  {
 236  236          char    *ttyn;
 237  237  
 238      -        if ( role == MASTER ) {
      238 +        if (role == MASTER) {
 239  239                  ttyn = ttyname(fdread);
 240      -                if ( ttyn != NULL && Dev_mode != 0 )
      240 +                if (ttyn != NULL && Dev_mode != 0)
 241  241                          chmod(ttyn, Dev_mode);  /* can fail, but who cares? */
 242  242          }
 243  243  
 244  244          /*      must flush fd's for datakit     */
 245  245          /*      else close can hang             */
 246      -        if ( ioctl(fdread, DIOCFLUSH, NULL) != 0 )
 247      -                DEBUG(4, "dkteardown: DIOCFLUSH of input fd %d failed", fdread);
 248      -        if ( ioctl(fdwrite, DIOCFLUSH, NULL) != 0 )
 249      -                DEBUG(4, "dkteardown: DIOCFLUSH of output fd %d failed", fdwrite);
      246 +        if (ioctl(fdread, DIOCFLUSH, NULL) != 0)
      247 +                DEBUG(4, "dkteardown: DIOCFLUSH of input fd %d failed",
      248 +                    fdread);
      249 +        if (ioctl(fdwrite, DIOCFLUSH, NULL) != 0)
      250 +                DEBUG(4, "dkteardown: DIOCFLUSH of output fd %d failed",
      251 +                    fdwrite);
 250  252  
 251      -        (void)close(fdread);
 252      -        (void)close(fdwrite);
 253      -        return(SUCCESS);
      253 +        (void) close(fdread);
      254 +        (void) close(fdwrite);
      255 +        return (SUCCESS);
 254  256  }
 255  257  #endif /* DATAKIT */
 256  258  
 257  259  
 258  260  #ifdef TLI
 259  261  /*
 260  262   *      tread - tli read routine
 261  263   */
 262  264  static ssize_t
 263  265  tread(fd, buf, nbytes)
 264  266  int             fd;
 265  267  char            *buf;
 266  268  unsigned        nbytes;
 267  269  {
 268  270          int             rcvflags;
 269  271  
 270      -        return((ssize_t)t_rcv(fd, buf, nbytes, &rcvflags));
      272 +        return ((ssize_t)t_rcv(fd, buf, nbytes, &rcvflags));
 271  273  }
 272  274  
 273  275  /*
 274  276   *      twrite - tli write routine
 275  277   */
 276  278  #define N_CHECK 100
 277  279  static ssize_t
 278  280  twrite(fd, buf, nbytes)
 279  281  int             fd;
 280  282  char            *buf;
 281  283  unsigned        nbytes;
 282  284  {
 283  285          register int            i, ret;
 284  286          static int              n_writ, got_info;
 285  287          static struct t_info    info;
 286  288  
 287      -        if ( got_info == 0 ) {
 288      -                if ( t_getinfo(fd, &info) != 0 ) {
      289 +        if (got_info == 0) {
      290 +                if (t_getinfo(fd, &info) != 0) {
 289  291                          tfaillog(fd, "twrite: t_getinfo\n");
 290      -                        return(FAIL);
      292 +                        return (FAIL);
 291  293                  }
 292  294                  got_info = 1;
 293  295          }
 294  296  
 295  297          /* on every N_CHECKth call, check that are still in DATAXFER state */
 296      -        if ( ++n_writ == N_CHECK ) {
      298 +        if (++n_writ == N_CHECK) {
 297  299                  n_writ = 0;
 298      -                if ( t_getstate(fd) != T_DATAXFER )
 299      -                        return(FAIL);
 300      -        }       
      300 +                if (t_getstate(fd) != T_DATAXFER)
      301 +                        return (FAIL);
      302 +        }
 301  303  
 302      -        if ( info.tsdu <= 0 || nbytes <= info.tsdu )
 303      -                return(t_snd(fd, buf, nbytes, NULL));
      304 +        if (info.tsdu <= 0 || nbytes <= info.tsdu)
      305 +                return (t_snd(fd, buf, nbytes, NULL));
 304  306  
 305  307          /* if get here, then there is a limit on transmit size  */
 306  308          /* (info.tsdu > 0) and buf exceeds it                   */
 307  309          i = ret = 0;
 308      -        while ( nbytes >= info.tsdu ) {
 309      -                if ( (ret = t_snd(fd,  &buf[i], info.tsdu, NULL)) != info.tsdu )
 310      -                        return( ( ret >= 0 ? (i + ret) : ret ) );
      310 +        while (nbytes >= info.tsdu) {
      311 +                if ((ret = t_snd(fd,  &buf[i], info.tsdu, NULL)) != info.tsdu)
      312 +                        return ((ret >= 0 ? (i + ret) : ret));
 311  313                  i += info.tsdu;
 312  314                  nbytes -= info.tsdu;
 313  315          }
 314      -        if ( nbytes != 0 ) {
 315      -                if ( (ret = t_snd(fd,  &buf[i], nbytes, NULL)) != nbytes )
 316      -                        return( (ssize_t)( ret >= 0 ? (i + ret) : ret ) );
      316 +        if (nbytes != 0) {
      317 +                if ((ret = t_snd(fd,  &buf[i], nbytes, NULL)) != nbytes)
      318 +                        return ((ssize_t)(ret >= 0 ? (i + ret) : ret));
 317  319                  i += nbytes;
 318  320          }
 319      -        return((ssize_t)i);
      321 +        return ((ssize_t)i);
 320  322  }
 321  323  
 322  324  
 323  325  /*
 324  326   *      tioctl - stub for tli ioctl routine
 325  327   */
 326  328  /*ARGSUSED*/
 327  329  static int
 328  330  #ifdef __STDC__
 329  331  tioctl(int fd, int request, ...)
 330  332  #else
 331  333  tioctl(fd, request, arg)
 332  334  int     fd, request;
 333  335  #endif
 334  336  {
 335      -        return(SUCCESS);
      337 +        return (SUCCESS);
 336  338  }
 337  339  
 338  340  /*
 339  341   *      tsetup - tli setup routine
 340  342   *      note blatant assumption that *fdreadp == *fdwritep == 0
 341  343   */
 342  344  static int
 343      -tsetup( role, fdreadp, fdwritep )
      345 +tsetup(role, fdreadp, fdwritep)
 344  346  int     *fdreadp, *fdwritep;
 345  347  {
 346  348  
 347      -        if ( role == SLAVE ) {
      349 +        if (role == SLAVE) {
 348  350                  *fdreadp = 0;
 349  351                  *fdwritep = 1;
 350  352                  /* 2 has been re-opened to RMTDEBUG in main() */
 351  353                  errno = t_errno = 0;
 352      -                if ( t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1 ) {
      354 +                if (t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1) {
 353  355                          tfaillog(*fdreadp, "tsetup: t_sync\n");
 354      -                        return(FAIL);
      356 +                        return (FAIL);
 355  357                  }
 356  358          }
 357      -        return(SUCCESS);
      359 +        return (SUCCESS);
 358  360  }
 359  361  
 360  362  /*
 361  363   *      tteardown - tli shutdown routine
 362  364   */
 363  365  /*ARGSUSED*/
 364  366  static int
 365      -tteardown( role, fdread, fdwrite )
      367 +tteardown(role, fdread, fdwrite)
 366  368  {
 367      -        (void)t_unbind(fdread);
 368      -        (void)t_close(fdread);
 369      -        return(SUCCESS);
      369 +        (void) t_unbind(fdread);
      370 +        (void) t_close(fdread);
      371 +        return (SUCCESS);
 370  372  }
 371  373  
 372  374  #ifdef TLIS
 373  375  /*
 374  376   *      tssetup - tli, with streams module, setup routine
 375  377   *      note blatant assumption that *fdreadp == *fdwritep
 376  378   */
 377  379  static int
 378      -tssetup( role, fdreadp, fdwritep )
      380 +tssetup(role, fdreadp, fdwritep)
 379  381  int     role;
 380  382  int     *fdreadp;
 381  383  int     *fdwritep;
 382  384  {
 383      -        if ( role == SLAVE ) {
      385 +        if (role == SLAVE) {
 384  386                  *fdreadp = 0;
 385  387                  *fdwritep = 1;
 386  388                  /* 2 has been re-opened to RMTDEBUG in main() */
 387  389                  DEBUG(5, "tssetup: SLAVE mode: leaving ok\n%s", "");
 388      -                return(SUCCESS);
      390 +                return (SUCCESS);
 389  391          }
 390  392  
 391  393          DEBUG(4, "tssetup: MASTER mode: leaving ok\n%s", "");
 392      -        return(SUCCESS);
      394 +        return (SUCCESS);
 393  395  }
 394  396  
 395  397  /*
 396  398   *      Report why a TLI call failed.
 397  399   */
 398  400  GLOBAL void
 399  401  tfaillog(fd, s)
 400  402  int     fd;
 401  403  char    *s;
 402  404  {
 403  405          char    fmt[ BUFSIZ ];
 404  406  
 405  407          if (0 < t_errno && t_errno < t_nerr) {
 406      -                sprintf( fmt, "%s: %%s\n", s );
      408 +                sprintf(fmt, "%s: %%s\n", s);
 407  409                  DEBUG(5, fmt, t_errlist[t_errno]);
 408  410                  logent(s, t_errlist[t_errno]);
 409      -                if ( t_errno == TSYSERR ) {
      411 +                if (t_errno == TSYSERR) {
 410  412                          strcpy(fmt, "tlicall: system error: %s\n");
 411  413                          DEBUG(5, fmt, strerror(errno));
 412      -                } else if ( t_errno == TLOOK ) {
      414 +                } else if (t_errno == TLOOK) {
 413  415                          show_tlook(fd);
 414  416                  }
 415  417          } else {
 416  418                  sprintf(fmt, "unknown tli error %d", t_errno);
 417  419                  logent(s, fmt);
 418  420                  sprintf(fmt, "%s: unknown tli error %d", s, t_errno);
 419  421                  DEBUG(5, fmt, 0);
 420  422                  sprintf(fmt, "%s: %%s\n", s);
 421  423                  DEBUG(5, fmt, strerror(errno));
 422  424          }
 423      -        return;
 424  425  }
 425  426  
 426  427  GLOBAL void
 427  428  show_tlook(fd)
 428  429  int fd;
 429  430  {
 430  431          register int reason;
 431  432          register char *msg;
 432  433          extern int      t_errno;
 433  434  /*
 434  435   * Find out the current state of the interface.
 435  436   */
 436  437          errno = t_errno = 0;
 437      -        switch( reason = t_getstate(fd) ) {
      438 +        switch (reason = t_getstate(fd)) {
 438  439          case T_UNBND:           msg = "T_UNBIND";       break;
 439  440          case T_IDLE:            msg = "T_IDLE";         break;
 440  441          case T_OUTCON:          msg = "T_OUTCON";       break;
 441  442          case T_INCON:           msg = "T_INCON";        break;
 442  443          case T_DATAXFER:        msg = "T_DATAXFER";     break;
 443  444          case T_OUTREL:          msg = "T_OUTREL";       break;
 444  445          case T_INREL:           msg = "T_INREL";        break;
 445  446          default:                msg = NULL;             break;
 446  447          }
 447      -        if( msg == NULL )
      448 +        if (msg == NULL)
 448  449                  return;
 449  450  
 450  451          DEBUG(5, "state is %s", msg);
 451      -        switch( reason = t_look(fd) ) {
      452 +        switch (reason = t_look(fd)) {
 452  453          case -1:                msg = ""; break;
 453  454          case 0:                 msg = "NO ERROR"; break;
 454  455          case T_LISTEN:          msg = "T_LISTEN"; break;
 455  456          case T_CONNECT:         msg = "T_CONNECT"; break;
 456  457          case T_DATA:            msg = "T_DATA";  break;
 457  458          case T_EXDATA:          msg = "T_EXDATA"; break;
 458  459          case T_DISCONNECT:      msg = "T_DISCONNECT"; break;
 459  460          case T_ORDREL:          msg = "T_ORDREL"; break;
 460      -        case T_ERROR:           msg = "T_ERROR"; break;
 461  461          case T_UDERR:           msg = "T_UDERR"; break;
 462  462          default:                msg = "UNKNOWN ERROR"; break;
 463  463          }
 464  464          DEBUG(4, " reason is %s\n", msg);
 465  465  
 466      -        if ( reason == T_DISCONNECT )
      466 +        if (reason == T_DISCONNECT)
 467  467          {
 468  468                  struct t_discon *dropped;
 469      -                if ( ((dropped = 
 470      -                        (struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0) 
 471      -                ||  (t_rcvdis(fd, dropped) == -1 )) {
      469 +                if (((dropped =
      470 +                    (struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0) ||
      471 +                    (t_rcvdis(fd, dropped) == -1)) {
 472  472                          if (dropped)
 473  473                                  t_free((char *)dropped, T_DIS);
 474  474                          return;
 475  475                  }
 476  476                  DEBUG(5, "disconnect reason #%d\n", dropped->reason);
 477  477                  t_free((char *)dropped, T_DIS);
 478  478          }
 479      -        return;
 480  479  }
 481  480  
 482  481  #endif /*  TLIS  */
 483  482  
 484  483  #endif /*  TLI  */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX