aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-02-22 15:52:54 +0100
committerAlice Frosi <afrosi@redhat.com>2023-02-22 16:15:03 +0100
commit977ffec509a95efeca2b7c508912d5d1df7cd677 (patch)
tree3d5c169951b05008415d5eafdf263c51e8cf164d
parentba9623361f74be93674f2862903a39ae6d48e96e (diff)
downloadseitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar.gz
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar.bz2
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar.lz
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar.xz
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.tar.zst
seitan-977ffec509a95efeca2b7c508912d5d1df7cd677.zip
Rename actions to operations
Replace all the action related names to operations to make them more generic.
-rw-r--r--gluten.h44
-rw-r--r--operations.c (renamed from actions.c)46
-rw-r--r--operations.h (renamed from actions.h)4
-rw-r--r--tests/unit/Makefile18
-rw-r--r--tests/unit/test_op_call.c (renamed from tests/unit/test_action_call.c)26
-rw-r--r--tests/unit/test_operations.c (renamed from tests/unit/test_actions.c)96
6 files changed, 117 insertions, 117 deletions
diff --git a/gluten.h b/gluten.h
index e027923..1b6c3d1 100644
--- a/gluten.h
+++ b/gluten.h
@@ -36,20 +36,20 @@ enum ns_type {
};
/*
- * struct act_context - Description of the context where the call needs to be executed
+ * struct op_context - Description of the context where the call needs to be executed
* @ns: Descrption of the each namespace where the call needs to be executed
*/
-struct act_context {
+struct op_context {
struct ns_spec ns[sizeof(enum ns_type)];
};
-enum action_type {
- A_CALL,
- A_BLOCK,
- A_CONT,
- A_INJECT,
- A_INJECT_A,
- A_RETURN,
+enum op_type {
+ OP_CALL,
+ OP_BLOCK,
+ OP_CONT,
+ OP_INJECT,
+ OP_INJECT_A,
+ OP_RETURN,
};
enum value_type {
@@ -57,23 +57,23 @@ enum value_type {
REFERENCE,
};
-struct act_call {
+struct op_call {
long nr;
bool has_ret;
void *args[6];
- struct act_context context;
+ struct op_context context;
uint16_t ret_off;
};
-struct act_block {
+struct op_block {
int32_t error;
};
-struct act_continue {
+struct op_continue {
bool cont;
};
-struct act_return {
+struct op_return {
enum value_type type;
union {
int64_t value;
@@ -89,19 +89,19 @@ struct fd_type {
};
};
-struct act_inject {
+struct op_inject {
struct fd_type newfd;
struct fd_type oldfd;
};
-struct action {
- enum action_type type;
+struct op {
+ enum op_type type;
union {
- struct act_call call;
- struct act_block block;
- struct act_continue cont;
- struct act_return ret;
- struct act_inject inj;
+ struct op_call call;
+ struct op_block block;
+ struct op_continue cont;
+ struct op_return ret;
+ struct op_inject inj;
};
};
#endif /* GLUTEN_H */
diff --git a/actions.c b/operations.c
index bfdd5b1..82b99a8 100644
--- a/actions.c
+++ b/operations.c
@@ -15,7 +15,7 @@
#include <errno.h>
#include "gluten.h"
-#include "actions.h"
+#include "operations.h"
static bool is_cookie_valid(int notifyFd, uint64_t id)
{
@@ -87,7 +87,7 @@ static void proc_ns_name(unsigned i, char *ns)
}
}
-static int set_namespaces(const struct act_call *a, int tpid)
+static int set_namespaces(const struct op_call *a, int tpid)
{
char path[PATH_MAX + 1];
char ns_name[PATH_MAX / 2];
@@ -131,7 +131,7 @@ static int set_namespaces(const struct act_call *a, int tpid)
static int execute_syscall(void *args)
{
struct arg_clone *a = (struct arg_clone *)args;
- const struct act_call *c = a->args;
+ const struct op_call *c = a->args;
if (set_namespaces(a->args, a->pid) < 0) {
exit(EXIT_FAILURE);
@@ -166,7 +166,7 @@ int do_call(struct arg_clone *c)
return 0;
}
-static void set_inject_fields(uint64_t id, void *data, const struct action *a,
+static void set_inject_fields(uint64_t id, void *data, const struct op *a,
struct seccomp_notif_addfd *resp)
{
const struct fd_type *new = &(a->inj).newfd;
@@ -187,7 +187,7 @@ static void set_inject_fields(uint64_t id, void *data, const struct action *a,
resp->newfd_flags = 0;
}
-int do_actions(void *data, struct action actions[], unsigned int n_actions,
+int do_operations(void *data, struct op operations[], unsigned int n_operations,
int pid, int notifyfd, uint64_t id)
{
struct seccomp_notif_addfd resp_fd;
@@ -195,13 +195,13 @@ int do_actions(void *data, struct action actions[], unsigned int n_actions,
struct arg_clone c;
unsigned int i;
- for (i = 0; i < n_actions; i++) {
- switch (actions[i].type) {
- case A_CALL:
+ for (i = 0; i < n_operations; i++) {
+ switch (operations[i].type) {
+ case OP_CALL:
resp.id = id;
resp.val = 0;
resp.flags = 0;
- c.args = &actions[i].call;
+ c.args = &operations[i].call;
c.pid = pid;
if (do_call(&c) == -1) {
resp.error = -1;
@@ -217,37 +217,37 @@ int do_actions(void *data, struct action actions[], unsigned int n_actions,
* The result of the call needs to be save as
* reference
*/
- if (actions[i].call.has_ret) {
+ if (operations[i].call.has_ret) {
memcpy((uint16_t *)data +
- actions[i].call.ret_off,
+ operations[i].call.ret_off,
&c.ret, sizeof(c.ret));
}
break;
- case A_BLOCK:
+ case OP_BLOCK:
resp.id = id;
resp.val = 0;
resp.flags = 0;
- resp.error = actions[i].block.error;
+ resp.error = operations[i].block.error;
if (send_target(&resp, notifyfd) == -1)
return -1;
break;
- case A_RETURN:
+ case OP_RETURN:
resp.id = id;
resp.flags = 0;
resp.error = 0;
- if (actions[i].ret.type == IMMEDIATE)
- resp.val = actions[i].ret.value;
+ if (operations[i].ret.type == IMMEDIATE)
+ resp.val = operations[i].ret.value;
else
memcpy(&resp.val,
(uint16_t *)data +
- actions[i].ret.value_off,
+ operations[i].ret.value_off,
sizeof(resp.val));
if (send_target(&resp, notifyfd) == -1)
return -1;
break;
- case A_CONT:
+ case OP_CONT:
resp.id = id;
resp.flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;
resp.error = 0;
@@ -255,19 +255,19 @@ int do_actions(void *data, struct action actions[], unsigned int n_actions,
if (send_target(&resp, notifyfd) == -1)
return -1;
break;
- case A_INJECT_A:
- set_inject_fields(id, data, &actions[i], &resp_fd);
+ case OP_INJECT_A:
+ set_inject_fields(id, data, &operations[i], &resp_fd);
resp_fd.flags |= SECCOMP_ADDFD_FLAG_SEND;
if (send_inject_target(&resp_fd, notifyfd) == -1)
return -1;
break;
- case A_INJECT:
- set_inject_fields(id, data, &actions[i], &resp_fd);
+ case OP_INJECT:
+ set_inject_fields(id, data, &operations[i], &resp_fd);
if (send_inject_target(&resp_fd, notifyfd) == -1)
return -1;
break;
default:
- fprintf(stderr, "unknow action %d \n", actions[i].type);
+ fprintf(stderr, "unknow operation %d \n", operations[i].type);
}
}
return 0;
diff --git a/actions.h b/operations.h
index c3376b7..aeb09d5 100644
--- a/actions.h
+++ b/operations.h
@@ -7,13 +7,13 @@
#define NS_NUM (sizeof(enum ns_type))
struct arg_clone {
- const struct act_call *args;
+ const struct op_call *args;
pid_t pid;
long ret;
int err;
};
int do_call(struct arg_clone *c);
-int do_actions(void *data, struct action actions[], unsigned int n_actions,
+int do_operations(void *data, struct op operations[], unsigned int n_operations,
int tpid, int notifyfd, uint64_t id);
#endif /* ACTIONS_H */
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
index 87f64c4..3ae4fd7 100644
--- a/tests/unit/Makefile
+++ b/tests/unit/Makefile
@@ -1,16 +1,16 @@
CFLAGS += -lcheck
-test: test-filter test-actions test-action-call
+test: test-filter test-operations test-op-call
test-filter: test-filter.c
$(CC) $(CFLAGS) -o test-filter ../../filter.c ../../disasm.c test-filter.c
./test-filter
-test-action-call: test_action_call.c ../../actions.c ../../actions.h ../../gluten.h
- $(CC) $(CFLAGS) -o test-action-call ../../actions.c test_action_call.c
- ./test-action-call
+test-op-call: test_op_call.c ../../operations.c ../../operations.h ../../gluten.h
+ $(CC) $(CFLAGS) -o test-op-call ../../operations.c test_op_call.c
+ ./test-op-call
-test-actions: test_actions.c ../../actions.c ../../actions.h ../../common.h
- $(CC) $(CFLAGS) -o test-actions \
- ../../common.c ../../actions.c \
- test_actions.c
- ./test-actions
+test-operations: test_operations.c ../../operations.c ../../operations.h ../../common.h
+ $(CC) $(CFLAGS) -o test-operations \
+ ../../common.c ../../operations.c \
+ test_operations.c
+ ./test-operations
diff --git a/tests/unit/test_action_call.c b/tests/unit/test_op_call.c
index 8621174..6ffef99 100644
--- a/tests/unit/test_action_call.c
+++ b/tests/unit/test_op_call.c
@@ -13,7 +13,7 @@
#include <check.h>
#include "../../gluten.h"
-#include "../../actions.h"
+#include "../../operations.h"
struct args_write_file {
char *file;
@@ -102,7 +102,7 @@ START_TEST(test_with_open_read_ns)
char test_file[] = "/tmp/test.txt";
char t[PATH_MAX] = "Hello Test";
struct args_write_file args = { test_file, t, sizeof(t) };
- struct act_call call;
+ struct op_call call;
int flags = O_RDWR;
struct arg_clone c;
char buf[PATH_MAX];
@@ -142,7 +142,7 @@ START_TEST(test_with_read)
{
char test_file[] = "/tmp/test.txt";
char t[PATH_MAX] = "Hello Test";
- struct act_call call;
+ struct op_call call;
struct arg_clone c;
char buf[PATH_MAX];
unsigned i;
@@ -168,7 +168,7 @@ END_TEST
START_TEST(test_with_getppid)
{
- struct act_call call;
+ struct op_call call;
struct arg_clone c;
unsigned i;
long pid = (long)getpid();
@@ -185,19 +185,19 @@ START_TEST(test_with_getppid)
}
END_TEST
-Suite *action_call_suite(void)
+Suite *op_call_suite(void)
{
Suite *s;
- TCase *tactions;
+ TCase *tops;
- s = suite_create("Perform actions call");
- tactions = tcase_create("action calls");
+ s = suite_create("Perform ops call");
+ tops = tcase_create("op calls");
- tcase_add_test(tactions, test_with_getppid);
- tcase_add_test(tactions, test_with_read);
- tcase_add_test(tactions, test_with_open_read_ns);
+ tcase_add_test(tops, test_with_getppid);
+ tcase_add_test(tops, test_with_read);
+ tcase_add_test(tops, test_with_open_read_ns);
- suite_add_tcase(s, tactions);
+ suite_add_tcase(s, tops);
return s;
}
@@ -208,7 +208,7 @@ int main(void)
Suite *s;
SRunner *runner;
- s = action_call_suite();
+ s = op_call_suite();
runner = srunner_create(s);
srunner_run_all(runner, CK_VERBOSE);
diff --git a/tests/unit/test_actions.c b/tests/unit/test_operations.c
index 8893722..6c5952f 100644
--- a/tests/unit/test_actions.c
+++ b/tests/unit/test_operations.c
@@ -19,7 +19,7 @@
#include <check.h>
#include "../../gluten.h"
-#include "../../actions.h"
+#include "../../operations.h"
#include "../../common.h"
struct args_target {
@@ -209,11 +209,11 @@ void setup_fd()
START_TEST(test_act_continue)
{
- struct action actions[] = {
- { .type = A_CONT },
+ struct op operations[] = {
+ { .type = OP_CONT },
};
- int ret = do_actions(NULL, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(NULL, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
ck_assert_msg(ret == 0, strerror(errno));
ck_assert_int_eq(at->err, 0);
@@ -222,14 +222,14 @@ END_TEST
START_TEST(test_act_block)
{
- struct action actions[] = {
+ struct op operations[] = {
{
- .type = A_BLOCK,
+ .type = OP_BLOCK,
.block = { .error = -1 },
},
};
- int ret = do_actions(NULL, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(NULL, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_result(-1, 0, false);
@@ -238,14 +238,14 @@ END_TEST
START_TEST(test_act_return)
{
- struct action actions[] = {
+ struct op operations[] = {
{
- .type = A_RETURN,
+ .type = OP_RETURN,
.ret = { .type = IMMEDIATE, .value = 1 },
},
};
- int ret = do_actions(NULL, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(NULL, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_result(1, 0, false);
@@ -256,16 +256,16 @@ START_TEST(test_act_return_ref)
{
int64_t v = 2;
uint16_t offset = 4;
- struct action actions[] = {
+ struct op operations[] = {
{
- .type = A_RETURN,
+ .type = OP_RETURN,
.ret = { .type = REFERENCE, .value_off = offset },
},
};
memcpy((uint16_t *)&tmp_data + offset, &v, sizeof(v));
- int ret = do_actions(&tmp_data, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(&tmp_data, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_result(v, 0, false);
@@ -274,15 +274,15 @@ END_TEST
START_TEST(test_act_call)
{
- struct action actions[] = {
+ struct op operations[] = {
{
- .type = A_CALL,
+ .type = OP_CALL,
.call = { .nr = __NR_getppid, .has_ret = false },
},
- { .type = A_CONT },
+ { .type = OP_CONT },
};
- int ret = do_actions(NULL, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(NULL, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_result(1, 0, true);
@@ -291,17 +291,17 @@ END_TEST
START_TEST(test_act_call_ret)
{
- struct action actions[] = {
+ struct op operations[] = {
{
- .type = A_CALL,
+ .type = OP_CALL,
.call = { .nr = __NR_getppid,
.has_ret = true,
.ret_off = 2 },
},
- { .type = A_CONT },
+ { .type = OP_CONT },
};
- int ret = do_actions(&tmp_data, actions,
- sizeof(actions) / sizeof(actions[0]), -1, notifyfd,
+ int ret = do_operations(&tmp_data, operations,
+ sizeof(operations) / sizeof(operations[0]), -1, notifyfd,
req.id);
long r;
ck_assert_msg(ret == 0, strerror(errno));
@@ -311,7 +311,7 @@ START_TEST(test_act_call_ret)
}
END_TEST
-static void test_inject(struct action actions[], int n, bool reference)
+static void test_inject(struct op operations[], int n, bool reference)
{
uint16_t new_off = 2, old_off = 4;
int fd_inj;
@@ -326,58 +326,58 @@ static void test_inject(struct action actions[], int n, bool reference)
memcpy((uint16_t *)&tmp_data + old_off, &test_fd,
sizeof(test_fd));
- actions[0].inj.newfd.fd_off = new_off;
- actions[0].inj.newfd.type = REFERENCE;
- actions[0].inj.oldfd.fd_off = old_off;
- actions[0].inj.oldfd.type = REFERENCE;
+ operations[0].inj.newfd.fd_off = new_off;
+ operations[0].inj.newfd.type = REFERENCE;
+ operations[0].inj.oldfd.fd_off = old_off;
+ operations[0].inj.oldfd.type = REFERENCE;
} else {
- actions[0].inj.newfd.fd = fd_inj;
- actions[0].inj.newfd.type = IMMEDIATE;
- actions[0].inj.oldfd.fd = test_fd;
- actions[0].inj.oldfd.type = IMMEDIATE;
+ operations[0].inj.newfd.fd = fd_inj;
+ operations[0].inj.newfd.type = IMMEDIATE;
+ operations[0].inj.oldfd.fd = test_fd;
+ operations[0].inj.oldfd.type = IMMEDIATE;
}
- ret = do_actions(&tmp_data, actions, n, -1, notifyfd, req.id);
+ ret = do_operations(&tmp_data, operations, n, -1, notifyfd, req.id);
ck_assert_msg(ret == 0, strerror(errno));
check_target_fd(pid, test_fd);
}
START_TEST(test_act_inject_a)
{
- struct action actions[] = { { .type = A_INJECT_A } };
- test_inject(actions, sizeof(actions) / sizeof(actions[0]), false);
+ struct op operations[] = { { .type = OP_INJECT_A } };
+ test_inject(operations, sizeof(operations) / sizeof(operations[0]), false);
}
END_TEST
START_TEST(test_act_inject_a_ref)
{
- struct action actions[] = { { .type = A_INJECT_A } };
- test_inject(actions, sizeof(actions) / sizeof(actions[0]), true);
+ struct op operations[] = { { .type = OP_INJECT_A } };
+ test_inject(operations, sizeof(operations) / sizeof(operations[0]), true);
}
END_TEST
START_TEST(test_act_inject)
{
- struct action actions[] = { { .type = A_INJECT } };
- test_inject(actions, sizeof(actions) / sizeof(actions[0]), false);
+ struct op operations[] = { { .type = OP_INJECT } };
+ test_inject(operations, sizeof(operations) / sizeof(operations[0]), false);
}
END_TEST
START_TEST(test_act_inject_ref)
{
- struct action actions[] = { { .type = A_INJECT } };
- test_inject(actions, sizeof(actions) / sizeof(actions[0]), true);
+ struct op operations[] = { { .type = OP_INJECT } };
+ test_inject(operations, sizeof(operations) / sizeof(operations[0]), true);
}
END_TEST
-Suite *action_call_suite(void)
+Suite *op_call_suite(void)
{
Suite *s;
int timeout = 30;
TCase *cont, *block, *ret, *call;
TCase *inject, *inject_a;
- s = suite_create("Perform actions");
+ s = suite_create("Perform operations");
cont = tcase_create("a_continue");
tcase_add_checked_fixture(cont, setup_without_fd, teardown);
@@ -428,7 +428,7 @@ int main(void)
Suite *s;
SRunner *runner;
- s = action_call_suite();
+ s = op_call_suite();
runner = srunner_create(s);
srunner_run_all(runner, CK_VERBOSE);