More functions converted to use threaded file handling.
- write log record function
diff --git a/osaf/services/saf/logsv/lgs/lgs_amf.c
b/osaf/services/saf/logsv/lgs/lgs_amf.c
--- a/osaf/services/saf/logsv/lgs/lgs_amf.c
+++ b/osaf/services/saf/logsv/lgs/lgs_amf.c
@@ -31,7 +31,7 @@ static void close_all_files(void)
stream = log_stream_getnext_by_name_nof(NULL);
while (stream != NULL) {
- if (log_stream_file_close_efop(stream) != 0)
+ if (log_stream_file_close_hf(stream) != 0)
LOG_WA("Could not close file for stream %s",
stream->name);
stream = log_stream_getnext_by_name_nof(stream->name);
diff --git a/osaf/services/saf/logsv/lgs/lgs_file.c
b/osaf/services/saf/logsv/lgs/lgs_file.c
--- a/osaf/services/saf/logsv/lgs/lgs_file.c
+++ b/osaf/services/saf/logsv/lgs/lgs_file.c
@@ -123,8 +123,6 @@ static void *file_hndl_thread(void *nopa
void *outbuf;
uint32_t max_outsize;
- gnolfh_in_t *lldtestpar1;
-
TRACE("LLDTEST: %s - is started",__FUNCTION__);
osaf_mutex_lock_ordie(&lgs_ftcom_mutex); /* LOCK */
@@ -176,18 +174,16 @@ static void *file_hndl_thread(void *nopa
break;
case LGSF_GET_NUM_LOGFILES:
TRACE("LLDTEST: %s - LGSF_GET_NUM_LOGFILES
received",__FUNCTION__);
- lldtestpar1 = (gnolfh_in_t *) inbuf;
- TRACE("LLDTEST from inbuf");
- TRACE("LLDTEST: lldtestpar1->file_name
\"%s\"",lldtestpar1->file_name);
- TRACE("LLDTEST: lldtestpar1->logsv_root_dir
\"%s\"",lldtestpar1->logsv_root_dir);
- TRACE("LLDTEST: lldtestpar1->pathName
\"%s\"",lldtestpar1->pathName);
-
hndl_rc = get_number_of_log_files_hdl(inbuf,
outbuf, max_outsize);
break;
case LGSF_MAKELOGDIR:
TRACE("LLDTEST: %s - LGSF_MAKELOGDIR
received",__FUNCTION__);
hndl_rc = make_log_dir_hdl(inbuf, outbuf,
max_outsize);
break;
+ case LGSF_WRITELOGREC:
+ TRACE("LLDTEST: %s - LGSF_WRITELOGREC
received",__FUNCTION__);
+ hndl_rc = write_log_record(inbuf, outbuf,
max_outsize);
+ break;
default:
break;
}
diff --git a/osaf/services/saf/logsv/lgs/lgs_file.h
b/osaf/services/saf/logsv/lgs/lgs_file.h
--- a/osaf/services/saf/logsv/lgs/lgs_file.h
+++ b/osaf/services/saf/logsv/lgs/lgs_file.h
@@ -19,9 +19,10 @@
#define LGS_FILE_H
#include <stdint.h>
-#include <limits.h>
#include <stddef.h>
+#include <saAis.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -40,6 +41,7 @@ typedef enum {
LGSF_DELETE_FILE,
LGSF_GET_NUM_LOGFILES,
LGSF_MAKELOGDIR,
+ LGSF_WRITELOGREC,
LGSF_NOREQ
}lgsf_treq_t;
@@ -53,62 +55,6 @@ typedef struct {
void *data_out; /* Buffer containing out data from the handler */
}lgsf_apipar_t;
-/*****************************************************************************
- * Handlers:
- * This is the part of a file system handling function that shall execute in
- * the file handling thread.
- * Defines for in and out parameters for each handler
- *****************************************************************************/
-
-/* fileopen_hdl
- * Inpar char str[]
- * No typedef needed
- * Ret code file descriptor or -1 if error
- * Outpar int errno_save
- * No typedef needed
- */
-
-/* fileclose_hdl
- * Inpar int fd
- * No typedef needed
- * No out parameters
- */
-
-/* delete_file_hdl
- * Inpar char str[]
- * No typedef needed
- * No out parameters
- */
-
-/* make_log_dir_hdl
- * Ret code -1 if error
- * Out parameter is a string of max PATH_MAX
- * Parameter data_out_size must be set to PATH_MAX
- */
-typedef struct {
- char root_dir[PATH_MAX+1]; /* Implementer defined root directory */
- char rel_path[PATH_MAX+1]; /* Path to create */
-}mld_in_t;
-
-/* get_number_of_log_files_hdl
- */
-typedef struct {
- /* File name prefix (name part before time stamps) */
- char file_name[NAME_MAX+1];
- /* logsv_root_dir + pathName makes up the path to the log files
- * Note: The whole path cannot be a longer string than PATH_MAX
- */
- char logsv_root_dir[PATH_MAX+1];
- char pathName[PATH_MAX+1];
-}gnolfh_in_t;
-
-/* parameter [out]
- * char str[PATH_MAX + NAME_MAX]
- * No typdef needed
- * Out parameter is a string of max PATH_MAX + NAME_MAX length
- * Parameter data_out_size must be set to PATH_MAX + NAME_MAX.
- */
-
char *lgsf_retcode_str(lgsf_retcode_t rc);
uint32_t lgs_file_init(void);
lgsf_retcode_t log_file_api(lgsf_apipar_t *param_in);
diff --git a/osaf/services/saf/logsv/lgs/lgs_filehdl.c
b/osaf/services/saf/logsv/lgs/lgs_filehdl.c
--- a/osaf/services/saf/logsv/lgs/lgs_filehdl.c
+++ b/osaf/services/saf/logsv/lgs/lgs_filehdl.c
@@ -55,6 +55,47 @@
*****************************************************************************/
/**
+ * Write a log record to file
+ * The file must be opened for append
+ *
+ * @param indata
+ * @param outdata
+ * @param max_outsize
+ * @return (-1) on error or number of written bytes
+ */
+int write_log_record(void *indata, void *outdata, size_t max_outsize)
+{
+ int rc, bytes_written = 0;
+ wlrh_t *params_in = (wlrh_t *) indata;
+ /* The logrecord is stored in the indata buffer right after the
+ * wlrh_t structure
+ */
+ char *logrecord = (char *) (indata + sizeof(wlrh_t));
+
+ TRACE_ENTER2("LLDTEST1");
+
+ retry:
+ rc = write(params_in->fd, &logrecord[bytes_written],
+ params_in->record_size - bytes_written);
+ if (rc == -1) {
+ if (errno == EINTR)
+ goto retry;
+
+ LOG_ER("write FAILED: %s", strerror(errno));
+ goto done;
+ } else {
+ /* Handle partial writes */
+ bytes_written += rc;
+ if (bytes_written < params_in->fixedLogRecordSize)
+ goto retry;
+ }
+
+ done:
+ TRACE_LEAVE2("LLDTEST1: rc=%d",rc);
+ return rc;
+}
+
+/**
* Make directory. Handles creation of directory path.
* Creates the relative in the directory given by the root path. If the root
* path does not exist/is not available a root path is created based on the
@@ -159,8 +200,8 @@ int fileopen_hdl(void *indata, void *out
char *filepath = (char *) indata;
int *errno_out_p = (int *) outdata;
- TRACE_ENTER2("LLDTEST1");
- TRACE("LLDTEST1: Open filepath \"%s\"",filepath);
+ TRACE_ENTER2("LLDTEST");
+ TRACE("LLDTEST: Open filepath \"%s\"",filepath);
open_retry:
fd_out = open(filepath, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR
| S_IRGRP);
@@ -176,7 +217,7 @@ open_retry:
}
*errno_out_p = errno_save;
- TRACE_LEAVE2("LLDTEST1");
+ TRACE_LEAVE2("LLDTEST");
return fd_out;
}
diff --git a/osaf/services/saf/logsv/lgs/lgs_filehdl.h
b/osaf/services/saf/logsv/lgs/lgs_filehdl.h
--- a/osaf/services/saf/logsv/lgs/lgs_filehdl.h
+++ b/osaf/services/saf/logsv/lgs/lgs_filehdl.h
@@ -11,11 +11,83 @@
#include <stdint.h>
#include <stddef.h>
#include <saAis.h>
+#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
+/*****************************************************************************
+ * Handlers:
+ * This is the part of a file system handling function that shall execute in
+ * the file handling thread.
+ * Defines for in and out parameters for each handler
+ *****************************************************************************/
+
+/* fileopen_hdl
+ * Inpar char str[]
+ * No typedef needed
+ * Ret code file descriptor or -1 if error
+ * Outpar int errno_save
+ * No typedef needed
+ */
+
+/* fileclose_hdl
+ * Inpar int fd
+ * No typedef needed
+ * No out parameters
+ */
+
+/* delete_file_hdl
+ * Inpar char str[]
+ * No typedef needed
+ * No out parameters
+ */
+
+/* make_log_dir_hdl
+ * Ret code -1 if error
+ * Out parameter is a string of max PATH_MAX
+ * Parameter data_out_size must be set to PATH_MAX
+ */
+typedef struct {
+ char root_dir[PATH_MAX+1]; /* Implementer defined root directory */
+ char rel_path[PATH_MAX+1]; /* Path to create */
+}mld_in_t;
+
+/* get_number_of_log_files_hdl(..)
+ */
+typedef struct {
+ /* File name prefix (name part before time stamps) */
+ char file_name[NAME_MAX+1];
+ /* logsv_root_dir + pathName makes up the path to the log files
+ * Note: The whole path cannot be a longer string than PATH_MAX
+ */
+ char logsv_root_dir[PATH_MAX+1];
+ char pathName[PATH_MAX+1];
+}gnolfh_in_t;
+
+ /* parameter [out]
+ * char str[PATH_MAX + NAME_MAX]
+ * No typdef needed
+ * Out parameter is a string of max PATH_MAX + NAME_MAX length
+ * Parameter data_out_size must be set to PATH_MAX + NAME_MAX.
+ */
+
+/* write_log_record_hdl(..)
+ * TBD: Fix handling of logrecord of unknown size!!!
+ * No out parameters
+ */
+typedef struct {
+ int fd; /* File descriptor for current log file */
+ size_t record_size; /* Size of logrecord including '\0' */
+ SaUint32T fixedLogRecordSize;
+}wlrh_t;
+/* logrecord:
+ * Is a string of varying length.
+ * Shall be added to the indata buffer directly after the wlrh_t
+ */
+
+int write_log_record(void *indata, void *outdata, size_t max_outsize);
int make_log_dir_hdl(void *indata, void *outdata, size_t max_outsize);
int fileopen_hdl(void *indata, void *outdata, size_t max_outsize);
int fileclose_hdl(void *indata, void *outdata, size_t max_outsize);
diff --git a/osaf/services/saf/logsv/lgs/lgs_imm.c
b/osaf/services/saf/logsv/lgs/lgs_imm.c
--- a/osaf/services/saf/logsv/lgs/lgs_imm.c
+++ b/osaf/services/saf/logsv/lgs/lgs_imm.c
@@ -802,7 +802,7 @@ static void logRootDirectory_set(const c
/* Create new files at new path */
stream = log_stream_getnext_by_name_nof(NULL);
while (stream != NULL) {
- if (lgs_create_config_file_efop(stream) != 0) {
+ if (lgs_create_config_file_ufop(stream) != 0) {
LOG_ER("New config file could not be created for
stream: %s",
stream->name);
}
diff --git a/osaf/services/saf/logsv/lgs/lgs_stream.c
b/osaf/services/saf/logsv/lgs/lgs_stream.c
--- a/osaf/services/saf/logsv/lgs/lgs_stream.c
+++ b/osaf/services/saf/logsv/lgs/lgs_stream.c
@@ -28,6 +28,7 @@
#include "lgs.h"
#include "lgs_file.h"
+#include "lgs_filehdl.h"
#define DEFAULT_NUM_APP_LOG_STREAMS 64
#define LGS_LOG_FILE_EXT ".log"
@@ -58,7 +59,7 @@ static int fileopen_hfop(char *filepath,
lgsf_retcode_t api_rc;
int fd;
- TRACE_ENTER2("LLDTEST1");
+ TRACE_ENTER2("LLDTEST");
osafassert(filepath != NULL);
@@ -71,14 +72,14 @@ static int fileopen_hfop(char *filepath,
api_rc = log_file_api(&apipar);
if (api_rc != LGSF_SUCESS) {
- TRACE("LLDTEST1: %s - API error %d",__FUNCTION__,api_rc);
+ TRACE("LLDTEST: %s - API error %d",__FUNCTION__,api_rc);
fd = -1;
} else {
fd = apipar.hdl_ret_code_out;
}
- TRACE("LLDTEST1: return %d",fd);
+ TRACE("LLDTEST: return %d",fd);
- TRACE_LEAVE2("LLDTEST1");
+ TRACE_LEAVE2("LLDTEST");
return fd;
}
@@ -622,7 +623,7 @@ int log_file_open_fh(log_stream_t *strea
char pathname[PATH_MAX + NAME_MAX + 1];
int errno_ret;
- TRACE_ENTER2("LLDTEST1");
+ TRACE_ENTER2("LLDTEST");
sprintf(pathname, "%s/%s/%s.log", lgs_cb->logsv_root_dir,
stream->pathName, stream->logFileCurrent);
@@ -631,7 +632,7 @@ int log_file_open_fh(log_stream_t *strea
*errno_save = errno_ret;
}
- TRACE_LEAVE2("LLDTEST1");
+ TRACE_LEAVE2("LLDTEST");
return fd;
}
@@ -661,7 +662,7 @@ SaAisErrorT log_stream_open_efop(log_str
goto done;
}
- if (lgs_create_config_file_efop(stream) != 0) {
+ if (lgs_create_config_file_ufop(stream) != 0) {
rc = SA_AIS_ERR_TRY_AGAIN;
goto done;
}
@@ -686,7 +687,7 @@ SaAisErrorT log_stream_open_efop(log_str
}
/* be nice to those without a shared file system, see #1138 */
- if (lgs_create_config_file_efop(stream) != 0) {
+ if (lgs_create_config_file_ufop(stream) != 0) {
LOG_ER("%s: Creating config file failed", __FUNCTION__);
rc = SA_AIS_ERR_TRY_AGAIN;
goto done;
@@ -731,11 +732,11 @@ int log_stream_close_efop(log_stream_t *
goto done;
}
- rc = lgs_file_rename_fop(stream->pathName,
stream->logFileCurrent, timeString, LGS_LOG_FILE_EXT);
+ rc = lgs_file_rename_ufop(stream->pathName,
stream->logFileCurrent, timeString, LGS_LOG_FILE_EXT);
if (rc == -1)
goto done;
- rc = lgs_file_rename_fop(stream->pathName,
stream->fileName, timeString, LGS_LOG_FILE_CONFIG_EXT);
+ rc = lgs_file_rename_ufop(stream->pathName,
stream->fileName, timeString, LGS_LOG_FILE_CONFIG_EXT);
if (rc == -1)
goto done;
}
@@ -756,7 +757,7 @@ int log_stream_close_efop(log_stream_t *
*
* @return int
*/
-int log_stream_file_close_efop(log_stream_t *stream)
+int log_stream_file_close_hf(log_stream_t *stream)
{
int rc = 0;
@@ -777,116 +778,6 @@ int log_stream_file_close_efop(log_strea
return rc;
}
-#if 0 /* replaced by file handler */
-static int check_oldest(char *line, char *fname_prefix, int fname_prefix_size,
int *old_date, int *old_time)
-{
- int date, time, c, d;
- date = time = c = d = 0;
- int len = 0;
- char name_format[NAME_MAX+1];
- char time_stamps[] = "_%d_%d_%d_%d.log";
-
- len = strlen(time_stamps);
- len += fname_prefix_size;
-
- strncpy(name_format, fname_prefix, fname_prefix_size);
- name_format[fname_prefix_size] = '\0';
- TRACE_3("fname: %s", name_format);
- strncat(name_format, time_stamps, NAME_MAX);
- if (sscanf(line, name_format, &date, &time, &c, &d) == 4) {
- TRACE_3("line: arg1: %d 2: %d 3: %d 4: %d ok", date, time, c,
d);
- if (date < *old_date || *old_date == -1) {
- *old_date = date;
- *old_time = time;
- return 1;
- } else if ((date == *old_date) && (time < *old_time)) {
- *old_date = date;
- *old_time = time;
- return 1;
- }
- } else if (sscanf(line, name_format, &date, &time) == 2) {
- TRACE_3("line: arg1: %d 2: %d ok", date, time);
- if (date < *old_date || *old_date == -1) {
- *old_date = date;
- *old_time = time;
- return 1;
- } else if ((date == *old_date) && (time < *old_time)) {
- *old_date = date;
- *old_time = time;
- return 1;
- }
- } else {
- TRACE_3("no match");
- }
- return 0;
-}
-
-/* Filter function used by scandir. */
-static char file_prefix[NAME_MAX];
-static int filter_func(const struct dirent *finfo)
-{
- int ret;
- ret = strncmp(file_prefix, finfo->d_name, strlen(file_prefix));
- return !ret;
-}
-
-/**
- * Return number of log files in a dir and the name of the oldest file.
- * @param logStream[in]
- * @param oldest_file[out]
- *
- * @return int
- */
-static int get_number_of_log_files_hfop(log_stream_t *logStream, char
*oldest_file)
-{
- struct dirent **namelist;
- int n, old_date = -1, old_time = -1, old_ind = -1, files, i, failed = 0;
- char path[PATH_MAX];
-
- osafassert(oldest_file != NULL);
-
- /* Initialize the filter */
- strcpy(file_prefix, logStream->fileName);
-
- sprintf(path, "%s/%s", lgs_cb->logsv_root_dir, logStream->pathName);
- files = n = scandir(path, &namelist, filter_func, alphasort);
- if (n == -1 && errno == ENOENT)
- return 0;
-
- if (n < 0) {
- LOG_ER("scandir:%s %s", strerror(errno), path);
- return -1;
- }
-
- TRACE_3("There are %d files", n);
- if (n == 0)
- return files;
-
- while (n--) {
- TRACE_3("%s", namelist[n]->d_name);
- if (check_oldest(namelist[n]->d_name, logStream->fileName,
- strlen(logStream->fileName), &old_date,
&old_time)) {
- old_ind = n;
- } else {
- failed++; /* wrong format */
- }
- }
- if (old_ind != -1) {
- TRACE_1(" oldest: %s", namelist[old_ind]->d_name);
- sprintf(oldest_file, "%s/%s", path, namelist[old_ind]->d_name);
- } else {
- TRACE("Only file/files with wrong format found");
- }
-
- /* Free scandir allocated memory */
- for (i = 0; i < files; i++)
- free(namelist[i]);
- free(namelist);
-
- return (files - failed);
-}
-#endif
-
/**
* Return number of log files in a dir and the name of the oldest file.
* @param logStream[in]
@@ -926,6 +817,7 @@ static int get_number_of_log_files_hfop(
return rc;
}
+#if 0
/**
* log_stream_write will write a number of bytes to the associated file. If
* the file size gets too big, the file is closed, renamed and a new file is
@@ -956,7 +848,7 @@ int log_stream_write_efop(log_stream_t *
goto done;
}
/* Creating config file on new ACTIVE */
- if (lgs_create_config_file_efop(stream) != 0) {
+ if (lgs_create_config_file_ufop(stream) != 0) {
TRACE("Creating config file failed");
rc = -1;
goto done;
@@ -970,6 +862,7 @@ int log_stream_write_efop(log_stream_t *
TRACE("stream %s now opened", stream->name);
}
+#if 1 /* LLDTEST: Replace by filehdl function */
retry:
rc = write(stream->fd, &buf[bytes_written], count - bytes_written);
if (rc == -1) {
@@ -986,7 +879,8 @@ int log_stream_write_efop(log_stream_t *
if (bytes_written < stream->fixedLogRecordSize)
goto retry;
}
-
+#endif
+
rc = 0;
stream->curFileSize += count;
@@ -1000,7 +894,7 @@ int log_stream_write_efop(log_stream_t *
}
stream->fd = -1;
- rc = lgs_file_rename_fop(stream->pathName,
stream->logFileCurrent, current_time, LGS_LOG_FILE_EXT);
+ rc = lgs_file_rename_ufop(stream->pathName,
stream->logFileCurrent, current_time, LGS_LOG_FILE_EXT);
if (rc == -1)
goto done;
@@ -1026,6 +920,135 @@ int log_stream_write_efop(log_stream_t *
TRACE_LEAVE2("rc=%d", rc);
return rc;
}
+#endif
+#if 1
+/**
+ * log_stream_write will write a number of bytes to the associated file. If
+ * the file size gets too big, the file is closed, renamed and a new file is
+ * opened. If there are too many files, the oldest file will be deleted.
+ *
+ * @param stream
+ * @param buf
+ * @param count
+ *
+ * @return int -1 on error, 0 otherwise
+ */
+int log_stream_write_efop(log_stream_t *stream, const char *buf, size_t count)
+{
+ int rc = 0;
+ lgsf_apipar_t apipar;
+ void *params_in;
+ wlrh_t *header_in_p;
+ char *logrec_p;
+ size_t params_in_size;
+ lgsf_retcode_t api_rc;
+
+ osafassert(stream != NULL && buf != NULL);
+ TRACE_ENTER2("%s", stream->name);
+
+ /* Open files on demand e.g. on new active after fail/switch-over. This
+ * enables LOG to cope with temporary file system problems. */
+
+ if (stream->fd == -1) {
+ /* Creating directory of given path to store log and cfg files,
+ * if not using shared file system. */
+ if (lgs_make_dir_hfop(stream->pathName) != 0) {
+ LOG_NO("Create directory '%s/%s' failed",
lgs_cb->logsv_root_dir, stream->pathName);
+ rc = -1;
+ goto done;
+ }
+ /* Creating config file on new ACTIVE */
+ if (lgs_create_config_file_ufop(stream) != 0) {
+ TRACE("Creating config file failed");
+ rc = -1;
+ goto done;
+ }
+ TRACE("stream: %s not opened, opening it now", stream->name);
+ stream->fd = log_file_open_fh(stream, NULL);
+ if (stream->fd == -1) {
+ rc = -1;
+ goto done;
+ }
+ TRACE("stream %s now opened", stream->name);
+ }
+
+ /* Write the log record
+ */
+ /* allocate memory for header + log record */
+ params_in_size = sizeof(wlrh_t) + count;
+ params_in = malloc(params_in_size);
+
+ header_in_p = (wlrh_t *) params_in;
+ logrec_p = (char *) (params_in + sizeof(wlrh_t));
+
+ header_in_p->fd = stream->fd;
+ header_in_p->fixedLogRecordSize = stream->fixedLogRecordSize;
+ header_in_p->record_size = count;
+ memcpy(logrec_p, buf, count);
+
+ /* Fill in API structure */
+ apipar.req_code_in = LGSF_WRITELOGREC;
+ apipar.data_in_size = params_in_size;
+ apipar.data_in = params_in;
+ apipar.data_out_size = 0;
+ apipar.data_out = NULL;
+
+ api_rc = log_file_api(&apipar);
+ if (api_rc != LGSF_SUCESS) {
+ TRACE("%s - API error %d",__FUNCTION__,api_rc);
+ rc = -1;
+ } else {
+ rc = apipar.hdl_ret_code_out;
+ }
+
+ free(params_in);
+
+ if (rc == -1) {
+ /* Careful with log level here to avoid syslog flooding */
+ LOG_IN("write '%s' failed", stream->logFileCurrent);
+ }
+ /* End write the log record */
+
+ rc = 0;
+ stream->curFileSize += count;
+
+ if ((stream->curFileSize + count) > stream->maxLogFileSize) {
+ int errno_save;
+ char *current_time = lgs_get_time();
+
+ if ((rc = fileclose_hfop(stream->fd)) == -1) {
+ LOG_ER("close FAILED: %s", strerror(errno));
+ goto done;
+ }
+ stream->fd = -1;
+
+ rc = lgs_file_rename_ufop(stream->pathName,
stream->logFileCurrent, current_time, LGS_LOG_FILE_EXT);
+ if (rc == -1)
+ goto done;
+
+ /* Invalidate logFileCurrent for this stream */
+ stream->logFileCurrent[0] = 0;
+
+ /* Remove oldest file if needed */
+ if ((rc = rotate_if_needed_fh(stream)) == -1)
+ goto done;
+
+ stream->creationTimeStamp = lgs_get_SaTime();
+ sprintf(stream->logFileCurrent, "%s_%s", stream->fileName,
current_time);
+ if ((stream->fd = log_file_open_fh(stream, &errno_save)) == -1)
{
+ LOG_NO("Could not open '%s' - %s",
stream->logFileCurrent, strerror(errno_save));
+ rc = -1;
+ goto done;
+ }
+
+ stream->curFileSize = 0;
+ }
+
+ done:
+ TRACE_LEAVE2("rc=%d", rc);
+ return rc;
+}
+#endif
/**
* Get stream from array
@@ -1209,18 +1232,18 @@ int log_stream_config_change_efop(bool c
goto done;
}
- if ((rc = lgs_file_rename_fop(stream->pathName,
stream->logFileCurrent, current_time, LGS_LOG_FILE_EXT)) == -1) {
+ if ((rc = lgs_file_rename_ufop(stream->pathName,
stream->logFileCurrent, current_time, LGS_LOG_FILE_EXT)) == -1) {
goto done;
}
- if ((rc = lgs_file_rename_fop(stream->pathName,
current_file_name, current_time, LGS_LOG_FILE_CONFIG_EXT)) == -1) {
+ if ((rc = lgs_file_rename_ufop(stream->pathName,
current_file_name, current_time, LGS_LOG_FILE_CONFIG_EXT)) == -1) {
goto done;
}
}
/* Creating the new config file */
if (create_files_f == LGS_STREAM_CREATE_FILES) {
- if ((rc = lgs_create_config_file_efop(stream)) != 0)
+ if ((rc = lgs_create_config_file_ufop(stream)) != 0)
goto done;
sprintf(stream->logFileCurrent, "%s_%s", stream->fileName,
current_time);
diff --git a/osaf/services/saf/logsv/lgs/lgs_stream.h
b/osaf/services/saf/logsv/lgs/lgs_stream.h
--- a/osaf/services/saf/logsv/lgs/lgs_stream.h
+++ b/osaf/services/saf/logsv/lgs/lgs_stream.h
@@ -77,7 +77,7 @@ extern log_stream_t *log_stream_new_2_no
extern SaAisErrorT log_stream_open_efop(log_stream_t *stream);
extern int log_stream_close_efop(log_stream_t **stream);
-extern int log_stream_file_close_efop(log_stream_t *stream);
+extern int log_stream_file_close_hf(log_stream_t *stream);
extern int log_stream_write_efop(log_stream_t *stream, const char *buf, size_t
count);
extern void log_stream_id_print(void);
diff --git a/osaf/services/saf/logsv/lgs/lgs_util.c
b/osaf/services/saf/logsv/lgs/lgs_util.c
--- a/osaf/services/saf/logsv/lgs/lgs_util.c
+++ b/osaf/services/saf/logsv/lgs/lgs_util.c
@@ -41,6 +41,7 @@
#include "lgs_util.h"
#include "lgs_fmt.h"
#include "lgs_file.h"
+#include "lgs_filehdl.h"
#define ALARM_STREAM_ENV_PREFIX "ALARM"
#define NOTIFICATION_STREAM_ENV_PREFIX "NOTIFICATION"
@@ -60,7 +61,7 @@
*
* @return int
*/
-int lgs_create_config_file_efop(log_stream_t *stream)
+int lgs_create_config_file_ufop(log_stream_t *stream)
{
int rc, n;
char pathname[PATH_MAX + NAME_MAX];
@@ -195,7 +196,7 @@ SaTimeT lgs_get_SaTime(void)
*
* @return int
*/
-int lgs_file_rename_fop(const char *path, const char *old_name, const char
*time_stamp, const char *suffix)
+int lgs_file_rename_ufop(const char *path, const char *old_name, const char
*time_stamp, const char *suffix)
{
int ret;
char oldpath[PATH_MAX + NAME_MAX];
@@ -330,106 +331,6 @@ bool lgs_relative_path_check_ts(const ch
return rc;
}
-#if 0
-static void quick_fix_make_root_dir_fop(const char* root_dir)
-{
- struct stat statbuf;
- char dir_to_make[PATH_MAX];
- char* dir_ptr = strchr(root_dir, '/');
- dir_ptr++;
- while ((dir_ptr = strchr(dir_ptr, '/')) != NULL) {
- dir_ptr++;
- strncpy(dir_to_make, root_dir, dir_ptr - root_dir);
- dir_to_make[dir_ptr - root_dir] = '\0';
- if (lstat(dir_to_make, &statbuf) != 0) {
- mkdir(dir_to_make, S_IRWXU | S_IRWXG | S_IRWXO);
- }
- }
- if (lstat(root_dir, &statbuf) != 0) {
- mkdir(root_dir, S_IRWXU | S_IRWXG | S_IRWXO);
- }
-}
-
-/**
- * Create directory structure, if not already created.
- * @param path
- * @return -1 on error
- */
-int lgs_make_dir_hfop(const char* root, const char* path)
-{
- int rc = 0;
- const int MAX_DEPTH = 10;
- const char* path_p = path;
- int dir_depth = 0;
- size_t dirs_len[MAX_DEPTH];
- struct stat buf;
- char dir_to_make[PATH_MAX + NAME_MAX];
- int i = 0;
- int rel_idx = strlen(root);
-
- TRACE_ENTER();
-
- /* the root directory must already exist. */
- struct stat statbuf;
-
- /* quick temporary fix for ticket 3053 */
- if (lstat(root, &statbuf) != 0) {
- quick_fix_make_root_dir_fop(root);
- }
- /* end tempoarary fix */
-
- if (lgs_relative_path_check_ts(root) || lstat(root, &statbuf) != 0 ||
- (strlen(root) + strlen(path) + 2) > (PATH_MAX +
NAME_MAX)) {
- LOG_ER("root directory problem %s", root);
- rc = -1;
- goto done;
- }
- if (lgs_relative_path_check_ts(path)) {
- LOG_ER("relative path in directory %s", path);
- rc = -1;
- goto done;
- }
-
- /* Check the relative path directory depth, will not allow more than
10. */
- while (dir_depth < MAX_DEPTH && (path_p = strchr(path_p, '/')) != NULL)
{
- if (path_p > &path[0]) {
- /* cover the '//' situation */
- if (*(path_p -1) != '/') {
- dirs_len[dir_depth++] = path_p - &path[0];
- }
- }
- path_p++;
- }
- /* cover the case when the string doesn't end with '/' */
- if (path[strlen(path) -1] != '/') dirs_len[dir_depth++] = strlen(path);
-
- if (path_p != NULL) {
- LOG_ER("relative path directory problem %s", path);
- rc = -1;
- goto done;
- }
-
- strncpy(dir_to_make, root, strlen(root));
- if (path[0] != '/' && root[strlen(root) -1] != '/') {
- dir_to_make[strlen(root)] = '/';
- rel_idx++;
- }
- while (rc == 0 && i < dir_depth) {
- strncpy(&dir_to_make[rel_idx], path, dirs_len[i]);
- dir_to_make[rel_idx + dirs_len[i]] = '\0';
- if (lstat(dir_to_make, &buf) != 0)
- {
- rc = mkdir(dir_to_make, S_IRWXU | S_IRWXG | S_IRWXO);
- }
- i++;
- }
-
-done:
- TRACE_LEAVE2("%u", rc);
- return rc;
-}
-#endif
-
/**
* Create directory structure, if not already created.
* The structure is created in the log service root directory pointed to in
@@ -456,7 +357,7 @@ int lgs_make_dir_hfop(const char* path)
TRACE_ENTER2("LLDTEST");
- /* Check depth of path */
+ /* Check depth of path TBD */
// while (strchr)
strncpy(params_in.root_dir, lgs_cb->logsv_root_dir, PATH_MAX+1);
diff --git a/osaf/services/saf/logsv/lgs/lgs_util.h
b/osaf/services/saf/logsv/lgs/lgs_util.h
--- a/osaf/services/saf/logsv/lgs/lgs_util.h
+++ b/osaf/services/saf/logsv/lgs/lgs_util.h
@@ -45,10 +45,10 @@
*/
extern char *lgs_get_time(void);
-extern int lgs_create_config_file_efop(log_stream_t *stream);
+extern int lgs_create_config_file_ufop(log_stream_t *stream);
extern void lgs_evt_destroy(lgsv_lgs_evt_t *evt);
extern SaTimeT lgs_get_SaTime(void);
-extern int lgs_file_rename_fop(const char *path, const char *old_name, const
char *time_stamp, const char *suffix);
+extern int lgs_file_rename_ufop(const char *path, const char *old_name, const
char *time_stamp, const char *suffix);
//extern uint32_t lgs_create_known_streams(lgs_cb_t *lgs_cb); /* Not used, no
code */
extern void lgs_exit(const char *msg, SaAmfRecommendedRecoveryT rec_rcvr);
extern bool lgs_relative_path_check_ts(const char* path);
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel