-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include <dirent.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#include <ini.h> | ||
#include <tllist.h> | ||
|
||
/*int service_add(Service *service) { | ||
Launcher *launcher = service->launcher; | ||
_c_cleanup_(c_freep) char *object_path = NULL; | ||
int r; | ||
if (service->running) | ||
return 0; | ||
r = asprintf(&object_path, "/org/bus1/DBus/Name/%s", service->id); | ||
if (r < 0) | ||
return error_origin(-ENOMEM); | ||
r = sd_bus_call_method(launcher->bus_controller, | ||
NULL, | ||
"/org/bus1/DBus/Broker", | ||
"org.bus1.DBus.Broker", | ||
"AddName", | ||
NULL, | ||
NULL, | ||
"osu", | ||
object_path, | ||
service->name, | ||
service->uid); | ||
if (r < 0) | ||
return error_origin(r); | ||
service->running = true; | ||
return 0; | ||
}*/ | ||
|
||
struct service { | ||
char* name; | ||
char* systemd_service; | ||
char* user; | ||
|
||
int id; | ||
}; | ||
|
||
tll(struct service) service_list = tll_init(); | ||
|
||
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0 | ||
|
||
static int handler(void* user, const char* section, const char* name, const char* value) { | ||
struct service* service = user; | ||
if (MATCH("D-BUS Service", "Name")) { | ||
service->name = strdup(value); | ||
} else if (MATCH("D-BUS Service", "SystemdService")) { | ||
service->systemd_service = strdup(value); | ||
} else if (MATCH("D-BUS Service", "User")) { | ||
service->user = strdup(value); | ||
} else return 0; | ||
return 1; | ||
} | ||
|
||
void add_dir(const char* path) { | ||
struct dirent **namelist; | ||
int n; | ||
|
||
n = scandir(path, &namelist, NULL, alphasort); | ||
if (n == -1) { | ||
perror("scandir"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
chdir(path); | ||
while (n--) { | ||
if (namelist[n]->d_name[0] != '.') { | ||
struct service service = {0}; | ||
ini_parse(namelist[n]->d_name, handler, &service); | ||
if (service.name && service.systemd_service && service.user && strcmp(service.name, "org.bluez")) { | ||
printf("%s %s %s\n", service.name, service.systemd_service, service.user); | ||
tll_push_back(service_list, service); | ||
} | ||
} | ||
|
||
free(namelist[n]); | ||
} | ||
free(namelist); | ||
} | ||
|
||
#include "sd-bus.h" | ||
|
||
void add_service(sd_bus* bus_controller) { | ||
int i=0; | ||
tll_foreach(service_list, it) { | ||
char path[128]; | ||
sprintf(path, "/org/bus1/DBus/Name/%d", i); | ||
sd_bus_call_method(bus_controller, NULL, "/org/bus1/DBus/Broker", "org.bus1.DBus.Broker", "AddName", NULL, NULL, "osu", path, it->item.name, 0); | ||
it->item.id = i; | ||
i++; | ||
} | ||
} | ||
|
||
static struct service *find_service_by_id(int id) { | ||
tll_foreach(service_list, it) | ||
if (it->item.id == id) | ||
return &it->item; | ||
return NULL; | ||
} | ||
|
||
int start_service(int id) { | ||
int r = -1; | ||
struct service* service = find_service_by_id(id); | ||
if (service) { | ||
//printf("%s\n", service->systemd_service); | ||
char cmd[256]; | ||
sprintf(cmd, "s6-rc change %s", service->systemd_service); | ||
fprintf(stderr, "%s\n", cmd); | ||
r = system(cmd); | ||
} | ||
return r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind', 'basu'], value: 'auto', description: 'Provider of the sd-bus library') | ||
option('s6-rc', type : 'boolean', value : false) |