Topics

[ptest-runner][PATCH] Fix inappropriate ioctl when detaching tty

Tero Kinnunen
 

Fixes error

ERROR: Unable to detach from controlling tty, Inappropriate ioctl for device

when running multiple ptests

ptest-runner a b

or when invoked over ssh single command, like

$ ssh localhost ptest-runner a

For ssh case, fd 0 is not a tty. (isatty(0) is false).
When running multiple ptests, deattach for parent needs to be
done only once. On subsequent calls, if deattach fails,
according to man 4 tty

it is obviously not attached to a terminal and does not
need to detach itself.

Detach was not necessary, skip the error message.

Signed-off-by: Tero Kinnunen <tero.kinnunen@...>
---
utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils.c b/utils.c
index a8ba190..35ef551 100644
--- a/utils.c
+++ b/utils.c
@@ -444,7 +444,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
break;
}
dirname(ptest_dir);
- if (ioctl(0, TIOCNOTTY) == -1) {
+ if (ioctl(0, TIOCNOTTY) == -1 && errno != ENOTTY) {
fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
}

--
2.25.1

Anibal Limon
 

Hi Tero,

First thanks for the patch, Is there an option to test for isatty(fd) for run ioctl instead?.

Regards,
Anibal

On Tue, 7 Jul 2020 at 02:21, Tero Kinnunen <tero.kinnunen@...> wrote:
Fixes error

    ERROR: Unable to detach from controlling tty, Inappropriate ioctl for device

when running multiple ptests

    ptest-runner a b

or when invoked over ssh single command, like

    $ ssh localhost ptest-runner a

For ssh case, fd 0 is not a tty. (isatty(0) is false).
When running multiple ptests, deattach for parent needs to be
done only once. On subsequent calls, if deattach fails,
according to man 4 tty

    it is obviously not attached to a terminal and does not
    need to detach itself.

Detach was not necessary, skip the error message.

Signed-off-by: Tero Kinnunen <tero.kinnunen@...>
---
 utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils.c b/utils.c
index a8ba190..35ef551 100644
--- a/utils.c
+++ b/utils.c
@@ -444,7 +444,7 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
                                break;
                        }
                        dirname(ptest_dir);
-                       if (ioctl(0, TIOCNOTTY) == -1) {
+                       if (ioctl(0, TIOCNOTTY) == -1 && errno != ENOTTY) {
                                fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
                        }

--
2.25.1

Tero Kinnunen
 

On Tue, Jul 7, 2020 at 06:49 AM, Anibal Limon wrote:
First thanks for the patch, Is there an option to test for isatty(fd) for run ioctl instead?.
Hi Anibal,

    if (isatty(0) && ioctl(0, TIOCNOTTY) == -1)

would help for ssh case but not to errors between tests. There fd 0 is a tty but detach should
be done only once. Now it is inside loop. It could work if it was also moved outside the loop,
before PTEST_LIST_ITERATE_START?

Kind regards,

    - Tero

Anibal Limon
 



On Wed, 8 Jul 2020 at 01:46, Tero Kinnunen <tero.kinnunen@...> wrote:
On Tue, Jul 7, 2020 at 06:49 AM, Anibal Limon wrote:
First thanks for the patch, Is there an option to test for isatty(fd) for run ioctl instead?.
Hi Anibal,

    if (isatty(0) && ioctl(0, TIOCNOTTY) == -1)

would help for ssh case but not to errors between tests. There fd 0 is a tty but detach should
be done only once. Now it is inside loop. It could work if it was also moved outside the loop,
before PTEST_LIST_ITERATE_START?

Agree, Add isatty(0) and move that validation outside the loop.

Anibal
 

Kind regards,

    - Tero