Skip to content

Commit 743b258

Browse files
author
norberttakacs
committed
persist-tool: add persist-tool to OSE
In this first commit the goal was to be able to compile persist-tool and make dump function to be working. Signed-off-by: norberttakacs <norbert.takacs@balabit.com>
1 parent ba2d3ad commit 743b258

16 files changed

+1669
-56
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ include packaging/debian/Makefile.am
219219
include dbld/Makefile.am
220220
include cmake/Makefile.am
221221
include dev-utils/plugin_skeleton_creator/Makefile.am
222+
include persist-tool/Makefile.am
222223

223224
TEST_EXTENSIONS = .sh
224225
@VALGRIND_CHECK_RULES@

lib/persist-state.c

-55
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,10 @@
3535
#include <string.h>
3636
#include <signal.h>
3737

38-
typedef struct _PersistFileHeader
39-
{
40-
union
41-
{
42-
struct
43-
{
44-
/* should contain SLP4, everything is Big-Endian */
45-
46-
/* 64 bytes for file header */
47-
gchar magic[4];
48-
/* should be zero, any non-zero value is not supported and causes the state to be dropped */
49-
guint32 flags;
50-
/* number of name-value keys in the file */
51-
guint32 key_count;
52-
/* space reserved for additional information in the header */
53-
gchar __reserved1[52];
54-
/* initial key store where the first couple of NV keys are stored, sized to align the header to 4k boundary */
55-
gchar initial_key_store[4032];
56-
};
57-
gchar __padding[4096];
58-
};
59-
} PersistFileHeader;
60-
6138
#define PERSIST_FILE_INITIAL_SIZE 16384
6239
#define PERSIST_STATE_KEY_BLOCK_SIZE 4096
6340
#define PERSIST_FILE_WATERMARK 4096
6441

65-
typedef struct
66-
{
67-
void (*handler)(gpointer user_data);
68-
gpointer cookie;
69-
} PersistStateErrorHandler;
70-
7142
/*
7243
* The syslog-ng persistent state is a set of name-value pairs,
7344
* updated atomically during syslog-ng runtime. When syslog-ng
@@ -135,32 +106,6 @@ typedef struct
135106
* the file you need to check it whether it is inside the mapped file.
136107
*
137108
*/
138-
struct _PersistState
139-
{
140-
gint version;
141-
gchar *committed_filename;
142-
gchar *temp_filename;
143-
gint fd;
144-
gint mapped_counter;
145-
GMutex *mapped_lock;
146-
GCond *mapped_release_cond;
147-
guint32 current_size;
148-
guint32 current_ofs;
149-
gpointer current_map;
150-
PersistFileHeader *header;
151-
PersistStateErrorHandler error_handler;
152-
153-
/* keys being used */
154-
GHashTable *keys;
155-
PersistEntryHandle current_key_block;
156-
gint current_key_ofs;
157-
gint current_key_size;
158-
};
159-
160-
typedef struct _PersistEntry
161-
{
162-
PersistEntryHandle ofs;
163-
} PersistEntry;
164109

165110
/* everything is big-endian */
166111
typedef struct _PersistValueHeader

lib/persist-state.h

+58-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,66 @@
2727

2828
#include "syslog-ng.h"
2929

30-
typedef struct _PersistState PersistState;
30+
typedef struct _PersistFileHeader
31+
{
32+
union
33+
{
34+
struct
35+
{
36+
/* should contain SLP4, everything is Big-Endian */
37+
38+
/* 64 bytes for file header */
39+
gchar magic[4];
40+
/* should be zero, any non-zero value is not supported and causes the state to be dropped */
41+
guint32 flags;
42+
/* number of name-value keys in the file */
43+
guint32 key_count;
44+
/* space reserved for additional information in the header */
45+
gchar __reserved1[52];
46+
/* initial key store where the first couple of NV keys are stored, sized to align the header to 4k boundary */
47+
gchar initial_key_store[4032];
48+
};
49+
gchar __padding[4096];
50+
};
51+
} PersistFileHeader;
52+
3153
typedef guint32 PersistEntryHandle;
3254

55+
typedef struct
56+
{
57+
void (*handler)(gpointer user_data);
58+
gpointer cookie;
59+
} PersistStateErrorHandler;
60+
61+
typedef struct _PersistEntry
62+
{
63+
PersistEntryHandle ofs;
64+
} PersistEntry;
65+
66+
struct _PersistState
67+
{
68+
gint version;
69+
gchar *committed_filename;
70+
gchar *temp_filename;
71+
gint fd;
72+
gint mapped_counter;
73+
GMutex *mapped_lock;
74+
GCond *mapped_release_cond;
75+
guint32 current_size;
76+
guint32 current_ofs;
77+
gpointer current_map;
78+
PersistFileHeader *header;
79+
PersistStateErrorHandler error_handler;
80+
81+
/* keys being used */
82+
GHashTable *keys;
83+
PersistEntryHandle current_key_block;
84+
gint current_key_ofs;
85+
gint current_key_size;
86+
};
87+
88+
typedef struct _PersistState PersistState;
89+
3390
gpointer persist_state_map_entry(PersistState *self, PersistEntryHandle handle);
3491
void persist_state_unmap_entry(PersistState *self, PersistEntryHandle handle);
3592

persist-tool/CMakeLists.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
set(PERSIST-TOOL_SOURCE
2+
add.c
3+
dump.c
4+
generate.c
5+
persist-tool.c
6+
state.c
7+
)
8+
9+
add_executable(persist-tool ${PERSIST-TOOL_SOURCE})
10+
11+
include_directories(persist-tool
12+
${CORE_INCLUDE_DIRS}
13+
${CMAKE_CURRENT_SOURCE_DIR}
14+
${GLIB_INCLUDE_DIRS}
15+
${PROJECT_SOURCE_DIR}/lib
16+
${JSONC_INCLUDE_DIR}
17+
${PROJECT_SOURCE_DIR}/lib/eventlog/src
18+
)
19+
20+
target_link_libraries(persist-tool
21+
${GLIB_GMODULE_LIBRARIES}
22+
${GLIB_GTHREAD_LIBRARIES}
23+
${GLIB_LIBRARIES}
24+
${JSONC_LIBRARY}
25+
syslog-ng
26+
)
27+
28+
if (JSONC_INTERNAL)
29+
add_dependencies(persist-tool JSONC)
30+
endif()
31+
32+
install(TARGETS persist-tool RUNTIME DESTINATION bin)

persist-tool/Makefile.am

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pkginclude_HEADERS += \
2+
persist-tool/add.h \
3+
persist-tool/dump.h \
4+
persist-tool/generate.h \
5+
persist-tool/persist-tool.h \
6+
persist-tool/state.h
7+
8+
bin_PROGRAMS += persist-tool/persist-tool
9+
persist_tool_persist_tool_CPPFLAGS = \
10+
-I$(top_srcdir)/lib \
11+
-I$(top_srcdir)/lib/jsonc \
12+
$(JSON_CFLAGS)
13+
14+
persist_tool_persist_tool_SOURCES = \
15+
persist-tool/add.c \
16+
persist-tool/dump.c \
17+
persist-tool/generate.c \
18+
persist-tool/persist-tool.c \
19+
persist-tool/state.c
20+
21+
persist_tool_persist_tool_LDADD = \
22+
$(TEST_LDADD) \
23+
@GLIB_LIBS@ \
24+
@BASE_LIBS@ \
25+
@JSON_LIBS@
26+
27+
EXTRA_DIST += persist-tool/CMakeLists.txt

0 commit comments

Comments
 (0)