rakudo / rakudo

🦋 Rakudo – Raku on MoarVM, JVM, and JS
https://rakudo.org/
Artistic License 2.0
1.72k stars 373 forks source link

raku -c does wrong thing when using module from unwritable directory #4389

Open jmaslak opened 3 years ago

jmaslak commented 3 years ago

The Problem

If Raku can't write to a directory with a module located in it, it will execute MAIN when compiling (I.E. with raku -c switch).

This bug is the same bug as https://github.com/Raku/docker/issues/44

mkdir t
echo 'multi MAIN() is export { say "BUG!" }' >t/BugTest.rakumod
chmod 500 t
raku -c -It -MBugTest -e ''

Expected Behavior

Should just say Syntax Ok

Actual Behavior

Prints BUG! in addition to Syntax Ok

Steps to Reproduce

See above.

Environment

Welcome to Rakudo(tm) v2021.04.
Implementing the Raku(tm) programming language v6.d.
Built on MoarVM version 2021.04.
melezhik commented 3 years ago

Not reproduced for me. On either 2021.05 or 4f61a108 4389 versions:

[root@6523d917496c r3tool]# tomty --env=4f61a108 4389
load configuration from /root/projects/r3tool/.tomty/env/config.4f61a108.pl6
[repository] :: index updated from file:///root/repo/api/v1/index
==================================================
[https://github.com/rakudo/rakudo/issues/4389]
==================================================

[4389] :: cat $root_dir/task.bash
[4389] ::
[4389] :: cd $cache_root_dir
[4389] ::
[4389] :: mkdir t
[4389] ::
[4389] :: echo 'multi MAIN() is export { say "BUG!" }' >t/BugTest.rakumod
[4389] ::
[4389] :: chmod 500 t
[4389] ::
[4389] :: stat t
[4389] ::
[4389] :: $RAKUBIN -v
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] :: $RAKUBIN -c -It -MBugTest -e ''
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] ::
[4389] ::   File: t
[4389] ::   Size: 4096          Blocks: 8          IO Block: 4096   directory
[4389] :: Device: 9fh/159d      Inode: 2493572     Links: 2
[4389] :: Access: (0500/dr-x------)  Uid: (    0/    root)   Gid: (    0/    root)
[4389] :: Access: 2021-06-18 17:26:57.400912000 +0000
[4389] :: Modify: 2021-06-18 17:26:57.400912000 +0000
[4389] :: Change: 2021-06-18 17:26:57.402912000 +0000
[4389] ::  Birth: -
[4389] :: Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.05-23-g4f61a108b.
[4389] :: Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
[4389] :: Built on MoarVM version 2021.05-14-g0a62f0c6a.
[4389] :: ===========================
[4389] :: Syntax OK
[4389] :: ===========================
[root@6523d917496c r3tool]# nano 4389/task.bash
[root@6523d917496c r3tool]# tomty --env=default 4389
load configuration from /root/projects/r3tool/.tomty/env/config.pl6
[repository] :: index updated from file:///root/repo/api/v1/index
==================================================
[https://github.com/rakudo/rakudo/issues/4389]
==================================================

[4389] :: cat $root_dir/task.bash
[4389] ::
[4389] :: cd $cache_root_dir
[4389] ::
[4389] :: mkdir t
[4389] ::
[4389] :: echo 'multi MAIN() is export { say "BUG!" }' >t/BugTest.rakumod
[4389] ::
[4389] :: chmod 500 t
[4389] ::
[4389] :: stat t
[4389] ::
[4389] :: $RAKUBIN -v
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] :: $RAKUBIN -c -It -MBugTest -e ''
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] ::
[4389] ::   File: t
[4389] ::   Size: 4096          Blocks: 8          IO Block: 4096   directory
[4389] :: Device: 9fh/159d      Inode: 2493572     Links: 2
[4389] :: Access: (0500/dr-x------)  Uid: (    0/    root)   Gid: (    0/    root)
[4389] :: Access: 2021-06-18 17:27:31.926230000 +0000
[4389] :: Modify: 2021-06-18 17:27:31.926230000 +0000
[4389] :: Change: 2021-06-18 17:27:31.927230000 +0000
[4389] ::  Birth: -
[4389] :: Welcome to Rakudo(tm) v2021.05.
[4389] :: Implementing the Raku(tm) programming language v6.d.
[4389] :: Built on MoarVM version 2021.05.
[4389] :: ===========================
[4389] :: Syntax OK
[4389] :: ===========================
melezhik commented 3 years ago

I run it by root btw 🤔

melezhik commented 3 years ago

not reproduced on 2021.04 as well

[root@6523d917496c r3tool]# tomty  --env=2021_04  4389
load configuration from /root/projects/r3tool/.tomty/env/config.2021_04.pl6
[repository] :: index updated from file:///root/repo/api/v1/index
==================================================
[https://github.com/rakudo/rakudo/issues/4389]
==================================================

[4389] :: cat $root_dir/task.bash
[4389] ::
[4389] :: cd $cache_root_dir
[4389] ::
[4389] :: mkdir t
[4389] ::
[4389] :: echo 'multi MAIN() is export { say "BUG!" }' >t/BugTest.rakumod
[4389] ::
[4389] :: chmod 500 t
[4389] ::
[4389] :: stat t
[4389] ::
[4389] :: $RAKUBIN -v
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] :: $RAKUBIN -c -It -MBugTest -e ''
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] ::
[4389] ::   File: t
[4389] ::   Size: 4096          Blocks: 8          IO Block: 4096   directory
[4389] :: Device: 9fh/159d      Inode: 2493573     Links: 2
[4389] :: Access: (0500/dr-x------)  Uid: (    0/    root)   Gid: (    0/    root)
[4389] :: Access: 2021-06-18 17:39:46.361736000 +0000
[4389] :: Modify: 2021-06-18 17:39:46.361736000 +0000
[4389] :: Change: 2021-06-18 17:39:46.363736000 +0000
[4389] ::  Birth: -
[4389] :: Welcome to Rakudo(tm) v2021.04.
[4389] :: Implementing the Raku(tm) programming language v6.d.
[4389] :: Built on MoarVM version 2021.04.
[4389] :: ===========================
[4389] :: Syntax OK
[4389] :: ===========================
jmaslak commented 3 years ago

Ya, you need to run it as a normal user, not root, to see the bug. I couldn't reproduce the bug as root.

melezhik commented 3 years ago

I see. Reproduced for ca8dea277aa93be11b34a4b3847d5501f05cb067

[r3@6523d917496c r3tool]$ tomty --color  4389
[repository] :: index updated from file:///home/r3/repo/api/v1/index
==================================================
[https://github.com/rakudo/rakudo/issues/4389]
==================================================

[4389] :: cat $root_dir/task.bash
[4389] ::
[4389] :: cd $cache_root_dir
[4389] ::
[4389] :: mkdir t
[4389] ::
[4389] :: echo 'multi MAIN() is export { say "BUG!" }' >t/BugTest.rakumod
[4389] ::
[4389] :: chmod 500 t
[4389] ::
[4389] :: stat t
[4389] ::
[4389] :: $RAKUBIN -v
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] :: $RAKUBIN -c -It -MBugTest -e ''
[4389] ::
[4389] :: echo ===========================
[4389] ::
[4389] ::
[4389] ::   File: t
[4389] ::   Size: 4096          Blocks: 8          IO Block: 4096   directory
[4389] :: Device: 9fh/159d      Inode: 3411145     Links: 2
[4389] :: Access: (0500/dr-x------)  Uid: ( 1000/      r3)   Gid: ( 1000/      r3)
[4389] :: Access: 2021-06-18 22:25:20.879450000 +0000
[4389] :: Modify: 2021-06-18 22:25:20.879450000 +0000
[4389] :: Change: 2021-06-18 22:25:20.880450000 +0000
[4389] ::  Birth: -
[4389] :: Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2021.05-37-gca8dea277.
[4389] :: Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
[4389] :: Built on MoarVM version 2021.05-16-gb015e1a46.
[4389] :: ===========================
[4389] :: BUG!
[4389] :: Syntax OK
[4389] :: ===========================
[task check] stdout match (r) <(\S+)> True
[task check] <no BUG! in output> False
=================
TASK CHECK FAIL
coke commented 1 year ago

Still in 2022.07