From a255eea7ebe772851b38135146084af52b914c05 Mon Sep 17 00:00:00 2001 From: Stefan de Konink Date: Sat, 9 Aug 2008 20:43:55 +0200 Subject: [PATCH] Still locking to do --- experiment5.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/experiment5.c b/experiment5.c index 927e366..39eb9cb 100644 --- a/experiment5.c +++ b/experiment5.c @@ -2,6 +2,7 @@ #include #include #include +#include typedef struct line LINE; @@ -174,9 +175,6 @@ static char * print_ip(unsigned long int ipaddress) { static int print_forget(char *path) { FILE *fd = fopen(path, "w+"); - if (fd) - flock(fd, LOCK_EX); - LINE *step = first; while (step) { LINE *this = step; @@ -195,10 +193,8 @@ static int print_forget(char *path) { free(this); } - if (fd) { - flock(fd, LOCK_UN); + if (fd) fclose(fd); - } return 0; } @@ -273,12 +269,10 @@ static char * loader(char *cabinet) { if ((fd = fopen(pad, "r")) != NULL) { char line[128]; - flock(fd, LOCK_EX); while (!feof(fd)) { if (fgets(line, 128, fd) > 0) add_line(line); } - flock(fd, LOCK_UN); fclose(fd); } @@ -286,6 +280,7 @@ static char * loader(char *cabinet) { } /* Exported functions */ +/* TODO: implement better locking */ int removeOldMac(char *cabinet, char *mac) { char *pad = loader(cabinet); -- 2.11.4.GIT