Skip to content
Snippets Groups Projects
  • Mark A. Grondona's avatar
    013ac790
    env: fix shell function import · 013ac790
    Mark A. Grondona authored
    src/common/env.c:env_array_user_default() tries to import a "default"
    user environment by parsing the output of something like
    
     su - <user> -c "/bin/env" ( or "slurmstepd getenv")
    
    (or an equivalent) when the job is run with --get-user-env. There is some
    code that tries to detect and import exported bash shell functions, which
    usually have the form
    
     func=() { ...
     }
    
    into the job environment. However, one of the many problems with the
    code is that the test for bounds overflow:
    
                  if ((strlen(value) + strlen(line)) >
                      (sizeof(value) - 1))
                         break;
    
    useis sizeof(value) and value is a char *. This means that all multiline
    shell functions are truncated, and the following error appears in
    users batch script output:
    
     /bin/sh: func: line 1: syntax error: unexpected end of file
     /bin/sh: error importing function definition for `func'
    
    This patch fixes the bounds test.
    
    Similar cut-and-paste code in _load_env_cache() was also fixed.
    
    However, it should be noted that there are many other potential cases
    where shell functions will not be properly imported by this code.
    (For example, quoted unbalanced brackets used in the function)
    Someday this should be fixed.
    013ac790
    History
    env: fix shell function import
    Mark A. Grondona authored
    src/common/env.c:env_array_user_default() tries to import a "default"
    user environment by parsing the output of something like
    
     su - <user> -c "/bin/env" ( or "slurmstepd getenv")
    
    (or an equivalent) when the job is run with --get-user-env. There is some
    code that tries to detect and import exported bash shell functions, which
    usually have the form
    
     func=() { ...
     }
    
    into the job environment. However, one of the many problems with the
    code is that the test for bounds overflow:
    
                  if ((strlen(value) + strlen(line)) >
                      (sizeof(value) - 1))
                         break;
    
    useis sizeof(value) and value is a char *. This means that all multiline
    shell functions are truncated, and the following error appears in
    users batch script output:
    
     /bin/sh: func: line 1: syntax error: unexpected end of file
     /bin/sh: error importing function definition for `func'
    
    This patch fixes the bounds test.
    
    Similar cut-and-paste code in _load_env_cache() was also fixed.
    
    However, it should be noted that there are many other potential cases
    where shell functions will not be properly imported by this code.
    (For example, quoted unbalanced brackets used in the function)
    Someday this should be fixed.