@@ -602,16 +602,30 @@ def executeBuiltinUlimit(cmd, shenv):
602602 """executeBuiltinUlimit - Change the current limits."""
603603 if os .name != "posix" :
604604 raise InternalShellError (cmd , "'ulimit' not supported on this system" )
605+ # Import resource here after we confirm we are on a POSIX system as the
606+ # module does not exist on Windows.
607+ import resource
605608 if len (cmd .args ) != 3 :
606609 raise InternalShellError (cmd , "'ulimit' requires two arguments" )
607610 try :
608- new_limit = int (cmd .args [2 ])
611+ if cmd .args [2 ] == "unlimited" :
612+ new_limit = resource .RLIM_INFINITY
613+ else :
614+ new_limit = int (cmd .args [2 ])
609615 except ValueError as err :
610616 raise InternalShellError (cmd , "Error: 'ulimit': %s" % str (err ))
611617 if cmd .args [1 ] == "-v" :
612- shenv .ulimit ["RLIMIT_AS" ] = new_limit * 1024
618+ if new_limit != resource .RLIM_INFINITY :
619+ new_limit = new_limit * 1024
620+ shenv .ulimit ["RLIMIT_AS" ] = new_limit
613621 elif cmd .args [1 ] == "-n" :
614622 shenv .ulimit ["RLIMIT_NOFILE" ] = new_limit
623+ elif cmd .args [1 ] == "-s" :
624+ if new_limit != resource .RLIM_INFINITY :
625+ new_limit = new_limit * 1024
626+ shenv .ulimit ["RLIMIT_STACK" ] = new_limit
627+ elif cmd .args [1 ] == "-f" :
628+ shenv .ulimit ["RLIMIT_FSIZE" ] = new_limit
615629 else :
616630 raise InternalShellError (
617631 cmd , "'ulimit' does not support option: %s" % cmd .args [1 ]
@@ -811,6 +825,10 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
811825 not_args = []
812826 not_count = 0
813827 not_crash = False
828+
829+ # Expand all late substitutions.
830+ args = _expandLateSubstitutions (j , args , cmd_shenv .cwd )
831+
814832 while True :
815833 if args [0 ] == "env" :
816834 # Create a copy of the global environment and modify it for
@@ -860,9 +878,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
860878 # Ensure args[0] is hashable.
861879 args [0 ] = expand_glob (args [0 ], cmd_shenv .cwd )[0 ]
862880
863- # Expand all late substitutions.
864- args = _expandLateSubstitutions (j , args , cmd_shenv .cwd )
865-
866881 inproc_builtin = inproc_builtins .get (args [0 ], None )
867882 if inproc_builtin and (args [0 ] != "echo" or len (cmd .commands ) == 1 ):
868883 # env calling an in-process builtin is useless, so we take the safe
0 commit comments