From fa53571f2b1670383b4536540de35b732f973ac7 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 5 Sep 2013 15:14:00 +0200 Subject: [PATCH] Use common /var/run/rpcd base directory to store runtime information --- include/rpcd/session.h | 2 +- include/rpcd/uci.h | 2 ++ main.c | 5 +++++ uci.c | 8 ++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/rpcd/session.h b/include/rpcd/session.h index 70891bc..7fa388e 100644 --- a/include/rpcd/session.h +++ b/include/rpcd/session.h @@ -32,7 +32,7 @@ #define RPC_SID_LEN 32 #define RPC_DEFAULT_SESSION_TIMEOUT 300 -#define RPC_SESSION_DIRECTORY "/var/run/rpcd" +#define RPC_SESSION_DIRECTORY "/var/run/rpcd/sessions" struct rpc_session { struct avl_node avl; diff --git a/include/rpcd/uci.h b/include/rpcd/uci.h index 7a169f2..e334b9c 100644 --- a/include/rpcd/uci.h +++ b/include/rpcd/uci.h @@ -30,6 +30,8 @@ #include #include +#define RPC_UCI_SAVEDIR_PREFIX "/var/run/rpcd/uci-" + int rpc_uci_api_init(struct ubus_context *ctx); void rpc_uci_purge_savedirs(void); diff --git a/main.c b/main.c index 5a608c2..0bb06ce 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -58,6 +59,7 @@ exec_self(int argc, char **argv) int main(int argc, char **argv) { + struct stat s; const char *hangup; const char *ubus_socket = NULL; int ch; @@ -72,6 +74,9 @@ int main(int argc, char **argv) } } + if (stat("/var/run/rpcd", &s)) + mkdir("/var/run/rpcd", 0700); + signal(SIGPIPE, SIG_IGN); signal(SIGHUP, handle_signal); signal(SIGUSR1, handle_signal); diff --git a/uci.c b/uci.c index 0fede86..11df4d9 100644 --- a/uci.c +++ b/uci.c @@ -185,7 +185,7 @@ rpc_uci_set_savedir(struct blob_attr *sid) } snprintf(path, sizeof(path) - 1, - "/tmp/.uci-rpc-%s", (char *)blobmsg_data(sid)); + RPC_UCI_SAVEDIR_PREFIX "%s", blobmsg_get_string(sid)); uci_set_savedir(cursor, path); } @@ -1151,12 +1151,12 @@ rpc_uci_purge_savedir_cb(struct rpc_session *ses, void *priv) { char path[PATH_MAX]; - snprintf(path, sizeof(path) - 1, "/tmp/.uci-rpc-%s", ses->id); + snprintf(path, sizeof(path) - 1, RPC_UCI_SAVEDIR_PREFIX "%s", ses->id); rpc_uci_purge_savedir(path); } /* - * Removes all delta directories which match the /tmp/.uci-rpc-* pattern. + * Removes all delta directories which match the RPC_UCI_SAVEDIR_PREFIX. * This is used to clean up garbage when starting rpcd. */ void rpc_uci_purge_savedirs(void) @@ -1164,7 +1164,7 @@ void rpc_uci_purge_savedirs(void) int i; glob_t gl; - if (!glob("/tmp/.uci-rpc-*", 0, NULL, &gl)) + if (!glob(RPC_UCI_SAVEDIR_PREFIX "*", 0, NULL, &gl)) { for (i = 0; i < gl.gl_pathc; i++) rpc_uci_purge_savedir(gl.gl_pathv[i]);