From 82b99e5f25142bf472062c15435b6ad960d39bc3 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Sat, 8 Oct 2011 21:18:39 +0300 Subject: [PATCH] smackctl: initial restart Implemented initial restart functionality to smackctl. --- tests/smackctl.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/smackctl.c b/tests/smackctl.c index 4534fb6..134d72c 100644 --- a/tests/smackctl.c +++ b/tests/smackctl.c @@ -30,6 +30,8 @@ #include #include +static int restart(void); +static int stop(void); static int apply_rules(const char *path, int flags); int main(int argc, char **argv) @@ -39,14 +41,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (!strcmp(argv[1], "start")) { - if (apply_rules("/etc/smack/accesses", 0)) + if (!strcmp(argv[1], "start") || !strncmp(argv[1], "restart")) { + if (restart()) return EXIT_FAILURE; } else if (!strcmp(argv[1], "stop")) { - if (apply_rules("/smack/load", SMACK_RULE_SET_APPLY_CLEAR)) + if (stop()) return EXIT_FAILURE; - } else if (!strcmp(argv[1], "restart")) { - printf("restart\n"); } else if (!strcmp(argv[1], "status")) { printf("status\n"); } else { @@ -57,6 +57,25 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } +static int restart(void) +{ + if (stop()) + return -1; + + if (apply_rules("/etc/smack/accesses", 0)) + return -1; + + return 0; +} + +static int stop(void) +{ + if (apply_rules("/smack/load", SMACK_RULE_SET_APPLY_CLEAR)) + return -1; + + return 0; +} + static int apply_rules(const char *path, int flags) { SmackRuleSet rules = NULL; -- 2.7.4