summaryrefslogtreecommitdiffstats
path: root/ctdb/common/ctdb_control.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctdb/common/ctdb_control.c')
-rw-r--r--ctdb/common/ctdb_control.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c
index 9d6a0469dc1..7a9327ec574 100644
--- a/ctdb/common/ctdb_control.c
+++ b/ctdb/common/ctdb_control.c
@@ -33,6 +33,14 @@ struct ctdb_control_state {
void *private_data;
};
+#define CHECK_CONTROL_DATA_SIZE(size) do { \
+ if (indata.dsize != size) { \
+ DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
+ opcode, indata.dsize, size)); \
+ return -1; \
+ } \
+ } while (0)
+
/*
process a control request
*/
@@ -43,15 +51,26 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
switch (opcode) {
case CTDB_CONTROL_PROCESS_EXISTS: {
pid_t pid;
- if (indata.dsize != sizeof(pid_t)) {
- DEBUG(0,(__location__ " Invalid data in CTDB_CONTROL_PROCESS_EXISTS\n"));
- return -1;
- }
+ CHECK_CONTROL_DATA_SIZE(sizeof(pid));
pid = *(pid_t *)indata.dptr;
return kill(pid, 0);
}
+ case CTDB_CONTROL_SET_DEBUG: {
+ CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+ LogLevel = *(uint32_t *)indata.dptr;
+ return 0;
+ }
+
+ case CTDB_CONTROL_GET_DEBUG: {
+ CHECK_CONTROL_DATA_SIZE(0);
+ outdata->dptr = (uint8_t *)&LogLevel;
+ outdata->dsize = sizeof(LogLevel);
+ return 0;
+ }
+
case CTDB_CONTROL_STATUS: {
+ CHECK_CONTROL_DATA_SIZE(0);
outdata->dptr = (uint8_t *)&ctdb->status;
outdata->dsize = sizeof(ctdb->status);
return 0;
@@ -59,7 +78,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
case CTDB_CONTROL_GETVNNMAP: {
uint32_t i, len;
-
+ CHECK_CONTROL_DATA_SIZE(0);
len = 2+ctdb->vnn_map->size;
outdata->dsize = 4*len;
outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len);
@@ -95,22 +114,21 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
}
case CTDB_CONTROL_CONFIG: {
+ CHECK_CONTROL_DATA_SIZE(0);
outdata->dptr = (uint8_t *)ctdb;
outdata->dsize = sizeof(*ctdb);
return 0;
}
case CTDB_CONTROL_PING:
+ CHECK_CONTROL_DATA_SIZE(0);
return 0;
case CTDB_CONTROL_GETDBPATH: {
uint32_t db_id;
struct ctdb_db_context *ctdb_db;
- if (indata.dsize != sizeof(uint32_t)) {
- DEBUG(0,(__location__ " Invalid data in CTDB_CONTROL_GETDBPATH\n"));
- return -1;
- }
+ CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
db_id = *(uint32_t *)indata.dptr;
ctdb_db = find_ctdb_db(ctdb, db_id);
if (ctdb_db == NULL) return -1;