diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-04-11 00:36:41 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-04-11 00:36:41 (GMT) |
commit | 30009c26869094699c93ff5d922405e3a13fd26f (patch) | |
tree | 4bc9160061d1ab4dc1f8250185242fee1b348439 /src/analysis/db/client.c | |
parent | 3fbcabfd38e58dc4c47c9cd6ad95acb82e6e352b (diff) |
Moved all the temporary creations in a temporary directory.
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r-- | src/analysis/db/client.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index 31fc062..26d71f3 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -29,8 +29,6 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include <sys/socket.h> -#include <sys/un.h> #include <i18n.h> @@ -209,27 +207,15 @@ GDbClient *g_db_client_new(char *author, char *kfile, const char *name, const ch bool g_db_client_start_internal(GDbClient *client) { - char *suffix; /* Suffixe pour un fichier */ - char *sock_path; /* Chemin vers le canal UNIX */ + bool status; /* Bilan de la connexion */ struct sockaddr_un addr; /* Adresse de transmission */ int ret; /* Bilan d'un appel */ char *desc; /* Description du serveur ciblé*/ - bool status; /* Bilan de la connexion */ /* Identification du serveur à contacter */ - asprintf(&suffix, "chrysalide" G_DIR_SEPARATOR_S ".internal_server.%d", getpid()); - sock_path = get_xdg_config_dir(suffix); - free(suffix); - - memset(&addr, 0, sizeof(struct sockaddr_un)); - -#define UNIX_PATH_MAX 108 - - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, sock_path, UNIX_PATH_MAX - 1); - - free(sock_path); + status = build_tmp_socket("internal-server", &addr); + if (!status) goto gdcni_error; /* Création d'un canal de communication */ @@ -237,7 +223,7 @@ bool g_db_client_start_internal(GDbClient *client) if (client->fd == -1) { perror("socket"); - return false; + goto gdcni_error; } ret = connect(client->fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)); @@ -247,7 +233,7 @@ bool g_db_client_start_internal(GDbClient *client) goto gdcsi_no_listening; } - asprintf(&desc, "unix://.internal_server.%d", getpid()); + asprintf(&desc, "unix://%s", addr.sun_path); status = g_db_client_start_common(client, desc); @@ -261,6 +247,9 @@ bool g_db_client_start_internal(GDbClient *client) gdcsi_no_listening: close(client->fd); + + gdcni_error: + client->fd = -1; return false; |