Skip to content
Snippets Groups Projects
Commit db4653a4 authored by Utz-Uwe Haus's avatar Utz-Uwe Haus
Browse files

move mkdirhier() to utilities

parent 5fc04511
No related branches found
No related tags found
No related merge requests found
Pipeline #78771 passed
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#ifndef MAESTRO_I_MISC_H_ #ifndef MAESTRO_I_MISC_H_
#define MAESTRO_I_MISC_H_ 1 #define MAESTRO_I_MISC_H_ 1
#include "maestro/status.h"
/**@ingroup MSTRO_Internal /**@ingroup MSTRO_Internal
**@{ **@{
*/ */
...@@ -64,6 +66,11 @@ popcount(unsigned int v) ...@@ -64,6 +66,11 @@ popcount(unsigned int v)
#define ctz(x) (ffs(x)-1) #define ctz(x) (ffs(x)-1)
#endif #endif
/** ensure all directories in DIRNAME exist. If not, try creating them */
mstro_status
mkdirhier(const char *dirname);
/**@} (end of group MSTRO_Internal) */ /**@} (end of group MSTRO_Internal) */
#endif /* MAESTRO_I_MISC_H_ */ #endif /* MAESTRO_I_MISC_H_ */
...@@ -57,6 +57,7 @@ libmaestro_core_la_SOURCES = \ ...@@ -57,6 +57,7 @@ libmaestro_core_la_SOURCES = \
uuid.c uuid_sha1.c \ uuid.c uuid_sha1.c \
uuid_str.c uuid_ui128.c uuid_ui64.c \ uuid_str.c uuid_ui128.c uuid_ui64.c \
base64.c\ base64.c\
misc.c \
env.c logging.c tpl.c \ env.c logging.c tpl.c \
statistics.c \ statistics.c \
pool.c \ pool.c \
......
#include "maestro/i_misc.h"
#include "maestro/logging.h"
#define _POSIX_C_SOURCE 1
#include <limits.h>
#include <assert.h>
#include <sys/stat.h>
#include <errno.h>
/* simplify logging */
#define NOISE(...) LOG_DEBUG(MSTRO_LOG_MODULE_CORE,__VA_ARGS__)
#define DEBUG(...) LOG_DEBUG(MSTRO_LOG_MODULE_CORE,__VA_ARGS__)
#define INFO(...) LOG_INFO(MSTRO_LOG_MODULE_CORE,__VA_ARGS__)
#define WARN(...) LOG_WARN(MSTRO_LOG_MODULE_CORE,__VA_ARGS__)
#define ERR(...) LOG_ERR(MSTRO_LOG_MODULE_CORE,__VA_ARGS__)
/** find next separator in PATH. Return the start of that segment */
static inline
const char *
next_sep (const char *path)
{
while (*path)
if (*path == '/' || *path == '\\')
return path;
else
path++;
return NULL;
}
mstro_status
mkdirhier(const char *dirname)
{
assert(strlen(dirname)<PATH_MAX);
char buf[PATH_MAX];
const char *prev = dirname;
const char *next;
struct stat sb;
while(NULL!=(next = next_sep(prev))) {
strncpy(buf, dirname, next - dirname) ;
buf[next - dirname] = '\0';
if(stat(buf,&sb)) {
mkdir(buf, 0777); /* umask taken into account by system */
/* we ignore errors, as we'll see an error on the last part */
}
prev=next+1;
}
/* handle last part */
if(stat(dirname, &sb)) {
int s = mkdir(dirname, 0777);
if(s!=0) {
ERR("Failed to create GFS transport directory %s: %d (%s)\n",
dirname, errno, strerror(errno));
return MSTRO_FAIL;
}
}
return MSTRO_OK;
}
...@@ -177,47 +177,6 @@ mstro_transport__src_datalen_get(mstro_cdo src, ...@@ -177,47 +177,6 @@ mstro_transport__src_datalen_get(mstro_cdo src,
mstro_event_domain g_transport_rdma_edom = NULL; mstro_event_domain g_transport_rdma_edom = NULL;
const char* mstro_transport_rdma_edom_name = RDMA_EDOM_NAME; const char* mstro_transport_rdma_edom_name = RDMA_EDOM_NAME;
/** find next separator in PATH. Return the start of that segment */
static inline
const char * next_sep (const char *path)
{
while (*path)
if (*path == '/' || *path == '\\')
return path;
else
path++;
return NULL;
}
mstro_status
mkdirhier(char *dirname)
{
char buf[PATH_MAX];
const char *prev = dirname;
const char *next;
struct stat sb;
while(NULL!=(next = next_sep(prev))) {
strncpy(buf, dirname, next - dirname) ;
buf[next - dirname] = '\0';
if(stat(buf,&sb)) {
mkdir(buf, 0777); /* umask taken into account by system */
/* we ignore errors, as we'll see an error on the last part */
}
prev=next+1;
}
/* handle last part */
if(stat(dirname, &sb)) {
int s = mkdir(dirname, 0777);
if(s!=0) {
ERR("Failed to create GFS transport directory %s: %d (%s)\n",
dirname, errno, strerror(errno));
return MSTRO_FAIL;
}
}
return MSTRO_OK;
}
mstro_status mstro_status
mstro_transport_init() mstro_transport_init()
{ {
......
...@@ -87,10 +87,6 @@ mstro_transport__src_datalen_get(mstro_cdo src, ...@@ -87,10 +87,6 @@ mstro_transport__src_datalen_get(mstro_cdo src,
mstro_status mstro_status
mstro_transport_get_dst_buffer(mstro_cdo dst, void** data); mstro_transport_get_dst_buffer(mstro_cdo dst, void** data);
/** ensure all directories in DIRNAME exist. If not, try creating them */
mstro_status
mkdirhier(char *dirname);
/** @brief initialize individual transports */ /** @brief initialize individual transports */
mstro_status mstro_status
mstro_transport_init(); mstro_transport_init();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment