From: Baptiste Daroussin Date: Thu, 9 Dec 2021 09:18:58 +0000 (+0100) Subject: locking: remove lock wrappers, lock is now handled an open() time X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ced27f7a755d00a7e3f10cbf53bb92b81a1758b1;p=thirdparty%2Fmlmmj.git locking: remove lock wrappers, lock is now handled an open() time --- diff --git a/include/mylocking.h b/include/mylocking.h deleted file mode 100644 index 6027438e..00000000 --- a/include/mylocking.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2002, 2003 Mads Martin Joergensen - * - * $Id$ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef MYLOCKING_H -#define MYLOCKING_H - -int myexcllock(int fd); -int myunlock(int fd); - -#endif /* MYLOCKING_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 3d4c474a..12a5953a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,17 +13,17 @@ EXTRA_DIST = mlmmj-make-ml mlmmj_send_SOURCES = mlmmj.c mlmmj-send.c mail-functions.c itoa.c chomp.c \ incindexfile.c checkwait_smtpreply.c utils.c \ - mylocking.c init_sockfd.c strgen.c random-int.c \ + init_sockfd.c strgen.c random-int.c \ print-version.c log_error.c mygetline.c memory.c \ controls.c getaddrsfromfd.c readn.c send_mails.c mlmmj_receive_SOURCES = mlmmj-receive.c random-int.c strgen.c \ print-version.c log_error.c dumpfd2fd.c memory.c \ - log_oper.c mylocking.c readn.c + log_oper.c readn.c mlmmj_process_SOURCES = mlmmj.c mlmmj-process.c find_email_adr.c \ incindexfile.c itoa.c chomp.c utils.c \ - mylocking.c listcontrol.c random-int.c strgen.c \ + listcontrol.c random-int.c strgen.c \ print-version.c send_help.c prepstdreply.c \ do_all_the_voodoo_here.c mygetline.c gethdrline.c \ log_error.c controls.c dumpfd2fd.c \ @@ -32,14 +32,14 @@ mlmmj_process_SOURCES = mlmmj.c mlmmj-process.c find_email_adr.c \ send_mails.c checkwait_smtpreply.c \ mail-functions.c init_sockfd.c -mlmmj_sub_SOURCES = mlmmj.c mlmmj-sub.c mylocking.c \ +mlmmj_sub_SOURCES = mlmmj.c mlmmj-sub.c \ chomp.c random-int.c strgen.c \ subscriberfuncs.c print-version.c \ log_error.c mygetline.c prepstdreply.c memory.c \ controls.c readn.c utils.c unistr.c send_mails.c checkwait_smtpreply.c \ mail-functions.c init_sockfd.c -mlmmj_unsub_SOURCES = mlmmj.c mlmmj-unsub.c mylocking.c \ +mlmmj_unsub_SOURCES = mlmmj.c mlmmj-unsub.c \ chomp.c subscriberfuncs.c random-int.c \ strgen.c print-version.c log_error.c mygetline.c \ prepstdreply.c memory.c controls.c readn.c utils.c \ @@ -55,7 +55,7 @@ mlmmj_bounce_SOURCES = mlmmj.c mlmmj-bounce.c print-version.c log_error.c \ mlmmj_maintd_SOURCES = mlmmj.c mlmmj-maintd.c print-version.c log_error.c mygetline.c \ strgen.c random-int.c chomp.c memory.c \ send_digest.c dumpfd2fd.c utils.c \ - mylocking.c log_oper.c readn.c \ + log_oper.c readn.c \ prepstdreply.c gethdrline.c unistr.c controls.c \ send_mails.c checkwait_smtpreply.c \ mail-functions.c init_sockfd.c subscriberfuncs.c diff --git a/src/incindexfile.c b/src/incindexfile.c index 855c34b6..6ce28b0d 100644 --- a/src/incindexfile.c +++ b/src/incindexfile.c @@ -34,7 +34,6 @@ #include #include "wrappers.h" -#include "mylocking.h" #include "incindexfile.h" #include "itoa.h" #include "log_error.h" diff --git a/src/log_oper.c b/src/log_oper.c index 359d969d..9bdbc0d9 100644 --- a/src/log_oper.c +++ b/src/log_oper.c @@ -36,7 +36,6 @@ #include "log_error.h" #include "log_oper.h" #include "strgen.h" -#include "mylocking.h" #include "wrappers.h" #include "memory.h" @@ -66,7 +65,7 @@ int log_oper(const char *prefix, const char *basename, const char *fmt, ...) myfree(tmp); } - fd = open(logfilename, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR); + fd = open(logfilename, O_RDWR|O_CREAT|O_APPEND|O_EXLOCK, S_IRUSR|S_IWUSR); if(fd < 0) { log_error(LOG_ARGS, "Could not open %s", logfilename); myfree(logfilename); @@ -78,12 +77,6 @@ int log_oper(const char *prefix, const char *basename, const char *fmt, ...) else ct[24] = '\0'; - if(myexcllock(fd) < 0) { - log_error(LOG_ARGS, "Could not lock %s", logfilename); - myfree(logfilename); - return -1; - } - va_start(ap, fmt); i = vsnprintf(log_msg, sizeof(log_msg), fmt, ap); if(i < 0) { diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index 9c10e776..9efb08c3 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -43,7 +43,6 @@ #include "memory.h" #include "controls.h" #include "send_digest.h" -#include "mylocking.h" #include "log_oper.h" #include "utils.h" #include "send_mails.h" @@ -177,15 +176,10 @@ int discardmail(const char *old, const char *new, time_t age) time_t t; int fd, ret = 0; - fd = open(old, O_RDWR); + fd = open(old, O_RDWR|O_EXLOCK); if(fd < 0) return 0; - if(myexcllock(fd) < 0) { - close(fd); - return 0; - } - stat(old, &st); t = time(NULL); diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index 42f1d606..2ed84112 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -56,7 +56,6 @@ #include "wrappers.h" #include "memory.h" #include "controls.h" -#include "mylocking.h" #include "getaddrsfromfd.h" #include "utils.h" #include "send_mails.h" diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index d6b7ded8..8d4ac8d3 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -38,7 +38,6 @@ #include "mlmmj.h" #include "mlmmj-sub.h" -#include "mylocking.h" #include "wrappers.h" #include "strgen.h" #include "subscriberfuncs.h" diff --git a/src/mylocking.c b/src/mylocking.c deleted file mode 100644 index 0501c7e5..00000000 --- a/src/mylocking.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2002, 2003, 2005 Mads Martin Joergensen - * - * $Id$ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include - -#include "mylocking.h" - -int myexcllock(int fd) -{ - int excllock; - struct flock locktype; - - locktype.l_type = F_WRLCK; - locktype.l_whence = SEEK_SET; - locktype.l_start = 0; - locktype.l_len = 0; - do { - excllock = fcntl(fd, F_SETLKW, &locktype); - } while(excllock < 0 && errno == EINTR); - - return excllock; -} - -int myunlock(int fd) -{ - int unlock; - struct flock locktype; - - locktype.l_type = F_UNLCK; - locktype.l_whence = SEEK_SET; - locktype.l_start = 0; - locktype.l_len = 0; - do { - unlock = fcntl(fd, F_SETLKW, &locktype); - } while(unlock < 0 && errno == EINTR); - - return unlock; -}