Bug 198441 - net/socat: changing speed on many serial devices does not work
Summary: net/socat: changing speed on many serial devices does not work
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Emanuel Haupt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-09 01:56 UTC by Alexandre Fenyo
Modified: 2019-04-07 22:05 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (ehaupt)


Attachments
add the content of this file in net/socat/files/patch-xioopts.c - this is a patch for socat 1.7.3.0 (2.75 KB, patch)
2015-03-09 01:56 UTC, Alexandre Fenyo
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre Fenyo 2015-03-09 01:56:17 UTC
Created attachment 154044 [details]
add the content of this file in net/socat/files/patch-xioopts.c - this is a patch for socat 1.7.3.0

With SOCAT on systems where b0 to b4000000 options are not available, like FreeBSD, setting the speed of a TERMIOS terminal is done using the ispeed and ospeed options.

But when using simultaneously ispeed and ospeed parameters with SOCAT, the speed values are set within two distinct ioctl requests, so changing the speed of terminals or devices that need matching input and output returns an Invalid argument error (the TIOCSETA/TIOCSETAW/TIOCSETAF ioctl returns -1 and sets errno to EINVAL).

This is especially the case On FreeBSD, where many tty device drivers need matching input and output speeds:
- those that depend on ucom(4): uark(4), ubsa(4), ubser(4), uftdi(4), umcs(4), uplcom(4), uslcom(4), uvscom(4)
- some others, even not depending on ucom(4): sio(4), digi(4), rp(4)
But some don't: tty(4)

With those drivers, the input and output speeds must match and be set inside a single ioctl request (TIOCSETA, TIOCSETAW or TIOCSETAF). The only exception to this rule is when the input baud rate is zero because, according to POSIX, in that case, the input baud rate is set equal to the output baud rate.

For instance, this call to SOCAT on FreeBSD 10.1 terminates immediately with an EINVAL error:
# socat -d /dev/cuaU2,ispeed=57600,ospeed=57600,echo=0,raw TCP-LISTEN:9000,reuseaddr
2015/03/09 00:43:33 socat[20723] E tcsetattr(3, TCSADRAIN, 0x7fffffffe148): Invalid argument

The attached patch avoids this type of error: when setting both input and output speeds, only one ioctl syscall is performed.
Comment 1 Alexandre Fenyo 2015-03-09 02:11:05 UTC
The patch is for 1.7.3.0_1, that is the current version in the ports tree.
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-04-22 06:55:55 UTC
A commit references this bug:

Author: ehaupt
Date: Wed Apr 22 06:55:25 UTC 2015
New revision: 384479
URL: https://svnweb.freebsd.org/changeset/ports/384479

Log:
  With SOCAT on systems where b0 to b4000000 options are not available, like
  FreeBSD, setting the speed of a TERMIOS terminal is done using the ispeed and
  ospeed options.

  But when using simultaneously ispeed and ospeed parameters with SOCAT, the speed
  values are set within two distinct ioctl requests, so changing the speed of
  terminals or devices that need matching input and output returns an Invalid
  argument error (the TIOCSETA/TIOCSETAW/TIOCSETAF ioctl returns -1 and sets errno
  to EINVAL).

  This is especially the case On FreeBSD, where many tty device drivers need
  matching input and output speeds: - those that depend on ucom(4): uark(4),
  ubsa(4), ubser(4), uftdi(4), umcs(4), uplcom(4), uslcom(4), uvscom(4) - some
  others, even not depending on ucom(4): sio(4), digi(4), rp(4) But some don't:
  tty(4)

  With those drivers, the input and output speeds must match and be set inside a
  single ioctl request (TIOCSETA, TIOCSETAW or TIOCSETAF). The only exception to
  this rule is when the input baud rate is zero because, according to POSIX, in
  that case, the input baud rate is set equal to the output baud rate.

  For instance, this call to SOCAT on FreeBSD 10.1 terminates immediately with an
  EINVAL error: # socat -d /dev/cuaU2,ispeed=57600,ospeed=57600,echo=0,raw
  TCP-LISTEN:9000,reuseaddr 2015/03/09 00:43:33 socat[20723] E tcsetattr(3,
  TCSADRAIN, 0x7fffffffe148): Invalid argument

  Provide a patch that avoids this type of error: when setting both input and
  output speeds, only one ioctl syscall is performed.

  PR:             198441
  Submitted by:   Alexandre Fenyo <fbsd.bugzilla@fenyo.net>

Changes:
  head/net/socat/Makefile
  head/net/socat/files/patch-xioopts.c
Comment 3 Emanuel Haupt freebsd_committer freebsd_triage 2015-04-22 07:03:00 UTC
Committed, thanks. If not already done please also notify upstream (Gerhard Rieger <gerhard@dest-unreach.org>).
Comment 4 Alexandre Fenyo 2015-04-22 07:46:36 UTC
I have already notified upstream (but it is not already taken into account in the upstream distribution)
Thanks
Comment 5 Emanuel Haupt freebsd_committer freebsd_triage 2019-04-07 17:09:09 UTC
Just a quick notice that this issue has been fixed upstream according to:

http://www.dest-unreach.org/socat/doc/CHANGES
Comment 6 Alexandre Fenyo 2019-04-07 22:05:32 UTC
Thanks for the information.