From 2d7937de262da8ac5e4c34a6f69400a69c29dac5 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Fri, 19 Jun 2009 01:53:24 +0000 Subject: [PATCH] Warn user of missing dirs and exit gracefully. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2262 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/coroipcs.c | 6 ++++++ exec/main.c | 14 ++++++++++++++ exec/util.h | 3 ++- test/cpgbench.c | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/exec/coroipcs.c b/exec/coroipcs.c index 82e92a5c..c8e9eb05 100644 --- a/exec/coroipcs.c +++ b/exec/coroipcs.c @@ -795,6 +795,7 @@ extern void coroipcs_ipc_init ( int server_fd; struct sockaddr_un un_addr; int res; + struct stat stat_out; api = init_state; @@ -826,6 +827,11 @@ extern void coroipcs_ipc_init ( #if defined(COROSYNC_LINUX) sprintf (un_addr.sun_path + 1, "%s", api->socket_name); #else + res = stat (SOCKETDIR, &stat_out); + if (res == -1 || (res == 0 && !S_ISDIR(stat_out.st_mode))) { + api->log_printf ("Required directory not present %s\n", SOCKETDIR); + api->fatal_error ("Please create required directory."); + } sprintf (un_addr.sun_path, "%s/%s", SOCKETDIR, api->socket_name); unlink (un_addr.sun_path); #endif diff --git a/exec/main.c b/exec/main.c index be6db0c0..d9cde9ac 100644 --- a/exec/main.c +++ b/exec/main.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -650,6 +651,8 @@ int main (int argc, char **argv) char *iface; int res, ch; int background, setprio; + struct stat stat_out; + char corosync_lib_dir[PATH_MAX]; #if defined(HAVE_PTHREAD_SPIN_LOCK) pthread_spin_init (&serialize_spin, 0); @@ -811,6 +814,17 @@ int main (int argc, char **argv) res = logsys_thread_priority_set (SCHED_OTHER, NULL, 1); } + /* + * Make sure required directory is present + */ + sprintf (corosync_lib_dir, "%s/lib/corosync", LOCALSTATEDIR); + res = stat (corosync_lib_dir, &stat_out); + if ((res == -1) || (res == 0 && !S_ISDIR(stat_out.st_mode))) { + log_printf (LOGSYS_LEVEL_ERROR, "Required directory not present %s. Please create it.\n", corosync_lib_dir); + corosync_exit_error (AIS_DONE_DIR_NOT_PRESENT); + } + + res = totem_config_read (objdb, &totem_config, &error_string); if (res == -1) { log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string); diff --git a/exec/util.h b/exec/util.h index ee31b071..7612b1b1 100644 --- a/exec/util.h +++ b/exec/util.h @@ -59,7 +59,8 @@ enum e_ais_done { AIS_DONE_OBJDB = -13, AIS_DONE_INIT_SERVICES = -14, AIS_DONE_OUT_OF_MEMORY = -15, - AIS_DONE_FATAL_ERR = -16 + AIS_DONE_FATAL_ERR = -16, + AIS_DONE_DIR_NOT_PRESENT = -17 }; /* diff --git a/test/cpgbench.c b/test/cpgbench.c index efa6a6ec..9f7be7e0 100644 --- a/test/cpgbench.c +++ b/test/cpgbench.c @@ -177,6 +177,7 @@ int main (void) { for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */ cpg_benchmark (handle, size); + signal (SIGALRM, sigalrm_handler); size += 1000; }