Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ runtime/dgsh-tee
.vscode/*
.idea/*
.vs/*
venv/
36 changes: 36 additions & 0 deletions compiler/pash.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
def main():
## Parse arguments
args, shell_name = parse_args()

check_locale_settings()

## If it is interactive we need a different execution mode
##
## The user can also ask for an interactive mode irregardless of whether pash was invoked in interactive mode.
Expand Down Expand Up @@ -164,5 +167,38 @@ def execute_script(compiled_script_filename, command, arguments, shell_name):
return exec_obj.returncode



def check_locale_settings():
"""
Checks if locale settings are set correctly to avoid execution inconsistencies.
"""

locale_vars = {
"LC_ALL": os.environ.get("LC_ALL", "Not Set"),
"LANG": os.environ.get("LANG", "Not Set"),
"LC_CTYPE": os.environ.get("LC_CTYPE", "Not Set"),
"LC_COLLATE": os.environ.get("LC_COLLATE", "Not Set"),
"LC_NUMERIC": os.environ.get("LC_NUMERIC", "Not Set"),
}

# If LC_ALL is set, it overrides all locale settings
if locale_vars["LC_ALL"] not in ["Not Set", "C", "C.UTF-8"]:
log(f"WARNING: LC_ALL is set to '{locale_vars['LC_ALL']}', which overrides all other locale settings.")
log(f"Consider setting LC_ALL=C for full consistency.")
return # No need to check others if LC_ALL is set

# Warn if LC_COLLATE is neither C nor C.UTF-8
if locale_vars["LC_COLLATE"] not in ["C", "C.UTF-8"]:
log(f"WARNING: LC_COLLATE is set to '{locale_vars['LC_COLLATE']}'. This may affect sorting behavior.")
log(f"Consider setting LC_COLLATE=C for strict ASCII ordering.")

# Warn if LC_NUMERIC is neither C nor C.UTF-8
if locale_vars["LC_NUMERIC"] not in ["C", "C.UTF-8"]:
log(f"WARNING: LC_NUMERIC is set to '{locale_vars['LC_NUMERIC']}'. This may affect numerical operations.")
log(f"Consider setting LC_NUMERIC=C for consistent behavior.")

log("Locale settings checked. To avoid performance inconsistencies, use `LC_ALL=C.UTF-8`.")
pid = os.getpid()

if __name__ == "__main__":
main()
36 changes: 33 additions & 3 deletions compiler/pash_compilation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ def parse_args():


# Initialize the daemon

initial_env_vars = {}

def store_initial_env():
"""Stores initial locale environment variables at startup."""
global initial_env_vars
initial_env_vars = {
"LC_ALL": os.environ.get("LC_ALL", "Not Set"),
"LANG": os.environ.get("LANG", "Not Set"),
"LC_CTYPE": os.environ.get("LC_CTYPE", "Not Set"),
"LC_COLLATE": os.environ.get("LC_COLLATE", "Not Set"),
"LC_NUMERIC": os.environ.get("LC_NUMERIC", "Not Set")
}
log(f"Initial locale settings: {initial_env_vars}")

def init():
## Set the logging prefix
Expand All @@ -53,7 +65,7 @@ def init():
config.load_config(args.config_path)

pash_compiler.runtime_config = config.config["distr_planner"]

store_initial_env()
return args


Expand Down Expand Up @@ -511,13 +523,31 @@ def run(self):
self.connection_manager.close()
shutdown()

def check_final_env():
"""Checks if locale environment variables changed during execution."""
final_env_vars = {
"LC_ALL": os.environ.get("LC_ALL", "Not Set"),
"LANG": os.environ.get("LANG", "Not Set"),
"LC_CTYPE": os.environ.get("LC_CTYPE", "Not Set"),
"LC_COLLATE": os.environ.get("LC_COLLATE", "Not Set"),
"LC_NUMERIC": os.environ.get("LC_NUMERIC", "Not Set")
}

if final_env_vars != initial_env_vars:
log("WARNING: Locale environment variables changed during execution!")
log(f"Initial: {initial_env_vars}")
log(f"Final: {final_env_vars}")


def shutdown():
## There may be races since this is called through the signal handling
"""Shuts down the PaSh daemon."""
check_final_env()
log("PaSh daemon is shutting down...")
log("PaSh daemon shut down successfully...")




def main():
args = init()
if args.distributed_exec:
Expand Down
1 change: 0 additions & 1 deletion compiler/pash_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pickle
import traceback
from datetime import datetime

from sh_expand import env_vars_util
from sh_expand.expand import ExpansionError

Expand Down
Loading
Loading