Topics

[ptest-runner][PATCH v2] 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

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.

Signed-off-by: Tero Kinnunen <tero.kinnunen@...>
---
utils.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utils.c b/utils.c
index a8ba190..a4e190e 100644
--- a/utils.c
+++ b/utils.c
@@ -437,6 +437,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
break;
}
fprintf(fp, "START: %s\n", progname);
+ if (isatty(0) && ioctl(0, TIOCNOTTY) == -1) {
+ fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
+ }
PTEST_LIST_ITERATE_START(head, p)
char *ptest_dir = strdup(p->run_ptest);
if (ptest_dir == NULL) {
@@ -444,9 +447,6 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
break;
}
dirname(ptest_dir);
- if (ioctl(0, TIOCNOTTY) == -1) {
- fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
- }

if ((pgid = getpgid(0)) == -1) {
fprintf(fp, "ERROR: getpgid() failed, %s\n", strerror(errno));
--
2.25.1

Anibal Limon
 

Applied, Thanks!.

Anibal

On Fri, 10 Jul 2020 at 00:44, 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

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.

Signed-off-by: Tero Kinnunen <tero.kinnunen@...>
---
 utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utils.c b/utils.c
index a8ba190..a4e190e 100644
--- a/utils.c
+++ b/utils.c
@@ -437,6 +437,9 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
                        break;
                }
                fprintf(fp, "START: %s\n", progname);
+               if (isatty(0) && ioctl(0, TIOCNOTTY) == -1) {
+                       fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
+               }
                PTEST_LIST_ITERATE_START(head, p)
                        char *ptest_dir = strdup(p->run_ptest);
                        if (ptest_dir == NULL) {
@@ -444,9 +447,6 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
                                break;
                        }
                        dirname(ptest_dir);
-                       if (ioctl(0, TIOCNOTTY) == -1) {
-                               fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
-                       }

                        if ((pgid = getpgid(0)) == -1) {
                                fprintf(fp, "ERROR: getpgid() failed, %s\n", strerror(errno));
--
2.25.1