Ejemplo n.º 1
0
/* 
 * Called from both srun and slurmd.
 */
int slurm_spank_init (spank_t sp, int ac, char **av)
{
    uint32_t jobid;
    struct passwd *pw;
    uid_t uid;
    char buf [1024];
    int n;

    if (ac!=1) {
        slurm_error ("bindtmp: Error module need argument ' lls_mountpoint_prefix ' ");
        return (-1);
    }
    if (!spank_remote (sp))
        return (0);

    slurm_verbose("bindtmp: av[0] == %s ",av[0] );
    lls_mountpoint_prefix=av[0];

    spank_get_item (sp, S_JOB_UID, &uid);
    pw = getpwuid (uid);
    if (!pw) {
        slurm_error ("bindtmp: Error looking up uid in /etc/passwd");
        return (-1);
    }

    if (unshare (CLONE_NEWNS) < 0) {
        slurm_error ("bindtmp: Error unshare CLONE_NEWNS: %m");
        return (-1);
    }

    if ( spank_get_item (sp, S_JOB_ID, &jobid) != ESPANK_SUCCESS ) {
        slurm_error ("bindtmp: Error unable to get jobid");
        return (-1);
    }
    n = snprintf (buf, sizeof (buf), "%s%u",lls_mountpoint_prefix,  jobid);
    if ((n < 0) || (n > sizeof (buf) - 1)) {
        slurm_error ("bindtmp: Error sprintf ");
        return (-1);
    }
    if (mount(buf, "/tmp", NULL, MS_BIND , NULL)!= 0) {
        slurm_error ("bindtmp: Could not bind %s to /tmp",buf);
        return (-1);
    }

    return (0);
}
Ejemplo n.º 2
0
List lua_script_list_create (lua_State *L, const char *pattern)
{
    glob_t gl;
    size_t i;
    List l = NULL;

    if (pattern == NULL)
        return (NULL);

    int rc = glob (pattern, GLOB_ERR, ef, &gl);
    switch (rc) {
        case 0:
            l = list_create ((ListDelF) lua_script_destroy);
            for (i = 0; i < gl.gl_pathc; i++) {
                struct lua_script * s;
                s = lua_script_create (L, gl.gl_pathv[i]);
                if (s == NULL) {
                    slurm_error ("lua_script_create failed for %s.",
                            gl.gl_pathv[i]);
                    continue;
                }
                list_push (l, s);
            }
            break;
        case GLOB_NOMATCH:
            break;
        case GLOB_NOSPACE:
            slurm_error ("spank/lua: glob(3): Out of memory");
        case GLOB_ABORTED:
            slurm_verbose ("spank/lua: cannot read dir %s: %m", pattern);
            break;
        default:
            slurm_error ("Unknown glob(3) return code = %d", rc);
            break;
    }

    globfree (&gl);

    return l;
}
Ejemplo n.º 3
0
static int l_spank_log_msg (lua_State *L)
{
    int level = luaL_checknumber (L, 1);
    const char *msg;

    msg = l_string_sanitized (L);
    if (!msg)
        return (0);

    if (level == -1) {
        slurm_error (msg);
        lua_pushnumber (L, -1);
        return (1);
    }

    if (level == 0)
        slurm_info (msg);
    else if (level == 1)
        slurm_verbose (msg);
    else if (level == 2)
        slurm_debug (msg);
    return (0);
}
Ejemplo n.º 4
0
int spank_lua_init (spank_t sp, int ac, char *av[])
{
    struct spank_lua_options opt;
    ListIterator i;
    struct lua_script *script;
    int rc = 0;

    if (ac == 0) {
        slurm_error ("spank/lua: Requires at least 1 arg");
        return (-1);
    }
    /*
     *  Check for spank/lua options in argv
     */
    spank_lua_process_args (&ac, &av, &opt);

    /*
     *  dlopen liblua to ensure that symbols from that lib are
     *   available globally (so lua doesn't fail to dlopen its
     *   DSOs
     */
    if (!dlopen ("liblua.so", RTLD_NOW | RTLD_GLOBAL)) {
        slurm_error ("spank/lua: Failed to open liblua.so");
        return (-1);
    }

    global_L = luaL_newstate ();
    luaL_openlibs (global_L);

    /*
     *  Create the global SPANK table
     */
    SPANK_table_create (global_L);

    lua_script_list = lua_script_list_create (global_L, av[0]);
    if (lua_script_list == NULL) {
        slurm_verbose ("spank/lua: No files found in %s", av[0]);
        return (0);
    }

    /*
     *  Set up handler for lua_atpanic() so lua doesn't exit() on us.
     *   This handles errors from outside of protected mode --
     *   for example when this plugin is processing the global
     *   spank_options table. The spank_atpanic() function will
     *   return to the setjmp() point below (thus avoiding Lua's
     *   call to exit() from its own panic handler). This is basically
     *   here so that we can use luaL_error() everwhere without
     *   worrying about the context of the call.
     */
    lua_atpanic (global_L, spank_atpanic);
    if (setjmp (panicbuf)) {
        slurm_error ("spank/lua: PANIC: %s: %s",
                av[0], lua_tostring (global_L, -1));
        return (-1);
    }

    i = list_iterator_create (lua_script_list);
    while ((script = list_next (i))) {
        script->fail_on_error = opt.fail_on_error;

        /*
         *  Load script (luaL_loadfile) and compile it (lua_pcall).
         */
        if (luaL_loadfile (script->L, script->path) ||
            lua_pcall (script->L, 0, 0, 0)) {
            print_lua_script_error (script);
            if (opt.fail_on_error)
                return (-1);
            list_remove(i);
            lua_script_destroy (script);
            continue;
        }

        /*
         *  Don't keep script loaded if the script doesn't have any
         *   callbacks in the current context.
         */
        if (!lua_script_valid_in_context (sp, script)) {
                slurm_debug ("%s: no callbacks in this context",
                             basename (script->path));
                list_remove (i);
                lua_script_destroy (script);
        }
    }
    list_iterator_destroy (i);
    slurm_verbose ("spank/lua: Loaded %d plugins in this context",
                    list_count (lua_script_list));
    return rc;
}