Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ EXTRA_DIST = scripts/systemd/bumblebeed.service.in \
src/bbsocketclient.h \
src/bbsocket.h \
src/driver.h \
src/findpathwild.h \
src/module.h \
src/pci.h \
src/switch/switching.h
Expand All @@ -59,12 +60,12 @@ sbin_PROGRAMS = bin/bumblebeed
bin_PROGRAMS = bin/optirun

bin_optirun_SOURCES = src/module.c src/bbconfig.c src/bblogger.c src/bbrun.c \
src/bbsocket.c src/optirun.c src/bbsocketclient.c
src/bbsocket.c src/optirun.c src/bbsocketclient.c src/findpathwild.c
bin_optirun_LDADD = ${glib_LIBS} ${kmod_LIBS} -lrt
bin_bumblebeed_SOURCES = src/pci.c src/bbconfig.c src/bblogger.c src/bbrun.c \
src/bbsocket.c src/module.c src/bbsecondary.c src/switch/switching.c \
src/switch/sw_bbswitch.c src/switch/sw_switcheroo.c \
src/driver.c src/bumblebeed.c
src/driver.c src/bumblebeed.c src/findpathwild.c
bin_bumblebeed_LDADD = ${x11_LIBS} ${libbsd_LIBS} ${glib_LIBS} ${kmod_LIBS} -lrt

dist_doc_DATA = $(relnotes) README.markdown
Expand Down
12 changes: 12 additions & 0 deletions quickinstall.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

make clean
autoreconf -fi
./configure CONF_DRIVER=nvidia CONF_DRIVER_MODULE_NVIDIA=nvidia???? \
CONF_PRIMUS_LD_PATH=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus \
CONF_LDPATH_NVIDIA=/usr/lib/nvidia????:/usr/lib32/nvidia???? \
CONF_MODPATH_NVIDIA=/usr/lib/nvidia????/xorg,/usr/lib/xorg/modules \
make
sudo make install


1 change: 1 addition & 0 deletions scripts/systemd/bumblebeed.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Description=Bumblebee C Daemon

[Service]
Type=simple
ExecStartPre=-/usr/bin/prime-select intel
ExecStart=@SBINDIR@/bumblebeed --use-syslog
Restart=always
RestartSec=60
Expand Down
32 changes: 26 additions & 6 deletions src/bbconfig.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright (c) 2011-2013, The Bumblebee Project
* Copyright (c) 2011-2017, The Bumblebee Project
* Author: Joaquín Ignacio Aramendía samsagax@gmail.com
* Author: Jaron Viëtor AKA "Thulinma" <jaron@vietors.com>
* Author: Stefan Helmert AKA "TheTesla" <stefan.helmert@t-online.de>
*
* This file is part of Bumblebee.
*
Expand Down Expand Up @@ -34,6 +35,7 @@
#include "bbconfig.h"
#include "bblogger.h"
#include "module.h"
#include "findpathwild.h"

/* config values for PM methods, edit bb_pm_method in bbconfig.h as well! */
const char *bb_pm_method_string[PM_METHODS_COUNT] = {
Expand Down Expand Up @@ -380,7 +382,10 @@ GKeyFile *bbconfig_parse_conf(void) {
}
key = "PrimusLibraryPath";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
free_and_set_value(&bb_config.primus_ld_path, g_key_file_get_string(bbcfg, section, key, NULL));
char* primusLibraryPath;
primusLibraryPath = malloc(MAX_STR_LEN);
findPathListWild(primusLibraryPath, g_key_file_get_string(bbcfg, section, key, NULL));
free_and_set_value(&bb_config.primus_ld_path, primusLibraryPath);
}
key = "VGLTransport";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
Expand Down Expand Up @@ -423,7 +428,10 @@ GKeyFile *bbconfig_parse_conf(void) {
}
key = "XorgConfDir";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
free_and_set_value(&bb_config.x_conf_dir, g_key_file_get_string(bbcfg, section, key, NULL));
char* xorgConfDir;
xorgConfDir = malloc(MAX_STR_LEN);
findPathListWild(xorgConfDir, g_key_file_get_string(bbcfg, section, key, NULL));
free_and_set_value(&bb_config.x_conf_dir, xorgConfDir);
}
key = "XorgBinary";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
Expand Down Expand Up @@ -457,18 +465,30 @@ void bbconfig_parse_conf_driver(GKeyFile *bbcfg, char *driver) {
/* if KernelDriver is empty, the default behavior is to copy Driver which
* is done in driver_detect() */
if (*module_name) {
free_and_set_value(&bb_config.module_name, module_name);
char* kernelDriver;
kernelDriver = malloc(MAX_STR_LEN);
if(findDriverWild(kernelDriver, module_name)) {
free_and_set_value(&bb_config.module_name, kernelDriver);
} else {
free_and_set_value(&bb_config.module_name, module_name);
}
} else {
g_free(module_name);
}
}
key = "LibraryPath";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
free_and_set_value(&bb_config.ld_path, g_key_file_get_string(bbcfg, section, key, NULL));
char* libraryPath;
libraryPath = malloc(MAX_STR_LEN);
findPathListWild(libraryPath, g_key_file_get_string(bbcfg, section, key, NULL));
free_and_set_value(&bb_config.ld_path, libraryPath);
}
key = "XorgModulePath";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
free_and_set_value(&bb_config.mod_path, g_key_file_get_string(bbcfg, section, key, NULL));
char* xorgModulePath;
xorgModulePath = malloc(MAX_STR_LEN);
findPathListWildDelim(xorgModulePath, g_key_file_get_string(bbcfg, section, key, NULL), ',');
free_and_set_value(&bb_config.mod_path, xorgModulePath);
}
key = "PMMethod";
if (g_key_file_has_key(bbcfg, section, key, NULL)) {
Expand Down
225 changes: 225 additions & 0 deletions src/findpathwild.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*
* Copyright (c) 2017, The Bumblebee Project
* Author: Stefan Helmert AKA "TheTesla" <stefan.helmert@t-online.de>
*
* This file is part of Bumblebee.
*
* Bumblebee 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 3 of the License, or
* (at your option) any later version.
*
* Bumblebee 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 Bumblebee. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* findpathwild.c: Bumblebee wildcard handler for configuration file handler
*/


#include "findpathwild.h"
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/utsname.h>


char* getRootPath(char *rootPath, char *wildPath)
{
char c;
c = 1;
unsigned pidxend = 0;
int i;
for(i=0; c && i < MAX_STR_LEN; i++){
c = wildPath[i];
rootPath[i] = c;
if('/' == c){
pidxend = i;
}
if('?' == c){
rootPath[pidxend] = 0;
return &wildPath[pidxend+1]; // may be dangerous, bacause reduces maximum string length
}
}
return "";
}

char* splitStr(char* str, char delim)
{
char c;
c = 1;
int i;
for(i=0; c && i < MAX_STR_LEN; i++){
c = str[i];
if(delim == c){
str[i] = 0;
return &str[i+1];
}

}
return "";
}

int cmpStrWild(char* inputStr, char* wildStr)
{
char ci, cw;
ci = 1;
cw = 1;
int i;
for(i = 0; ci && cw && i < MAX_STR_LEN; i++){
ci = inputStr[i];
cw = wildStr[i];
if(ci == cw) continue;
if('?' == cw) continue;
return 0;
}
if(0 == ci && 0 == cw) return 1;
return 0;
}

char* findPathWild(char* foundPath, char* wildPath)
{
DIR *dir;
struct dirent *ent;
char found[MAX_STR_LEN];
char rootPath[MAX_STR_LEN];
char currentLabel[MAX_STR_LEN];
char* pathEnd;
int cmpResult;


if('/' == wildPath[strlen(wildPath) -1]){
wildPath[strlen(wildPath) -1] = 0;
}

pathEnd = getRootPath(rootPath, wildPath);
strncpy(currentLabel, pathEnd, MAX_STR_LEN - 1);
pathEnd = splitStr(currentLabel, '/');
strncat(rootPath, "/", MAX_STR_LEN - strlen(rootPath) - 1);
// structur: /root/Path / currentLabel / p?th/E?d/
// | rootPath | currentLabel | pathEnd

if ((dir = opendir (rootPath)) != NULL) { // acceppt only if path exists
if(0 == currentLabel[0]) { // no currentLabel means end of path reached
strncpy(foundPath, rootPath, MAX_STR_LEN - 1);
closedir (dir);
return foundPath; // means the path is found in deepest recursion
}
while ((ent = readdir (dir)) != NULL) { // go through all dirs in rootPath
cmpResult = cmpStrWild(ent->d_name, currentLabel); // check if wildcard matches
if(cmpResult) { // found match - next recursion step, process inner directory wildcards
strncpy(found, rootPath, MAX_STR_LEN - 1);
strncat(found, ent->d_name, MAX_STR_LEN - strlen(found) - 1);
strncat(found, "/", MAX_STR_LEN - strlen(found) - 1);
strncat(found, pathEnd, MAX_STR_LEN - strlen(found) - 1);
if(findPathWild(foundPath, found) != NULL) {
closedir (dir);
return foundPath;
}
}
}
closedir (dir);
return NULL;
} else {
return NULL;
}
}


char* findPathListWildDelim(char* foundPathList, char* wildPathList, char delim)
{
char lWildPathList[MAX_STR_LEN] = "";
char foundPath[MAX_STR_LEN] = "";
char* nextStr;
char* wildPath;
char delimStr[2];
delimStr[0] = delim;
delimStr[1] = 0;
foundPathList[0] = 0;
strncpy(lWildPathList, wildPathList, MAX_STR_LEN - 1);
wildPath = lWildPathList;
while(1){
nextStr = splitStr(wildPath, delim);

if(0 == wildPath[0]) {
return foundPathList;
}

if(findPathWild(foundPath, wildPath)){
if(0 != foundPathList[0]) {
strncat(foundPathList, delimStr, MAX_STR_LEN - strlen(foundPathList) - 1);
}
strncat(foundPathList, foundPath, MAX_STR_LEN - strlen(foundPathList) - 1);
}
wildPath = nextStr;
}
return NULL;
}

char* findPathListWild(char* foundPathList, char* wildPathList)
{
return findPathListWildDelim(foundPathList, wildPathList, ':');
}

char* findFileWild(char* foundDriver, char* fileNameWild, char* rootPath)
{
DIR *dir;
struct dirent *ent;
char recursePath[MAX_STR_LEN];
char* ret;
if ((dir = opendir (rootPath)) != NULL) {
while ((ent = readdir (dir)) != NULL) {
if(0 == strcmp(ent->d_name, ".")) continue;
if(0 == strcmp(ent->d_name, "..")) continue;
strncpy(recursePath, rootPath, MAX_STR_LEN - 1);
strncat(recursePath, "/", MAX_STR_LEN - strlen(recursePath) - 1);
strncat(recursePath, ent->d_name, MAX_STR_LEN - strlen(recursePath) - 1);
if(NULL != (ret = findFileWild(foundDriver, fileNameWild, recursePath))) {
return ret;
}

}
closedir (dir);
return NULL;
} else { // can't open dir (is file or dir has not the right permissions)
struct stat s;
stat(rootPath, &s);
if(S_ISREG(s.st_mode)) { // is a file
if(cmpStrWild(basename(rootPath), fileNameWild)) {
strncpy(foundDriver, basename(rootPath), MAX_STR_LEN - 1);
return rootPath;
}
}
return NULL;
}
}

char* findDriverWild(char* foundDriver, char* driverNameWild)
{
struct utsname unameData;
char rootPath[MAX_STR_LEN];
char wild[MAX_STR_LEN];
char* ret;
if(uname(&unameData)) {
return NULL;
}
strncpy(rootPath, "/lib/modules/", MAX_STR_LEN - 1);
strncat(rootPath, unameData.release, MAX_STR_LEN - strlen(rootPath) - 1);
strncpy(wild, driverNameWild, MAX_STR_LEN - 1);
strncat(wild, ".ko", MAX_STR_LEN - strlen(wild) - 1);
ret = findFileWild(foundDriver, wild, rootPath);
foundDriver[strlen(foundDriver) - 3] = 0;
return ret;
}



41 changes: 41 additions & 0 deletions src/findpathwild.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2017, The Bumblebee Project
* Author: Stefan Helmert AKA "TheTesla" <stefan.helmert@t-online.de>
*
* This file is part of Bumblebee.
*
* Bumblebee 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 3 of the License, or
* (at your option) any later version.
*
* Bumblebee 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 Bumblebee. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* findpathwild.h: Bumblebee wildcard handler for configuration file handler
*/



#define MAX_STR_LEN 512

char* getRootPath(char *rootPath, char *wildPath);
char* splitStr(char* str, char delim);
int cmpStrWild(char* inputStr, char* wildStr);
char* findPathWild(char* foundPath, char* wildPath);
char* findPathListWildDelim(char* foundPathList, char* wildPathList, char delim);
char* findPathListWild(char* foundPathList, char* wildPathList);
char* findFileWild(char* foundDriver, char* fileNameWild, char* rootPath);
char* findDriverWild(char* foundDriver, char* driverNameWild);





Loading