From a6c531e78ae7d157163167a53d693958ff683a22 Mon Sep 17 00:00:00 2001 From: Bandie Date: Wed, 21 Mar 2018 22:46:45 +0100 Subject: [PATCH] Stopping unnecessary file writing --- Makefile | 4 +++- src/grub2-se-verifyserv.c | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index bf975d4..5086c3e 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,12 @@ install: chown root:root /usr/local/sbin/grub2-se-verifyserv chmod 740 /usr/local/sbin/grub2-se-verifyserv @printf "Done.\n" - @printf "You may want to enable and start the service: \"systemctl enable grub2-se-verifyserv ; systemctl start grub2-se-verifyserv\"\n" @printf "The file will be called /verified" + @printf "You may want to enable and start the service: \"systemctl enable grub2-se-verifyserv ; systemctl start grub2-se-verifyserv\"\n" + @printf "The file will be called /verified\n" uninstall: rm /usr/sbin/local/grub2-se-verifyserv + rm /etc/systemd/system/grub2-se-verifyserv.service @printf "Done.\n" clean: diff --git a/src/grub2-se-verifyserv.c b/src/grub2-se-verifyserv.c index 6869197..ae668fa 100644 --- a/src/grub2-se-verifyserv.c +++ b/src/grub2-se-verifyserv.c @@ -104,12 +104,14 @@ int main(int argc, char *argv[]){ if(WEXITSTATUS(statval) == STATUS_OK){ // If exit is STATUS_OK, write file with nothing in it - FILE *f = fopen(VRFFILE, "w"); - if(f == NULL){ - printf("ERROR opening file"); - return 1; + if(access(VRFFILE, F_OK) == -1){ + FILE *f = fopen(VRFFILE, "w"); + if(f == NULL){ + printf("ERROR opening file"); + return 1; + } + fclose(f); } - fclose(f); } else // If exit != 0