Skip to content

Commit

Permalink
capmon: move mode variable into capmon struct
Browse files Browse the repository at this point in the history
Signed-off-by: Casper Andersson <[email protected]>
  • Loading branch information
cappe987 committed Aug 18, 2022
1 parent a3717aa commit f8c4ebb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 8 additions & 0 deletions include/libcapmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ struct process_stats {
DECLARE_BITMAP(capabilities, CAP_LAST_CAP+1);
};

enum run_mode {
RUNMODE_NONE,
RUNMODE_MONITOR,
RUNMODE_ENA_BG,
RUNMODE_DIS_BG
};

struct capmon {
LIST_HEAD(available_probes, probe) available_probes;
LIST_HEAD(selected_probes, probe) selected_probes;
LIST_HEAD(filters, filter) filters;
LIST_HEAD(stats, process_stats) process_stats;
enum summary_mode summary;
bool in_background;
enum run_mode run_mode;
//struct available_probes *headp2;
//struct selected_probes *headp1;
};
Expand Down
26 changes: 9 additions & 17 deletions src/capmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ void usage(void)
stderr);
}

enum run_mode {
RUNMODE_NONE,
RUNMODE_MONITOR,
RUNMODE_ENA_BG,
RUNMODE_DIS_BG
};

int parse_args(struct capmon *cm, enum run_mode *mode, int argc, char **argv)
int parse_args(struct capmon *cm, int argc, char **argv)
{
int ena_bg = 0, dis_bg = 0, err = 0;
bool cap_all = false;
Expand All @@ -80,11 +73,11 @@ int parse_args(struct capmon *cm, enum run_mode *mode, int argc, char **argv)
switch (ch) {
case 'v':
VERSION();
*mode = RUNMODE_NONE;
cm->run_mode = RUNMODE_NONE;
goto out;
case 'h':
usage();
*mode = RUNMODE_NONE;
cm->run_mode = RUNMODE_NONE;
goto out;
case 'a':
cap_all = true;
Expand Down Expand Up @@ -131,11 +124,11 @@ int parse_args(struct capmon *cm, enum run_mode *mode, int argc, char **argv)
err = EINVAL;
goto out;
} else if (ena_bg) {
*mode = RUNMODE_ENA_BG;
cm->run_mode = RUNMODE_ENA_BG;
} else if (dis_bg) {
*mode = RUNMODE_DIS_BG;
cm->run_mode = RUNMODE_DIS_BG;
} else {
*mode = RUNMODE_MONITOR;
cm->run_mode = RUNMODE_MONITOR;
}

err = kprobes_can_read_write();
Expand All @@ -158,19 +151,18 @@ int parse_args(struct capmon *cm, enum run_mode *mode, int argc, char **argv)
int main(int argc, char **argv)
{
struct capmon capmon;
enum run_mode mode;
int err = 0;

capmon_init(&capmon);

err = parse_args(&capmon, &mode, argc, argv);
err = parse_args(&capmon, argc, argv);
if (err)
goto out;

/*capmon_print(&capmon);*/
capmon_print(&capmon);

/* TODO: proper error handling for background enable? */
switch (mode) {
switch (capmon.run_mode) {
case RUNMODE_NONE:
goto out;
case RUNMODE_MONITOR:
Expand Down
1 change: 1 addition & 0 deletions src/libcapmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void capmon_print(struct capmon *cm)
{
printf("--- CAPMON ---\n");
printf("Summary mode: %d\n", cm->summary);
printf("Run mode: %d\n", cm->run_mode);
print_probes(cm);
print_filters(cm);

Expand Down

0 comments on commit f8c4ebb

Please sign in to comment.