/** * GPL, yabbadabba * * Set of functions to gather system information for the jack setup wizard. * * TODO: Test for rt prio availability * * @author Florian Faber, faber@faberman.de * * @version 0.1 (2009-01-15) [FF] * - initial version * **/ /** maximum number of groups a user can be a member of **/ #define MAX_GROUPS 100 #include #include #include #include #include #include #include #include #include #include #include #include /** * This function checks for the existence of known frequency scaling mechanisms * in this system by testing for the availability of scaling governors/ * * @returns 0 if the system has no frequency scaling capabilities non-0 otherwise. **/ int system_has_frequencyscaling() { int fd; fd = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors", O_RDONLY); if (-1==fd) { return 0; } (void) close(fd); return 1; } static int read_string(char* filename, char* buf, size_t buflen) { int fd; ssize_t r=-1; memset(buf, 0, buflen); fd = open(filename, O_RDONLY); if (-1 scaling return 1; } } } } } else { // couldn't open file -> no more cores done = 1; } cpu++; } // couldn't find anything that points to scaling return 0; } static gid_t get_group_by_name(const char* name) { struct group* grp; gid_t res = 0; while ((0==res) && (NULL != (grp = getgrent()))) { if (0==strcmp(name, grp->gr_name)) { res = grp->gr_gid; } } endgrent(); return res; } /*** * Checks for a definition in /etc/security/limits.conf that looks * as if it allows RT scheduling priority. * * @returns 1 if there appears to be such a line **/ int system_has_rtprio_limits_conf () { const char* limits = "/etc/security/limits.conf"; char cmd[100]; snprintf (cmd, sizeof (cmd), "grep -q 'rtprio *[0-9][0-9]*' %s", limits); if (system (cmd) == 0) { return 1; } return 0; } /** * Checks for the existence of the 'audio' group on this system * * @returns 0 is there is no 'audio' group, the group id otherwise **/ int system_has_audiogroup() { return get_group_by_name("audio") || get_group_by_name ("jackuser"); } /** * Tests wether the owner of this process is in the 'audio' group. * * @returns 0 if the owner of this process is not in the audio group, non-0 otherwise **/ int system_user_in_audiogroup() { gid_t* list = (gid_t*) malloc(MAX_GROUPS * sizeof(gid_t)); int num_groups, i=0, found=0; unsigned int gid; if (NULL==list) { perror("Cannot allocate group list structure"); exit(EXIT_FAILURE); } gid = get_group_by_name("audio"); if (0==gid) { fprintf(stderr, "No audio group found\n"); exit(EXIT_FAILURE); } num_groups = getgroups(MAX_GROUPS, list); while (i