summaryrefslogtreecommitdiff
path: root/src/analysis/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db')
-rw-r--r--src/analysis/db/client.c27
-rw-r--r--src/analysis/db/server.c50
2 files changed, 21 insertions, 56 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;
diff --git a/src/analysis/db/server.c b/src/analysis/db/server.c
index 6455fda..1565501 100644
--- a/src/analysis/db/server.c
+++ b/src/analysis/db/server.c
@@ -31,8 +31,6 @@
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/un.h>
#include <i18n.h>
@@ -65,10 +63,6 @@ typedef union _gen_sockaddr_t
} gen_sockaddr_t;
-#ifndef UNIX_PATH_MAX
-# define UNIX_PATH_MAX 108
-#endif
-
/* Assure que le point de connexion est vierge. */
typedef bool (* clean_server_socket_cb) (GDbServer *);
@@ -176,6 +170,8 @@ static void g_db_server_init(GDbServer *server)
{
server->fd = -1;
+ server->basedir = NULL;
+
g_mutex_init(&server->mutex);
}
@@ -199,6 +195,9 @@ static void g_db_server_finalize(GDbServer *server)
free(server->desc);
+ if (server->basedir != NULL)
+ free(server->basedir);
+
G_OBJECT_CLASS(g_db_server_parent_class)->finalize(G_OBJECT(server));
}
@@ -221,9 +220,6 @@ GDbServer *g_db_server_new_internal(const char *author, char *kfile)
{
GDbServer *result; /* Adresse à retourner */
bool status; /* Bilan d'un chargement */
- char *suffix; /* Suffixe pour un fichier */
- size_t sock_length; /* Taille du chemin complet */
- char *sock_path; /* Chemin vers le canal UNIX */
result = g_object_new(G_TYPE_DB_SERVER, NULL);
@@ -236,33 +232,14 @@ GDbServer *g_db_server_new_internal(const char *author, char *kfile)
result->domain = AF_UNIX;
- asprintf(&suffix, "chrysalide" G_DIR_SEPARATOR_S ".internal_server.%d", getpid());
- sock_path = get_xdg_config_dir(suffix);
- free(suffix);
-
- sock_length = strlen(sock_path) + 1;
-
- if (sock_length > UNIX_PATH_MAX)
- {
- log_variadic_message(LMT_ERROR,
- _("Impossible to use '%s' for the internal server: path is too long ! (%zu vs %u)\n"),
- sock_path, sock_length, UNIX_PATH_MAX);
-
- goto gdsni_too_long;
- }
-
- memset(&result->addr, 0, sizeof(struct sockaddr_un));
-
- result->addr.unix_addr.sun_family = AF_UNIX;
- strncpy(result->addr.unix_addr.sun_path, sock_path, UNIX_PATH_MAX - 1);
-
- free(sock_path);
+ status = build_tmp_socket("internal-server", &result->addr.unix_addr);
+ if (!status) goto gdsni_error;
result->sock_len = sizeof(struct sockaddr_un);
/* Désignation humaine */
- asprintf(&result->desc, "unix://.internal_server.%d", getpid());
+ asprintf(&result->desc, "unix://%s", result->addr.unix_addr.sun_path);
/* Aide pour une sortie propre ? */
@@ -274,10 +251,6 @@ GDbServer *g_db_server_new_internal(const char *author, char *kfile)
return result;
- gdsni_too_long:
-
- free(sock_path);
-
gdsni_error:
g_object_unref(G_OBJECT(result));
@@ -351,6 +324,8 @@ GDbServer *g_db_server_new_remote(const char *conf)
struct hostent *hp; /* Informations sur l'hôte */
size_t desclen; /* Taille de désignation */
const char *ip; /* Adresse IPv4 ou IPv6 */
+ const char *tmpdir; /* Répertoire de travail */
+ bool status; /* Bilan d'un consultation */
result = g_object_new(G_TYPE_DB_SERVER, NULL);
@@ -404,9 +379,10 @@ GDbServer *g_db_server_new_remote(const char *conf)
/* Répertoire de stockage */
+ status = g_generic_config_get_value(get_main_configuration(), MPK_TMPDIR, &tmpdir);
+ if (!status) goto gdsn_error;
- result->basedir = strdup("/tmp/"); /* TODO */
-
+ result->basedir = strdup(tmpdir);
return result;