]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/9pfs: Return ENOTSUP on ioctl requests
authorStefan Jumarea <stefanjumarea02@gmail.com>
Fri, 15 Sep 2023 20:02:51 +0000 (23:02 +0300)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:32:28 +0000 (19:32 +0300)
Currently `9pfs` returns 0 for any `ioctl` request (except for
`TIOCGWINSZ`), which leads to multiple cases of files being interpreted
as terminals. You can see this problem when running python scripts,
since python uses `ioctl` calls to check if it should open up the
interactive interpretor or execute a script.

Same thing could happen for other applications that rely on `ioctl`
operations being properly executed, so the best way to go would be
return `ENOTSUP` (as is used to happen before commit 28d0edf).

If the `ioctl` call always return `ENOTSUP`, the Ruby binary
compatibility application will fail, since it tries to set O_ASYNC and
breaks on error, even if it does not directly depends on that, so for
now add a special case for that.

Signed-off-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1098

lib/9pfs/9pfs_vnops.c

index c6d98d941705ae6d06aece10904e5ba7545e8f02..127c3206c7e34b3dba3bdb4fbc837e5d28ba0d96 100644 (file)
@@ -1016,10 +1016,23 @@ static int uk_9pfs_ioctl(struct vnode *dvp, struct vfscore_file *fp,
                         unsigned long com, void *data)
 {
        switch (com) {
-       case TIOCGWINSZ:
-               return ENOTTY;
-       default:
+       /**
+        * HACK: In binary compatibility mode, Ruby tries to set O_ASYNC,
+        * which Unikraft does not yet support. If the `ioctl` call returns
+        * an error, Ruby stops working, even if it does not depend on the
+        * O_ASYNC being properly set.
+        *
+        * Until proper support, just return 0 in case an `FIONBIO` ioctl
+        * request is done, and ENOTSUP for all other cases.
+        *
+        * Setting `ioctl` to a nullop will not work, since it is used by
+        * interpreted languages (e.g. python3) to check if it should start
+        * the interpretor or just read a file.
+        */
+       case FIONBIO:
                return 0;
+       default:
+               return ENOTSUP;
        }
 }