Esempio n. 1
0
/**
 * Find an alternative path to the configuration directory.
 *
 * Attempt to find an alternative configuration directory pathname.  First
 * check for the presence of the AFSCONF environment variable, then check for
 * the contents of the $HOME/.AFSCONF file, then check for the contents of the
 * /.AFSCONF file.
 *
 * The AFSCONF environment, or contents of $HOME/.AFSCONF, or /.AFSCONF will be
 * typically set to something like /afs/<cell>/common/etc where, by convention,
 * the default files for ThisCell and CellServDB will reside. Note that a major
 * drawback is that a given afs client on that cell may NOT contain the same
 * contents.
 *
 * @param[out] aconfdir  pointer to an allocated string if a path was found
 *
 * @return 0 on success
 *
 * @note The returned string in pathp must be freed by the caller.
 */
static int
GetAlternatePath(char **aconfdir)
{
    int code;
    char *confdir = NULL;
    char *afsconf_path = getenv("AFSCONF");

    if (afsconf_path) {
	confdir = strdup(afsconf_path);
	if (!confdir)
	    return ENOMEM;
    }

    if (!confdir) {
	char *home_dir = getenv("HOME");
	if (home_dir) {
	    char *pathname = NULL;
	    int r = asprintf(&pathname, "%s/%s", home_dir, ".AFSCONF");
	    if (r < 0 || !pathname)
		return ENOMEM;
	    code = ReadFirstLine(pathname, &confdir);
	    free(pathname);
	    pathname = NULL;
	    if (code && code != ENOENT)
		return code;
	}
    }

    if (!confdir) {
	code = ReadFirstLine("/.AFSCONF", &confdir);
	if (code && code != ENOENT)
	    return code;
    }

    if (!confdir)
	return ENOENT;

    *aconfdir = confdir;
    return 0;
}
Esempio n. 2
0
/* find a synaptic evdev.
 */
static void
FindSynapticEvent(char** eventdev,const char* searchstring) {
	DIR* dir;
	struct dirent* entry;
	int lenght;

	char path[sizeof *"/sys/class/input/" + sizeof *"/name"+NAME_MAX];
	char *ret=NULL;
	*eventdev=NULL;

	SYSCALLPTR(dir=opendir("/sys/class/input/"));
	strcpy(path,"/sys/class/input/");
	lenght=strlen(path);


	while ((entry=FindFileStartingWith(dir,"input",strlen("input")))) {
		strcpy(&path[lenght],entry->d_name);
		strcat(path,"/name");


		if (ReadFirstLine(path,&ret))
            continue;
        if (strstr(ret,searchstring)) {
            xfree(ret);
            ret = NULL;
            break;
        }
        xfree(ret);
        ret = NULL;
	}
	if (!entry) {
		SYSCALL(closedir(dir));
		return;
	}

	strcpy(&path[lenght],entry->d_name);
	SYSCALL(closedir(dir));

	SYSCALLPTR(dir=opendir(path));
	entry=FindFileStartingWith(dir,"event",strlen("event"));
	if (entry) {
		*eventdev=xcalloc(strlen(entry->d_name)+1,sizeof(char));
		strcpy(*eventdev,entry->d_name);
	}
	SYSCALL(closedir(dir));
}