Skip to content

SOCK_SEQPACKET UNIX Socket Fallback and Direct Shebang Execution#111

Open
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:feature/SOCK_SEQPACKET
Open

SOCK_SEQPACKET UNIX Socket Fallback and Direct Shebang Execution#111
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:feature/SOCK_SEQPACKET

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator
SOCK_SEQPACKET UNIX Socket Fallback

Updated sys_socket and sys_socketpair
to automatically downgrade AF_UNIX
sockets of type SOCK_SEQPACKET to
SOCK_STREAM on macOS hosts.
Initialized the socket options
cache using the original
LINUX_SOCK_SEQPACKET type,
ensuring getsockopt queries for
SO_TYPE correctly report
SOCK_SEQPACKET to the guest.

Direct Shebang Execution

Implemented a recursive shebang parsing loop
in the standalone loader's entry point.
It reads shebang interpreter lines
(including optional arguments like #!/bin/sh -x),
updates elf_path to point to the interpreter,
prepends them to guest_argv, and resolves the
host path recursively up to a depth of 5 levels.

Summary by cubic

Adds macOS-safe AF_UNIX SOCK_SEQPACKET by creating SOCK_STREAM sockets on the host while still reporting SOCK_SEQPACKET to the guest. Also adds direct shebang execution with recursive interpreter resolution (max 5) and a daily upstream sync workflow.

  • New Features
    • AF_UNIX SOCK_SEQPACKET fallback on macOS: downgrade to SOCK_STREAM in sys_socket and sys_socketpair, but initialize the socket option cache with the original type so getsockopt(SO_TYPE) returns SOCK_SEQPACKET (compatible with the Rosetta shim path).
    • Standalone loader: parse shebang (#!, supports one optional arg), prepend interpreter to argv, update elf_path, resolve recursively up to 5 levels, clean up temp files between steps, and fail cleanly on overflow.
    • CI: add a workflow to sync the fork with upstream daily.

Written for commit c8288ed. Summary will update on new commits.

Review in cubic

@doanbaotrung doanbaotrung force-pushed the feature/SOCK_SEQPACKET branch from 66ce56b to c1e7082 Compare June 25, 2026 15:15
@doanbaotrung

Copy link
Copy Markdown
Collaborator Author

Fix #104

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/main.c">

<violation number="1" location="src/main.c:565">
P2: Shebang recursion limit is off by one: exactly max depth always fails. Allow max depth and fail only when an additional shebang is encountered.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/main.c
Comment thread src/main.c
}
}

if (shebang_depth >= max_shebang_depth) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Shebang recursion limit is off by one: exactly max depth always fails. Allow max depth and fail only when an additional shebang is encountered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main.c, line 565:

<comment>Shebang recursion limit is off by one: exactly max depth always fails. Allow max depth and fail only when an additional shebang is encountered.</comment>

<file context>
@@ -440,16 +440,134 @@ int main(int argc, char **argv)
+        }
+    }
+
+    if (shebang_depth >= max_shebang_depth) {
+        log_error("too many levels of shebang recursion (max %d) resolving %s",
+                  max_shebang_depth, argv[arg_start]);
</file context>

Comment thread src/main.c
Updated sys_socket and sys_socketpair
to automatically downgrade AF_UNIX
sockets of type SOCK_SEQPACKET to
SOCK_STREAM on macOS hosts.
Initialized the socket options
cache using the original
LINUX_SOCK_SEQPACKET type,
ensuring getsockopt queries for
SO_TYPE correctly report
SOCK_SEQPACKET to the guest.

Direct Shebang Execution

Implemented a recursive shebang parsing loop
in the standalone loader's entry point.
It reads shebang interpreter lines
(including optional arguments like #!/bin/sh -x),
updates elf_path to point to the interpreter,
prepends them to guest_argv, and resolves the
host path recursively up to a depth of 5 levels.
@doanbaotrung doanbaotrung force-pushed the feature/SOCK_SEQPACKET branch from 99a45a3 to c8288ed Compare June 25, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant