blob: 22164ddcc385b29444f72ecf26d1f20eca723da5 (
plain) (
tree)
|
|
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <systemd/sd-bus.h>
#include "libnpass/libnpass.h"
#include "npassd/db.h"
#include "npassd/service.h"
#include "util.h"
#define DBUS_WELL_KNOWN_NAME "org.freedesktop.secrets"
int main(void)
{
int ret;
sd_bus *bus;
char *store_path;
struct service service;
ret = pass_store_path_set(&store_path);
if (ret < 0)
return EXIT_FAILURE;
ret = db_init(store_path, &service.db);
if (ret < 0)
return EXIT_FAILURE;
ret = sd_bus_open_user(&bus);
if (ret < 0) {
print_err("Failed to connect to bus: %s", strerror(-ret));
return EXIT_FAILURE;
}
ret = sd_bus_request_name(bus, DBUS_WELL_KNOWN_NAME, 0);
if (ret < 0) {
print_err("Failed to acquire service name: %s", strerror(-ret));
if (ret == -EEXIST)
print_err(
"%s",
"Is a secret-service daemon already running?");
goto out_free_bus;
}
ret = service_init(bus, &service);
if (ret < 0)
goto out_free_bus;
for (;;) {
ret = sd_bus_process(bus, NULL);
if (ret < 0) {
fprintf(stderr, "Failed to process bus: %s\n",
strerror(-ret));
goto out_free_service;
}
if (ret > 0)
continue;
ret = sd_bus_wait(bus, UINT64_MAX);
if (ret < 0) {
fprintf(stderr, "Failed to wait on bus: %s\n",
strerror(-ret));
goto out_free_service;
}
}
out_free_service:
service_free(&service);
out_free_bus:
sd_bus_unref(bus);
return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
|