src/mn-slaved/hook.c
int
nol_s_hook_assign(const char *hook_nm,
                const char *code,
                size_t code_len)
{
    int  x;
    int  valid = 0;
    FILE *fp;

    for (x=0; x<NUM_HOOKS; x++) {
        if (strcmp(hook_str[x], hook_nm) == 0) {
            valid = 1;
            break;
        }
    }
    if (!valid) {
        syslog(LOG_ERR, "unknown hook type '%s'\n", hook_nm);
        return -1;
    }
    /* we should have chdir'ed to exec_dir already */
    if (!(fp = fopen(hook_nm, "wb"))) {
        syslog(LOG_ERR, "failed to open hook file '%s': %s", 
                hook_nm,
                strerror(errno));
        return -1;
    }

    fwrite(code, 1, code_len, fp);
    fclose(fp);
    chmod(hook_nm, S_IXUSR | S_IWUSR | S_IRUSR);

    hook_list[x] = 1;

    syslog(LOG_INFO, "registered hook '%s'\n", hook_nm);
    return 0;
}
/* save a script as a hook */
save a script as a hook
save a script as a hook
int
nol_s_hook_assign(const char *hook_nm,
                const char *code,
                size_t code_len)
{
    int  x;
    int  valid = 0;
    FILE *fp;
    for (x=0; x<NUM_HOOKS; x++) {
        if (strcmp(hook_str[x], hook_nm) == 0) {
            valid = 1;
            break;
        }
    }
    if (!valid) {
        syslog(LOG_ERR, "unknown hook type '%s'\n", hook_nm);
        return -1;
    }
    if (!(fp = fopen(hook_nm, "wb"))) {
        syslog(LOG_ERR, "failed to open hook file '%s': %s", 
                hook_nm,
                strerror(errno));
        return -1;
    }
    fwrite(code, 1, code_len, fp);
    fclose(fp);
    chmod(hook_nm, S_IXUSR | S_IWUSR | S_IRUSR);
    hook_list[x] = 1;
    syslog(LOG_INFO, "registered hook '%s'\n", hook_nm);
    return 0;
}
int nol_s_hook_assign ( const char * hook_nm , const char * code , size_t code_len ) { int x ; int valid = 0 ; FILE * fp ; for ( x = 0 ; x < NUM_HOOKS ; x ++ ) { if ( strcmp ( hook_str [ x ] , hook_nm ) == 0 ) { valid = 1 ; break ; } } if ( ! valid ) { syslog ( LOG_ERR , " \n " , hook_nm ) ; return -1 ; } if ( ! ( fp = fopen ( hook_nm , " " ) ) ) { syslog ( LOG_ERR , " " , hook_nm , strerror ( errno ) ) ; return -1 ; } fwrite ( code , 1 , code_len , fp ) ; fclose ( fp ) ; chmod ( hook_nm , S_IXUSR | S_IWUSR | S_IRUSR ) ; hook_list [ x ] = 1 ; syslog ( LOG_INFO , " \n " , hook_nm ) ; return 0 ; }
save a script as a hook
save a script as a hook
/* we should have chdir'ed to exec_dir already */