/** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Set of functions to gather system information for the jack setup wizard. * * TODO: Test for rt prio availability * * @author Florian Faber, faber@faberman.de * **/ /** 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 "systemtest.h" /** * 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; } /** * Tests wether the owner of this process is in the group 'name'. * * @returns 0 if the owner of this process is not in the group, non-0 otherwise **/ int system_user_in_group(const char *name) { 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(name); if (0==gid) { fprintf(stderr, "No %s group found\n", name); free(list); return 0; } num_groups = getgroups(MAX_GROUPS, list); while (i("/proc/meminfo"), buf, sizeof (buf))) { if (strncmp (buf, "MemTotal:", 9) == 0) { if (sscanf (buf, "%*s %llu", &res) != 1) { perror ("parse error in /proc/meminfo"); } } } else { perror("read from /proc/meminfo"); } return res*1024; } /** * Gets the version of the currently running kernel. The string * returned has to be freed by the caller. * * @returns String with the full version of the kernel **/ char* system_kernel_version() { return NULL; } char* system_get_username() { char* res = NULL; char* name = NULL; if ((name = getlogin())) { res = strdup(name); } return res; }