Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix-spawn/run fail to run, no output on CentOS 7 #4

Closed
jminh opened this issue Oct 25, 2023 · 2 comments · Fixed by #5
Closed

posix-spawn/run fail to run, no output on CentOS 7 #4

jminh opened this issue Oct 25, 2023 · 2 comments · Fixed by #5

Comments

@jminh
Copy link
Contributor

jminh commented Oct 25, 2023

On CentOS 7, below simple program is failing to run. There is no output on
CentOS 7.

$ cat hello.janet
#!/usr/bin/env janet
(import posix-spawn)

(posix-spawn/run ["ls"])

$ ./hello.janet
$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-ia32:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-ia32:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-ia32:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:        7.3.1611
Codename:       Core

From strace we can see there is no relevant system call like clone, fork or
vfork.

$ strace -ff -eprocess -o x ./hello.janet

$ cat x.147015
execve("./hello.janet", ["../hello.janet"], [/* 94 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ffff7f9f740) = 0
execve("/path/to/janet", ["janet", "./hello.janet"], [/* 94 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ffff7f9e140) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ffff7f9e410) = 147016
wait4(147016, [{WIFEXITED(s) && WEXITSTATUS(s) == 127}], 0, NULL) = 147016
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=147016, si_status=127, si_utime=0, si_stime=0} ---
exit_group(0)                           = ?
+++ exited with 0 +++

$ cat x.147016
exit_group(127)                         = ?
+++ exited with 127 +++
@jminh
Copy link
Contributor Author

jminh commented Oct 27, 2023

I've tried gdb to check what's going on but didn't find useful information.
While reading the posix_spawn document
(https://man7.org/linux/man-pages/man3/posix_spawn.3.html) , in the "Program
source" I noticed POSIX_SPAWN_SETSIGMASK as follows:

  s = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK);

Based on the descriptoin we should use this flag when we want to set sigmask.

With that, I have a patch as shown below to correctly run ls command. strace
also show there is a clone system call.

--- a/posix-spawn.c
+++ b/posix-spawn.c
@@ -371,6 +371,10 @@ static Janet primitive_pspawn(int32_t argc, Janet *argv) {
     SIGSETARG(sig_mask_set, 7);
 #undef SIGSETARG

+    if (posix_spawnattr_setflags(pattr, POSIX_SPAWN_SETSIGMASK) != 0) {
+        PSPAWN_ERROR("unable to setflags");
+    }
+
     if (posix_spawnattr_setsigdefault(pattr, &sig_dflt_set) != 0) {
         PSPAWN_ERROR("unable to sig default");
     }
$ strace -ff -eprocess -o x ./run.janet

$ cat x.143501
execve("./hello.janet", ["./hello.janet"], [/* 94 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ffff7f9f740) = 0
execve("/path/to/janet", ["janet", "./hello.janet"], [/* 94 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ffff7f9e140) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ffff7f9e410) = 143503
wait4(143503, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 143503
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=143503, si_status=0, si_utime=0, si_stime=0} ---
exit_group(0)                           = ?
+++ exited with 0 +++

$ grep '= 0' x.143503
execve("/usr/local/bin/ls", ["ls"], [/* 94 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ffff7f9c840) = 0

@jminh
Copy link
Contributor Author

jminh commented Nov 8, 2023

The proposal fix also resolves the issue
andrewchambers/janet-sh#20 .

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 a pull request may close this issue.

1 participant