Menu

#24 v1.09 TIOCSCTTY error

v1.06
fixed
1.09 (1)
5
2023-02-12
2022-05-04
No

Hi,
Version 1.09 is not working at all (also with -p switch)

:; /usr/bin/sshpass -V | head -1
sshpass 1.09

:; SSHPASS=*** /usr/bin/sshpass -e ssh -t ...
sshpass: Failed to set controlling terminal in child (TIOCSCTTY): Inappropriate ioctl for device

Version 1.08 does.

Best regards

Discussion

  • Shachar Shemesh

    Shachar Shemesh - 2022-05-04

    Can you please provide relevant details. What OS is this, where is the package from (i.e. - compiled by you or pre-packaged. If the later, by whom)?

     
  • Predrag Zečević

    It is OpenIndiana (fork from OpenSolaris):

    :; uname -rosv
    SunOS 5.11 illumos-1e6b83029f illumos
    

    Packaged by team: https://github.com/OpenIndiana/oi-userland/tree/oi/hipster/components/network/sshpass

    I have compiled v 1.08 from source file found here, with GCC 10:

    :; ./configure --prefix=/pz/SFW
    :; gmake install
    
    :; file /pz/SFW/bin/sshpass
    /pz/SFW/bin/sshpass: ELF 64-bit LSB executable, x86-64, version 1 (Solaris), dynamically linked, interpreter /usr/lib/amd64/ld.so.1, with debug_info, not stripped
    :; ldd /pz/SFW/bin/sshpass 
            libstdc++.so.6 =>        /usr/lib/amd64/libstdc++.so.6
            libresolv.so.2 =>        /usr/lib/amd64/libresolv.so.2
            libsocket.so.1 =>        /usr/lib/amd64/libsocket.so.1
            libnsl.so.1 =>   /usr/lib/amd64/libnsl.so.1
            libm.so.2 =>     /usr/lib/amd64/libm.so.2
            libintl.so.1 =>  /usr/lib/amd64/libintl.so.1
            libc.so.1 =>     /usr/lib/amd64/libc.so.1
            libgcc_s.so.1 =>         /usr/lib/64/libgcc_s.so.1
            libmd.so.1 =>    /lib/64/libmd.so.1
            libmp.so.2 =>    /lib/64/libmp.so.2
    

    UPDATE:

    • Version 1.09 (built using same command used to compile 1.08) throws TIOCSCTTY error
    • What is difference between those 2 version?
     

    Last edit: Predrag Zečević 2022-05-04
  • Shachar Shemesh

    Shachar Shemesh - 2022-05-28

    I tried installing it inside a VM, but I don't know how to install the dependencies. Can you explain the steps needed to turn a bare install to one that is capable of compiling sshpass?

     
    • Predrag Zečević

      Hi,

      you have to install build-essential meta package (it will install all development tools, full list of included packages at https://pkg.openindiana.org/hipster/manifest/0/metapackages%2Fbuild-essential%401.0%2C5.11-2022.0.0.1%3A20220117T192224Z)

      GCC suite is installed under /usr/gcc directory, so you have to adjust your environment variables.
      For example, I have installed several compilers:

      developer/gcc-10                                  10.3.0-2020.0.1.3          i--
      developer/gcc-11                                  11.3.0-2022.0.0.0          i--
      developer/gcc-7                                   7.5.0-2020.0.1.9           i--
      

      e.g.

      :; ls -1d /usr/gcc/*
      /usr/gcc/10
      /usr/gcc/11
      /usr/gcc/7
      

      So, issue:

      :; pfexec pkg install -v build-essential
      

      Best regards.

       

      Last edit: Predrag Zečević 2022-05-30
  • Predrag Zečević

    Any news on this?

     
  • Marcin Olszewski

    In fact, looks like there are two bugs in the code:
    1) per tty_ioctl's documentation, the TIOCSCTTY option requires an int argument, while none is provided here. Adding a zero solves the invalid argument problem (the only value mentioned is 1 and it is for root only)
    NOTE: because of the way the documentation is formatted, it is easy to treat the description for TIOCNOTTY - which says about a void argument - as the second part for TIOCSCTTY.
    3) Once the invalid argument is resolved, we'll face the 'operation not permitted' error. This is because, per tty_ioctl doc:
    The calling process must be a session leader and not have a controlling terminal already. If this terminal is already the controlling terminal of a different session group then the ioctl fails with EPERM
    Now, the condition is false because a call to open only specified the O_RDWR flag - while the documentation to open includes the O_NOCTTY flag which is described as:
    O_NOCTTY
    If pathname refers to a terminal device—see tty(4)—it will
    not become the process's controlling terminal even if the
    process does not have one.
    So in the absence of that flag, the open() must have already assigned the slave terminal as the controlling terminal and then a call to ioctl failed.
    A resolution is to add the O_NOCTTY flag to the call to open(); my working code is this:

    (...)
            // This line makes the ptty our controlling tty. We do not otherwise need it open
    #ifndef TIOCSCTTY
            slavept=open(name, O_RDWR);
    #else        
            slavept=open(name, O_RDWR | O_NOCTTY);
            // On some systems, an open(2) is insufficient to set the
            // controlling tty (see the documentation for TIOCSCTTY in
            // tty(4)).
            if (ioctl(slavept, TIOCSCTTY, 0) == -1) {
                perror("sshpass: Failed to set controlling terminal in child (TIOCSCTTY)");
                exit(RETURN_RUNTIME_ERROR);
            }
    #endif
            close( slavept );
    (...)
    
     
    ❤️
    2
  • Predrag Zečević

    HI!

    I have tested this patch, and it has worked!
    Many thanks.

     
  • Predrag Zečević

    Adding patch file (NOTE: it was tested only on OpenIndiana platform):

    :; patch -u main.c -i sshpass-1.09.main_c.patch
    

    Patch file was created by comparing original and modified file:

    :; diff -Naur sshpass-1.09-tar/main.c sshpass-1.09/main.c
    

    Regards.

     
    👍
    2
  • Iakov Kirilenko

    Iakov Kirilenko - 2023-02-09

    This patch helps to fix well known issue also for msys/mingw too. As I can see, there are no obvious reasons for regression with this change. Thanks.

     
  • Shachar Shemesh

    Shachar Shemesh - 2023-02-12

    Fix is pushed to repo. Thank you, everyone.

     
  • Shachar Shemesh

    Shachar Shemesh - 2023-02-12
    • status: open --> fixed
     
  • Shachar Shemesh

    Shachar Shemesh - 2023-02-12

    Release 1.10 now has the fix.

     

Log in to post a comment.