Changeset e9712e78 in rtems


Ignore:
Timestamp:
Aug 23, 2021, 4:43:23 PM (8 weeks ago)
Author:
Ryan Long <ryan.long@…>
Branches:
5
Children:
cfef84a0
Parents:
ff94ddc
git-author:
Ryan Long <ryan.long@…> (08/23/21 16:43:23)
git-committer:
Joel Sherrill <joel@…> (09/20/21 18:48:14)
Message:

pxcdevctl: Adjust for standard (5 branch)

psxdevctl is supposed to return the value in errno. Before, it was
returning -1 and setting errno. Changed the tests to reflect these
changes. Added code from RRADE's posix_devctl.c.

Closes #4505

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/posix_devctl.c

    rff94ddc re9712e78  
    3636
    3737#include  <unistd.h>
     38#include  <fcntl.h>
    3839
    3940int posix_devctl(
     
    4546)
    4647{
     48  int rv = 0;
     49
     50  /*
     51   * posix_devctl() is supposed to return an errno. eerno needs to be
     52   * preserved in spite of calling methods (e.g., close, fcntl, and ioctl)
     53   * that set it.
     54   */
     55  int errno_copy = errno;
     56
    4757  /*
    4858   * The POSIX 1003.26 standard allows for library implementations
     
    7383
    7484  /*
    75    * The FACE Technical Standard Edition 3.0 and newer requires the SOCKCLOSE
    76    * ioctl command. This is because the Security Profile does not include
    77    * close() and applications need a way to close sockets. Closing sockets is
    78    * a minimum requirement so using close() in the implementation meets that
    79    * requirement but also lets the application close other file types.
     85   *
    8086   */
    81   if (dcmd == SOCKCLOSE ) {
    82     return close(fd);
     87  switch (dcmd) {
     88
     89    /*
     90     * The FACE Technical Standard Edition 3.0 and newer requires the SOCKCLOSE
     91     * ioctl command. This is because the Security Profile does not include
     92     * close() and applications need a way to close sockets. Closing sockets is
     93     * a minimum requirement so using close() in the implementation meets that
     94     * requirement but also lets the application close other file types.
     95     */
     96    case SOCKCLOSE:
     97      if (close(fd) != 0) {
     98        rv = errno;
     99        errno = errno_copy;
     100
     101        return rv;
     102      }
     103      break;
     104
     105    /*
     106     * The FACE Technical Standard Edition 3.0 and newer requires the
     107     * posix_devctl command to support the FIONBIO subcommand.
     108     */
     109    case FIONBIO: {
     110      int tmp_flag;
     111      int flag;
     112
     113      if (nbyte != sizeof(int)) {
     114        return EINVAL;
     115      }
     116
     117      tmp_flag = fcntl(fd, F_GETFL, 0);
     118      if (tmp_flag == -1) {
     119        rv = errno;
     120        errno = errno_copy;
     121
     122        return rv;
     123      }
     124
     125      flag = *(int *)dev_data_ptr;
     126
     127      if (flag != 0) {
     128        tmp_flag |= O_NONBLOCK;
     129      } else {
     130        tmp_flag &= ~O_NONBLOCK;
     131      }
     132
     133      (void) fcntl(fd, F_SETFL, tmp_flag);
     134      break;
     135    }
     136
     137    default:
     138      if (ioctl(fd, dcmd, dev_data_ptr) != 0) {
     139        rv = errno;
     140        errno = errno_copy;
     141
     142        return errno;
     143      }
     144      break;
    83145  }
    84146
    85   return ioctl(fd, dcmd, dev_data_ptr);
     147  errno = errno_copy;
     148
     149  return rv;
    86150}
  • testsuites/psxtests/psxdevctl01/test.c

    rff94ddc re9712e78  
    5454  void   *dev_data_ptr;
    5555  size_t  nbyte;
    56   int     dev_info;
    5756
    5857  TEST_BEGIN();
    5958
    60   puts( "posix_devctl() FIONBIO on stdin return dev_info -- EBADF" );
    61   fd = 0;
    62   dcmd = FIONBIO;
    63   dev_data_ptr = &dev_data;
    64   nbyte = sizeof(dev_data);
    65   status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, &dev_info );
    66   rtems_test_assert( status == -1 );
    67   rtems_test_assert( errno == EBADF );
    68   rtems_test_assert( dev_info == 0 );
    69 
    70   puts( "posix_devctl() FIONBIO on stdin NULL dev_info -- EBADF" );
    71   fd = 0;
    72   dcmd = FIONBIO;
    73   dev_data_ptr = NULL;
    74   nbyte = 0;
    75   status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
    76   rtems_test_assert( status == -1 );
    77   rtems_test_assert( errno == EBADF );
    78 
    7959  puts( "posix_devctl() SOCKCLOSE on invalid file descriptor -- EBADF" );
    80   fd = 21;
     60  fd = -1;
    8161  dcmd = SOCKCLOSE;
    8262  dev_data_ptr = NULL;
    8363  nbyte = 0;
    8464  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
    85   rtems_test_assert( status == -1 );
    86   rtems_test_assert( errno == EBADF );
     65  rtems_test_assert( status == EBADF );
    8766
    8867  /*
     
    10382  rtems_test_assert( status == -1 );
    10483  rtems_test_assert( errno == EBADF );
     84
     85  puts( "posix_devctl() FIONBIO with invalid nbyte -- EINVAL" );
     86  fd = 0;
     87  dcmd = FIONBIO;
     88  dev_data_ptr = NULL;
     89  nbyte = 0;
     90  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
     91  rtems_test_assert( status == EINVAL );
     92
     93  puts( "posix_devctl() FIONBIO with invalid file descriptor -- EBADF" );
     94  fd = -1;
     95  dcmd = FIONBIO;
     96  dev_data_ptr = NULL;
     97  nbyte = sizeof(int);
     98  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
     99  rtems_test_assert( status == EBADF );
     100
     101  puts( "posix_devctl() FIONBIO flag not zero -- 0" );
     102  fd = 0;
     103  dcmd = FIONBIO;
     104  dev_data = 1;
     105  dev_data_ptr = &dev_data;
     106  nbyte = sizeof(int);
     107  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
     108  rtems_test_assert( status == 0 );
     109
     110  puts( "posix_devctl() FIONBIO flag is zero -- 0" );
     111  fd = 0;
     112  dcmd = FIONBIO;
     113  dev_data = 0;
     114  dev_data_ptr = &dev_data;
     115  nbyte = sizeof(int);
     116  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
     117  rtems_test_assert( status == 0 );
     118
     119  puts( "posix_devctl() dcmd not valid value -- EBADF" );
     120  fd = 0;
     121  dcmd = 1;
     122  dev_data = 0;
     123  dev_data_ptr = &dev_data;
     124  nbyte = sizeof(int);
     125  status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
     126  rtems_test_assert( status == EBADF );
     127
    105128  TEST_END();
    106129  exit(0);
Note: See TracChangeset for help on using the changeset viewer.