lockfile-progs-0.1.17build1/0000775000000000000000000000000012056456172012521 5ustar lockfile-progs-0.1.17build1/COPYING0000664000000000000000000004312706610505626013561 0ustar GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. lockfile-progs-0.1.17build1/Makefile0000664000000000000000000000376311624312243014160 0ustar LOADLIBES := -llockfile CFLAGS := -g -Wall -Wformat-security -Werror -O2 all: lockfile-create rm -rf bin mkdir -p bin cp -a lockfile-create bin cp -a lockfile-create bin/mail-lock cd bin && ln lockfile-create lockfile-remove cd bin && ln lockfile-create lockfile-touch cd bin && ln lockfile-create lockfile-check cd bin && ln mail-lock mail-unlock cd bin && ln mail-lock mail-touchlock mkdir -p man cp -a lockfile-progs.1 man (cd man && ln -sf lockfile-progs.1 lockfile-create.1 && \ ln -sf lockfile-progs.1 lockfile-remove.1 && \ ln -sf lockfile-progs.1 lockfile-touch.1 && \ ln -sf lockfile-progs.1 lockfile-check.1 && \ ln -sf lockfile-progs.1 mail-lock.1 && \ ln -sf lockfile-progs.1 mail-unlock.1 && \ ln -sf lockfile-progs.1 mail-touchlock.1) .PHONY: all lockfile-create: lockfile-progs.o ${CC} -o $@ ${LDFLAGS} $^ ${LOADLIBES} # These tests are quite insufficient, but perhaps better than nothing for now. check: all rm -rf check mkdir check bin/lockfile-create check/file bin/lockfile-touch --oneshot check/file bin/lockfile-check check/file bin/lockfile-remove check/file ! test -e check/file.lock bin/lockfile-create --lock-name check/file.lock bin/lockfile-touch --oneshot --lock-name check/file.lock bin/lockfile-check --lock-name check/file.lock bin/lockfile-remove --lock-name check/file.lock ! test -e check/file.lock bin/lockfile-create --use-pid --lock-name check/file.lock bin/lockfile-touch --oneshot --lock-name check/file.lock # PID shouldn't be the same, so this should fail. bin/lockfile-check --use-pid --lock-name check/file.lock bin/lockfile-remove --lock-name check/file.lock ! test -e check/file.lock bin/lockfile-create --use-pid --lock-name check/lockfile.no-pid .PHONY: check distclean: clean clean: rm -f lockfile-create lockfile-remove lockfile-touch lockfile-check rm -f mail-lock mail-unlock mail-touchlock rm -f *.o *~ rm -rf bin man rm -rf check .PHONY: clean distclean lockfile-progs-0.1.17build1/TODO0000664000000000000000000000007406773006051013206 0ustar -*-text-*- * Need to add support for the new L_PID option. lockfile-progs-0.1.17build1/debian/0000775000000000000000000000000013076470246013744 5ustar lockfile-progs-0.1.17build1/debian/changelog0000664000000000000000000001417113076470246015622 0ustar lockfile-progs (0.1.17build1) artful; urgency=medium * No-change rebuild to pick up -fPIE compiler default in static libraries -- Steve Langasek Fri, 21 Apr 2017 20:50:46 +0000 lockfile-progs (0.1.17) unstable; urgency=low * Add "p" to getopt_long()'s short options so the "-p" arg will actually work. As the manpage states, "-p" was intended to be the short argument for "--use-pid", but since "p" wasn't added to the getopt_long() optstring, it didn't actually work. Fix it. Thanks to Michael Deegan for the report. (Closes: #686057) * Fix cross-builds; use the cross-compiler when cross-building. Thanks to Colin Watson for the report and the patch. (Closes: #694842) -- Rob Browning Sat, 01 Dec 2012 12:16:09 -0600 lockfile-progs (0.1.16) unstable; urgency=low * Remove unused rc variable in chk() to silence gcc warning. Thanks to Matthias Klose for the report, and thanks to Aurelien Jarno for the 0.1.15.1 NMU. (Closes: #625384) * Use L_PID rather than L_PPID when appropriate. In cases where lockfile_create() and lockfile_check() were being called with L_PID, use L_PPID to capture the parent's PID. Capturing the PID of the lockfile-create or lockfile-check process made no sense. Thanks to Zrin Žiborski for the report, Larry Diegel for the patch, and Sebastian Siewior for the suggestion to update the documentation. (Closes: #626752) -- Rob Browning Sun, 21 Aug 2011 18:54:27 -0500 lockfile-progs (0.1.15) unstable; urgency=low * Add missing debhelper Build-Depends. -- Rob Browning Sun, 13 Jun 2010 02:21:19 -0500 lockfile-progs (0.1.14) unstable; urgency=low * Don't erroneously require -l for mail-related commands. Thanks to Andre Grueneberg . (closes: #563533) * Change --retry-count to --retry in the manpage. Thanks to Daniel Frank . (closes: #584779) * Change debian/rules to use "dh $@" approach. This also adds md5sums, fixing a wishlist bug. Thanks to Loïc Minier . (closes: #564798) -- Rob Browning Sat, 12 Jun 2010 13:02:23 -0500 lockfile-progs (0.1.13) unstable; urgency=low * Make exit_status volatile since it interacts with a signal handler. * Adjust code for -Wformat-security. Thanks to Michael Bienia . (closes: #487503) -- Rob Browning Sun, 21 Jun 2009 10:00:52 -0700 lockfile-progs (0.1.12) unstable; urgency=low * Fix manpage typos. Thanks to "A. Costa" . (closes: #439745) * Remove duplicate priority field from the control file. (closes: #464297) * Add a --use-pid option which adds L_PID to the underlying liblockfile call. Users should note the caveats in lockfile_create(3). * Add a lockfile-check program (see lockfile_check(3)). * Remove duplicate priority and section fields from debian/control. Thanks to Lucas Nussbaum and Patrick Winnertz . (closes: #464297) -- Rob Browning Wed, 17 Jun 2009 21:38:54 -0700 lockfile-progs (0.1.11) unstable; urgency=low * Add --quiet and --verbose options. (closes: #272539) * Use hard links for duplicate binaries. (closes: #382730) * Respect DEB_BUILD_OPTIONS nostrip. (closes: #437491) * Fix manpage to reflect changes to liblockfile --retry. (closes: #161685, #244314, #360474) * Add support for --lock-name (-l). (closes: #416355) -- Rob Browning Fri, 24 Aug 2007 17:35:23 -0700 lockfile-progs (0.1.10) unstable; urgency=low * update manpage to fix dashes under utf-8. (closes: #159907) * recompile to fix prelink problem. (closes: #231550) * fix manpage to note --try like semantics of --retry. -- Rob Browning Sat, 28 Feb 2004 11:44:30 -0600 lockfile-progs (0.1.9) unstable; urgency=low * Add command tool names to manpages. (closes: #88510) * Update my email address. -- Rob Browning Tue, 17 Jul 2001 12:38:34 -0500 lockfile-progs (0.1.8) unstable; urgency=low * Add Build-Depends: liblockfile-dev (Closes: Bug#94948, Bug#84547). * Move manpages to /usr/share/man (Closes: Bug#80755, Bug#91205). * Move docs to /usr/share (Closes: Bug#91571). -- Rob Browning Mon, 23 Apr 2001 15:24:26 -0500 lockfile-progs (0.1.7) unstable; urgency=low * Update to depend on liblockfile1 (Closes: Bug#44819) * Support new lockfile_create() signature. -- Rob Browning Fri, 24 Sep 1999 18:41:58 -0500 lockfile-progs (0.1.6) unstable; urgency=low * Really fix return codes (Closes: Bug#34279) -- Rob Browning Sat, 29 May 1999 13:36:42 -0500 lockfile-progs (0.1.5) unstable; urgency=low * Programs now return more meaningful result codes (Closes: Bug#31254). -- Rob Browning Sun, 17 Jan 1999 20:39:29 -0600 lockfile-progs (0.1.4) unstable; urgency=low * Don't allow locking arbitrary mailbox (Closes: Bug#28773). * Clean up code to use getopt. * Add --oneshot option to lock touching programs. * Add --retry-count option to locking programs. -- Rob Browning Sat, 21 Nov 1998 01:06:27 -0600 lockfile-progs (0.1.3) unstable; urgency=low * Rebuild as root. Libtricks built a broken .deb (a file that should have been a symlink was a truncated file of garbage). -- Rob Browning Fri, 30 Oct 1998 16:11:34 -0600 lockfile-progs (0.1.2) unstable; urgency=low * Make mail lock programs a separate binary, and make them sgid mail. -- Rob Browning Fri, 30 Oct 1998 15:47:17 -0600 lockfile-progs (0.1.1) unstable; urgency=low * Initial release. * This is beta code, so be a little cautious. I don't think there are any *serious* bugs, but... -- Rob Browning Mon, 19 Oct 1998 16:53:40 -0500 lockfile-progs-0.1.17build1/debian/compat0000664000000000000000000000000211404742242015131 0ustar 7 lockfile-progs-0.1.17build1/debian/control0000664000000000000000000000127611405103261015335 0ustar Source: lockfile-progs Section: misc Priority: optional Maintainer: Rob Browning Build-Depends: liblockfile-dev, debhelper (>= 7) Standards-Version: 3.6.1 Package: lockfile-progs Architecture: any Depends: ${shlibs:Depends} Description: Programs for locking and unlocking files and mailboxes This package includes several programs to safely lock and unlock files and mailboxes from the command line. These include: . lockfile-create lockfile-remove lockfile-touchlock mail-lock mail-unlock mail-touchlock . These programs use liblockfile to perform the file locking and unlocking, so they are guaranteed compatible with Debian's file locking policies. lockfile-progs-0.1.17build1/debian/copyright0000664000000000000000000000027607273061216015677 0ustar This is a Debian specific package, so there is no upstream source. lockfile-progs is covered under the terms of the GNU Public License. See /usr/share/common-licenses/GPL for more details. lockfile-progs-0.1.17build1/debian/lockfile-progs.lintian-overrides0000664000000000000000000000033111404743757022244 0ustar lockfile-progs binary: setgid-binary usr/bin/mail-lock 2755 root/mail lockfile-progs binary: setgid-binary usr/bin/mail-unlock 2755 root/mail lockfile-progs binary: setgid-binary usr/bin/mail-touchlock 2755 root/mail lockfile-progs-0.1.17build1/debian/rules0000775000000000000000000000214212056442532015015 0ustar #!/usr/bin/make -f # Copyright 1998-2012 Rob Browning # This file is covered under the terms of the Gnu Public License. DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE)) export CC := $(DEB_HOST_GNU_TYPE)-gcc endif export CFLAGS := -DDEBIAN -O2 -g export LDFLAGS := -g %: dh $@ override_dh_testdir: test -f debian/rules test -f lockfile-progs.c override_dh_auto_install: install -d debian/lockfile-progs/usr/bin cp -a bin/* debian/lockfile-progs/usr/bin/ # manpages install -d debian/lockfile-progs/usr/share/man/man1 cp -a man/* debian/lockfile-progs/usr/share/man/man1 find debian/lockfile-progs/usr/share/man -type f | xargs gzip -9v (cd debian/lockfile-progs/usr/share/man && \ for file in `find -type l`; \ do \ ln -sf lockfile-progs.1.gz $${file}.gz; \ rm -f $${file}; \ done) override_dh_fixperms: dh_fixperms chown :mail debian/lockfile-progs/usr/bin/mail-lock chmod g+s debian/lockfile-progs/usr/bin/mail-lock lockfile-progs-0.1.17build1/lockfile-progs.10000664000000000000000000001116311624310573015517 0ustar '\" t .\" ** The above line should force tbl to be a preprocessor ** .\" Man page for man .\" .\" Copyright (C), 1998-2008, Rob Browning .\" .\" You may distribute under the terms of the GNU General Public .\" License as specified in the file COPYING that comes with the .\" lockfile\-progs distribution. .\" .TH lockfile\-progs 1 "2008-02-10" "0.1.12" "Lockfile programs" .SH NAME lockfile\-progs \- command\-line programs to safely lock and unlock files and mailboxes (via liblockfile). .SH SYNOPSIS .nf \fBmail\-lock\fR [\-\-use\-pid] [\-\-retry \fIretry\-count\fR] \fBmail\-unlock\fR \fBmail\-touchlock\fR [\-\-oneshot] \fBlockfile\-create\fR [\-\-use\-pid] [\-\-retry \fIretry\-count\fR] [-\-lock\-name] \fIfilename\fR \fBlockfile\-remove\fR [-\-lock\-name] \fIfilename\fR \fBlockfile\-touch\fR [\-\-oneshot] [-\-lock\-name] \fIfilename\fR \fBlockfile\-check\fR [\-\-use-pid] [-\-lock\-name] \fIfilename\fR .fi .SH DESCRIPTION .PP Lockfile\-progs provides a set a programs that can be used to lock and unlock mailboxes and files safely (via liblockfile): .nf .RS 4 \fBmail\-lock\fR - lock the current user's mailbox \fBmail\-unlock\fR - unlock the current user's mailbox \fBmail\-touchlock\fR - touch the lock on the current user's mailbox \fBlockfile\-create\fR - lock a given file \fBlockfile\-remove\fR - remove the lock on a given file \fBlockfile\-touch\fR - touch the lock on a given file \fBlockfile\-check\fR - check the lock on a given file .RE .fi By default, the \fIfilename\fR argument refers to the name of the file to be locked, and the name of the lockfile will be \fIfilename\fR .lock. However, if the \-\-lock-name argument is specified, then \fIfilename\fR will be taken as the name of the lockfile itself. Each of the mail locking commands attempts to lock /var/spool/mail/, where is the name associated with the effective user ID, as determined by via geteuid(2). Once a file is locked, the lock must be touched at least once every five minutes or the lock will be considered stale, and subsequent lock attempts will succeed. Also see the \fB\-\-use\-pid\fR option and the \fBlockfile_create\fR(3) manpage. The \fBlockfile\-check\fR command tests whether or not a valid lock already exists. .SH OPTIONS .PP .\" --quiet \fB\-q\fR, \fB\-\-quiet\fR .RS 4 Suppress any output. Success or failure will only be indicated by the exit status. .RE .PP .\" --verbose \fB\-v\fR, \fB\-\-verbose\fR .RS 4 Enable diagnostic output. .RE .PP .\" --lock-name \fB\-l\fR, \fB\-\-lock\-name\fR .RS 4 Do not append .lock to the \fIfilename\fR. This option applies to \fBlockfile\-create\fR, \fBlockfile\-remove\fR, \fBlockfile-touch\fR, or \fBlockfile-check\fR. .RE .PP .\" --use-pid \fB\-p\fR, \fB\-\-use\-pid\fR .RS 4 Write the parent process id (PPID) to the lockfile whenever a lockfile is created, and use that pid when checking a lock's validity. See the \fBlockfile_create\fR(3) manpage for more information. This option applies to \fBlockfile\-create\fR and \fBlockfile-check\fR. NOTE: this option will not work correctly between machines sharing a filesystem. .RE .PP .\" --oneshot \fB\-o\fR, \fB\-\-oneshot\fR .RS 4 Touch the lock and exit immediately. This option applies to \fBlockfile\-touch\fR and \fBmail\-touchlock\fR. When not provided, these commands will run forever, touching the lock once every minute until killed. .RE .PP .\" --retry \fB\-r\fR \fIretry\-count\fR, \fB\-\-retry\fR \fIretry\-count\fR .RS 4 Try to lock \fIfilename\fR \fIretry\-count\fR times before giving up. Each attempt will be delayed a bit longer than the last (in 5 second increments) until reaching a maximum delay of one minute between retries. If \fIretry\-count\fR is unspecified, the default is 9 which will give up after 180 seconds (3 minutes) if all 9 lock attempts fail. .SH EXAMPLES .B Locking a file during a lengthy process: lockfile\-create /some/file lockfile\-touch /some/file & # Save the PID of the lockfile\-touch process BADGER="$!" do\-something\-important\-with /some/file kill "${BADGER}" lockfile\-remove /some/file .SH "EXIT STATUS" .PP \fB0\fR .RS 4 For \fBlockfile\-check\fR this indicates that a valid lock exists, otherwise it just indicates successful program execution. .RE .PP \fBNot 0\fR .RS 4 For \fBlockfile\-check\fR a non-zero exit status indicates that the specified lock does not exist or is not valid. For other programs it indicates that some problem was encountered. .RE .SH "SEE ALSO" .nf \fBmaillock\fR(3) \fBtouchlock\fR(3) \fBmailunlock\fR(3) \fBlockfile_create\fR(3) \fBlockfile_remove\fR(3) \fBlockfile_touch\fR(3) \fBlockfile_check\fR(3) .fi .SH AUTHOR Written by Rob Browning lockfile-progs-0.1.17build1/lockfile-progs.c0000664000000000000000000002124412056437625015612 0ustar /* lockfile-progs.c Copyright 1998-2009 Rob Browning This code is covered under the terms of the Gnu Public License. See the accompanying COPYING file for details. To do: It might be useful at some point to support a --user option to mail-lock that can only be used by the superuser (of course, they could just use lockfile-create with an appropriate path... */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include static const char *action = NULL; static char *target_file = NULL; static int retry_count_specified = 0; static int retry_count = 9; /* This will be a maximum of 3 minutes */ static int touchlock_oneshot = 0; static int use_pid = 0; /* not used yet, so not documented... */ static int lockfile_verbosity = 1; static int lockfile_add_dot_lock_to_name = 1; static volatile int exit_status = 0; static int msg(FILE *f, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); static int msg(FILE *f, const char *fmt, ...) { int rc = 0; if(lockfile_verbosity > 0) { va_list args; va_start(args, fmt); rc = vfprintf(f, fmt, args); va_end(args); } return rc; } static void chk(const int test, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); static void chk(const int test, const char *fmt, ...) { if(!test) { if(lockfile_verbosity > 0) { va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); } exit(1); } } static void usage(const char *command_name, FILE *file) { if(strcmp(command_name, "mail-lock") == 0) { msg(file, "usage: mail-lock [--use-pid] [--retry retry-count]\n"); } else if(strcmp(command_name, "mail-unlock") == 0) { msg(file, "usage: mail-unlock\n"); } else if(strcmp(command_name, "mail-touchlock") == 0) { msg(file, "usage: mail-touchlock [--oneshot]\n"); } else if(strcmp(command_name, "lockfile-create") == 0) { msg(file,"usage: lockfile-create" " [--use-pid] [--retry retry-count] [--lock-name] file\n"); } else if(strcmp(command_name, "lockfile-remove") == 0) { msg(file, "usage: lockfile-remove [--lock-name] file\n"); } else if(strcmp(command_name, "lockfile-touch") == 0) { msg(file, "usage: lockfile-touch [--oneshot] [--lock-name] file\n"); } else if(strcmp(command_name, "lockfile-check") == 0) { msg(file, "usage: lockfile-check [--use-pid] [--lock-name] file\n"); } else { msg(stderr, "lockfile: big problem - unknown command name: %s\n", command_name); exit(1); } } static void parse_arguments(const int argc, char *argv[]) { int usage_error = 0; int opt_result; const char *short_opts = "r:oplqv"; struct option long_opts[] = { { "retry", required_argument, NULL, 'r' }, { "oneshot", no_argument, NULL, 'o' }, { "use-pid", no_argument, NULL, 'p' }, { "lock-name", no_argument, NULL, 'l' }, { "quiet", no_argument, NULL, 'q' }, { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; char *cmd_name = rindex(argv[0], '/'); int mail_cmd_p = 0; if(cmd_name != NULL) { /* Skip the '/' */ cmd_name++; } else { cmd_name = argv[0]; } while((opt_result = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { switch(opt_result) { case 'o': touchlock_oneshot = 1; break; case 'p': use_pid = 1; break; case 'q': lockfile_verbosity = 0; break; case 'v': lockfile_verbosity = 2; break; case 'l': lockfile_add_dot_lock_to_name = 0; break; case 'r': { char *rest_of_string; long tmp_value = strtol(optarg, &rest_of_string, 10); retry_count_specified = 1; if((tmp_value == 0) && (rest_of_string == optarg)) { /* Bad value */ msg(stderr, "%s: bad retry-count value\n", cmd_name); usage(cmd_name, stderr); exit(1); } else retry_count = tmp_value; } break; case '?': usage(cmd_name, stderr); exit(1); break; default: msg(stderr, "%s: getopt returned impossible value 0%o.\n", cmd_name, opt_result); exit(1); break; } } if(strcmp(cmd_name, "mail-lock") == 0) { action = "lock"; mail_cmd_p = 1; } else if(strcmp(cmd_name, "mail-unlock") == 0) { action = "unlock"; mail_cmd_p = 1; } else if(strcmp(cmd_name, "mail-touchlock") == 0) { action = "touch"; mail_cmd_p = 1; } else if(strcmp(cmd_name, "lockfile-create") == 0) action = "lock"; else if(strcmp(cmd_name, "lockfile-remove") == 0) action = "unlock"; else if(strcmp(cmd_name, "lockfile-touch") == 0) action = "touch"; else if(strcmp(cmd_name, "lockfile-check") == 0) action = "check"; else usage_error = 1; if(retry_count_specified && (strcmp("lock", action) != 0)) usage_error = 1; if(use_pid && (strcmp("lock", action) != 0) && (strcmp("check", action) != 0)) usage_error = 1; if(touchlock_oneshot && (strcmp(action, "touch") != 0)) usage_error = 1; if(mail_cmd_p && !lockfile_add_dot_lock_to_name) usage_error = 1; if(usage_error) { usage(cmd_name, stderr); exit(1); } if(mail_cmd_p) { if(optind == argc) { uid_t user_id = geteuid(); struct passwd *user_info = getpwuid(user_id); if(user_info == NULL) { msg(stderr, "%s: fatal error, can't find info for user id %ud\n", cmd_name, user_id); exit(1); } if(asprintf(&target_file, "/var/spool/mail/%s", user_info->pw_name) == -1) { msg(stderr, "asprintf failed: line %d\n", __LINE__); exit(1); } } else { usage(cmd_name, stderr); exit(1); } } else { if((argc - optind) != 1) { usage(cmd_name, stderr); exit(1); } target_file = argv[optind]; } } static void handle_touchdeath(int sig) { exit(exit_status); } /* Must be called right after liblockfile call (b/c it calls strerror())*/ static char* get_status_code_string(int status) { switch (status) { case L_SUCCESS: return strdup("success"); break; case L_NAMELEN: return strdup("name too long"); break; case L_TMPLOCK: return strdup("cannot create temporary lockfile"); break; case L_TMPWRITE: return strdup("cannot write PID lockfile"); break; case L_MAXTRYS: return strdup("exceeded maximum number of lock attempts"); break; case L_ERROR: return strdup(strerror(errno));; break; default: return 0L; break; } } static int cmd_unlock(const char *lockfilename) { int rc = lockfile_remove(lockfilename); if((rc != L_SUCCESS) && (lockfile_verbosity > 0)) perror("lockfile removal failed"); return rc; } static int cmd_lock(const char *lockfilename, int retry_count) { int rc = lockfile_create(lockfilename, retry_count, (use_pid ? L_PPID : 0)); const char *rc_str = get_status_code_string(rc); if(rc != L_SUCCESS) msg(stderr, "lockfile creation failed: %s\n", rc_str); if(rc_str) free((void *) rc_str); return rc; } static int cmd_touch(const char *lockfilename, int touchlock_oneshot) { int rc = 0; signal(SIGTERM, handle_touchdeath); if(touchlock_oneshot) rc = lockfile_touch(lockfilename); else { while(1 && (rc == 0)) { rc = lockfile_touch(lockfilename); sleep(60); } } return rc; } static int cmd_check(const char *lockfilename) { int rc = lockfile_check(lockfilename, (use_pid ? L_PPID : 0)); return rc; } int main(int argc, char *argv[]) { const char *lock_name_pattern = "%s"; char *lockfilename = NULL; chk(L_SUCCESS == 0, "liblockfile's L_SUCCESS != 0 (aborting)"); parse_arguments(argc, argv); if(lockfile_add_dot_lock_to_name) lock_name_pattern = "%s.lock"; if(asprintf(&lockfilename, lock_name_pattern, target_file) == -1) { msg(stderr, "asprintf failed: line %d\n", __LINE__); exit(1); } if(strcmp(action, "unlock") == 0) exit_status = cmd_unlock(lockfilename); else if(strcmp(action, "lock") == 0) exit_status = cmd_lock(lockfilename, retry_count); else if(strcmp(action, "touch") == 0) exit_status = cmd_touch(lockfilename, touchlock_oneshot); else if(strcmp(action, "check") == 0) exit_status = cmd_check(lockfilename); if(lockfilename) free(lockfilename); return(exit_status); }