Ejemplo n.º 1
0
int module_path(char *result, const char *basename)
{
    /* Find a kernel module's path */
    struct stat sb;
    char buf[PATH_MAX];
    char rtlib_result[PATH_MAX];
    int has_rtdir;
    struct utsname uts;
	
    // Initialize kmodule_dir, only once
    if (kmodule_dir[0] == 0) {
	uname(&uts);

	get_rtapi_config(buf,"RUN_IN_PLACE",4);
	if (strncmp(buf,"yes",3) == 0) {
	    // Complete RTLIB_DIR should be <RTLIB_DIR>/<flavor>/<uname -r>
	    if (get_rtapi_config(buf,"RTLIB_DIR",PATH_MAX) != 0)
		return -ENOENT;

	    if (strcmp(default_flavor()->build_sys,"user-dso") == 0) {
		// point user threads to a common directory
		snprintf(kmodule_dir,PATH_MAX,"%s/userland/%s",
			 buf, uts.release);
	    } else {
		// kthreads each have their own directory
		snprintf(kmodule_dir,PATH_MAX,"%s/%s/%s",
			 buf, default_flavor()->name, uts.release);
	    }
	} else {
	    // Complete RTLIB_DIR should be /lib/modules/<uname -r>/linuxcnc
	    snprintf(kmodule_dir, PATH_MAX,
		     "/lib/modules/%s/linuxcnc", uts.release);
	}
    }

    // Look for module in kmodule_dir/RTLIB_DIR
    snprintf(result, PATH_MAX, "%s/%s.ko", kmodule_dir, basename);
    if ((stat(result, &sb) == 0)  && (S_ISREG(sb.st_mode)))
	return 0;

    // Not found; save result for possible later diagnostic msg
    strcpy(rtlib_result,result);

    // Check RTDIR as well (RTAI)
    has_rtdir = (get_rtapi_config(buf, "RTDIR", PATH_MAX) == 0 && buf[0] != 0);
    if (has_rtdir) {
	snprintf(result, PATH_MAX, "%s/%s.ko", buf, basename);
	if ((stat(result, &sb) == 0)  && (S_ISREG(sb.st_mode)))
	    return 0;
    }

    // Module not found
    fprintf(stderr, "module '%s.ko' not found in directory\n\t%s\n",
	    basename, kmodule_dir);
    if (has_rtdir)
	fprintf(stderr, "\tor directory %s\n", buf);

    return -ENOENT;
}
Ejemplo n.º 2
0
int run_module_helper(const char *format, ...)
{
    char mod_helper[PATH_MAX+100];

    if (get_rtapi_config(mod_helper, "linuxcnc_module_helper", PATH_MAX) != 0) {
        fprintf(stderr, "load_module: ERROR: failed to read "
		"linuxcnc_module_helper path from rtapi config\n");
	return -1;
    }
    strcat(mod_helper, " ");

    int n = strlen(mod_helper);
    va_list args;
    int retval;

    va_start(args, format);
    retval = vsnprintf(&mod_helper[n], sizeof(mod_helper) - n, format, args);
    va_end(args);

    if (retval < 0 ) {
	fprintf(stderr, "run_module_helper: invalid arguments\n");
	return retval;
    }
    return system(mod_helper);
}
Ejemplo n.º 3
0
static char *loadrt_generator(const char *text, int state) {
    static int len;
    static DIR *d;
    struct dirent *ent;
    char rtlibdir[PATH_MAX];

    if (get_rtapi_config(rtlibdir,"RTLIB_DIR",PATH_MAX) != 0)
    return NULL;

    strcat(rtlibdir,"/");
    strcat(rtlibdir, current_flavor->name);
    strcat(rtlibdir,"/");

    if(!state) {
        len = strlen(text);
        d = opendir(rtlibdir);
    }

    while(d && (ent = readdir(d))) {
        char *result;
        if(!strstr(ent->d_name, default_flavor()->mod_ext)) continue;
        if(startswith(ent->d_name, "rtapi.")) continue;
        if(startswith(ent->d_name, "hal_lib.")) continue;
        if(strncmp(text, ent->d_name, len) != 0) continue;
        result = strdup(ent->d_name);
        result[strlen(result) - \
           strlen(default_flavor()->mod_ext)] = 0;
        return result;
    }
    if (d != NULL) {
        closedir(d);
    }
    return NULL;
}
Ejemplo n.º 4
0
int rtapi_get_tags(const char *mod_name)
{
    char modpath[PATH_MAX];
    int result = 0, n = 0;
    char *cp1 = "";

    flavor_ptr flavor = default_flavor();

    if (kernel_threads(flavor)) {
	if (module_path(modpath, mod_name) < 0) {
	    perror("module_path");
	    return -1;
	}
    } else {
	if (get_rtapi_config(modpath,"RTLIB_DIR",PATH_MAX) != 0) {
	    perror("cant get  RTLIB_DIR ?\n");
	    return -1;
	}
	strcat(modpath,"/");
	strcat(modpath, flavor->name);
	strcat(modpath,"/");
	strcat(modpath,mod_name);
	strcat(modpath, flavor->mod_ext);
    }
    const char **caps = get_caps(modpath);

    char **p = (char **)caps;
    while (p && *p && strlen(*p)) {
	cp1 = *p++;
	if (strncmp(cp1,"HAL=", 4) == 0) {
	    n = strtol(&cp1[4], NULL, 10);
	    result |=  n ;
	}
    }
    free(caps);
    return result;
}
Ejemplo n.º 5
0
static char *loadusr_generator(const char *text, int state) {
    static int len;
    static DIR *d;
    struct dirent *ent;
    static int doing_table;
    char bindir[PATH_MAX];

    if (get_rtapi_config(bindir,"BIN_DIR",PATH_MAX) != 0)
    return NULL;

    if(!state) {
    if(argno == 1) doing_table = 1;
        string_table = loadusr_table;
        len = strlen(text);
        d = opendir(bindir);
    }

    if(doing_table) {
        char *result = table_generator(text, state);
        if(result) return result;
        doing_table = 0;
    }

    while(d && (ent = readdir(d))) {
        char *result;
        if(!startswith(ent->d_name, "hal")) continue;
        if(startswith(ent->d_name, "halcmd")) continue;
        if(strncmp(text, ent->d_name, len) != 0) continue;
        result = strdup(ent->d_name);
        return result;
    }
    if (d != NULL) {
        closedir(d);
    }
    return NULL;
}