diff options
-rw-r--r-- | Makefile.am | 5 | ||||
-rwxr-xr-x | bootstrap.sh | 21 | ||||
-rw-r--r-- | configure.ac | 26 | ||||
-rw-r--r-- | doc/README.html.in | 19 | ||||
-rw-r--r-- | doc/style.css | 25 | ||||
-rw-r--r-- | man/Makefile.am | 15 | ||||
-rw-r--r-- | man/ivcall.1.xml.in | 5 | ||||
-rw-r--r-- | man/xmltoman.css | 30 | ||||
-rw-r--r-- | man/xmltoman.dtd | 39 | ||||
-rw-r--r-- | man/xmltoman.xsl | 120 | ||||
-rw-r--r-- | src/ivcall.c | 11 | ||||
-rw-r--r-- | src/lock.c | 154 | ||||
-rw-r--r-- | src/lock.h | 4 | ||||
-rw-r--r-- | src/util.c | 4 |
14 files changed, 391 insertions, 87 deletions
diff --git a/Makefile.am b/Makefile.am index 1f2fd20..a107b0a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,3 +33,8 @@ homepage: cp *.tar.gz $$HOME/homepage/lennart/projects/ivcall cp doc/README.html doc/style.css $$HOME/homepage/lennart/projects/ivcall cp $$HOME/homepage/lennart/projects/ivcall/README.html $$HOME/homepage/lennart/projects/ivcall/index.html + +distcleancheck: + @: + +.PHONY: homepage distcleancheck diff --git a/bootstrap.sh b/bootstrap.sh index 73e6c40..6d6db78 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -17,22 +17,29 @@ # along with ivcall; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +run_versioned() { + local P + type -p "$1-$2" &> /dev/null && P="$1-$2" || local P="$1" + + shift 2 + "$P" "$@" +} + if [ "x$1" = "xam" ] ; then set -ex - automake -a -c + run_versioned automake 1.7 -a -c ./config.status else set -ex - - make maintainer-clean || true - rm -rf autom4te.cache rm -f config.cache - aclocal + run_versioned aclocal 1.7 autoheader - automake -a -c + run_versioned automake 1.7 -a -c autoconf -Wall - ./configure "$@" + ./configure --sysconfdir=/etc "$@" + + make clean fi diff --git a/configure.ac b/configure.ac index 2a3b0f5..9c46925 100644 --- a/configure.ac +++ b/configure.ac @@ -19,15 +19,25 @@ # along with ivcall; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -AC_PREREQ(2.57) -AC_INIT([ivcall], [0.2], [mzvipnyy@itaparica.org]) +AC_PREREQ(2.58) +AC_INIT([ivcall], [0.3], [mzvipnyy (at) 0pointer (dot) de]) AC_CONFIG_SRCDIR([src/ivcall.c]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([foreign -Wall]) -AM_MAINTAINER_MODE + +AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/ivcall/]) + +if type -p stow > /dev/null && test -d /usr/local/stow ; then + AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION} ***]) + ac_default_prefix="/usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION}" +fi # Checks for programs. AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET # If using GCC specify some additional parameters if test "x$GCC" = "xyes" ; then @@ -36,16 +46,12 @@ fi # Specify the locking directory AC_ARG_WITH(lockdir, - AC_HELP_STRING([--with-lockdir=LOCKDIR], [Specify a lock dir]), + AC_HELP_STRING([--with-lockdir=LOCKDIR], [Specify a UUCP lock dir]), LOCK_DIR="${withval}", LOCK_DIR="/var/lock") AC_SUBST(LOCK_DIR) +AC_MSG_NOTICE([*** Using $LOCK_DIR as lock directory ***]) -AC_PROG_CPP -AC_PROG_INSTALL -AC_PROG_LN_S -AC_PROG_MAKE_SET - AC_CHECK_FUNCS([alarm memset select strdup strerror strrchr]) AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h sys/ioctl.h sys/time.h termios.h unistd.h]) @@ -100,7 +106,5 @@ fi AM_CONDITIONAL([USE_XMLTOMAN], [test "x$xmltoman" = xyes]) -AC_MSG_NOTICE([*** Using $LOCK_DIR as lock directory ***]) - AC_CONFIG_FILES([src/Makefile Makefile man/Makefile doc/Makefile doc/README.html]) AC_OUTPUT diff --git a/doc/README.html.in b/doc/README.html.in index bf7a739..8dd94d4 100644 --- a/doc/README.html.in +++ b/doc/README.html.in @@ -10,7 +10,7 @@ <body> <h1><a name="top">ivcall @PACKAGE_VERSION@</a></h1> -<p><i>Copyright 2002,2003 Lennart Poettering <mzvscyhtq [at] itaparica.org></i></p> +<p><i>Copyright 2002,2003 Lennart Poettering <@PACKAGE_BUGREPORT@></i></p> <ul class="toc"> <li><a href="#license">License</a></li> @@ -42,6 +42,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p> <h2><a name="news">News</a></h2> +<div class="news-date">Sat Jan 2004: </div> <p class="news-text"><a +href="http://www.stud.uni-hamburg.de/~lennart/projects/ivcall/ivcall-0.3.tar.gz">Version +0.3</a> released, changes include: uucp locking fixes</p> + <div class="news-date">Sun July 27 2003: </div> <p class="news-text"><a href="http://www.stud.uni-hamburg.de/~lennart/projects/ivcall/ivcall-0.2.tar.gz">Version 0.2</a> released, changes include: many fixes, autoconf support</p> @@ -62,6 +66,8 @@ without any headers.</p> <h2><a name="documentation">Documentation</a></h2> +<p>Have a look on the man page <a href="@PACKAGE_URL@ivcall.1.xml"><tt>ivcall(1)</tt></a>. (An XSLT capable browser is required)</p> + <p>You may use <tt>ivcall</tt> as a Unix filter: <pre> @@ -119,13 +125,16 @@ on their source codes for learning how to use the <tt>isdn4linux</tt> modem emul <h2><a name="download">Download</a></h2> -<p>The newest release is always available from <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ivcall/">http://www.stud.uni-hamburg.de/~lennart/projects/ivcall/</a></p> +<p>The newest release is always available from <a href="@PACKAGE_URL@">@PACKAGE_URL@</a></p> + +<p>The current release is <a href="@PACKAGE_URL@ivcall-@PACKAGE_VERSION@.tar.gz">@PACKAGE_VERSION@</a></p> + +<p>Get <tt>ivcall</tt>'s development sources from the <a href="http://subversion.tigris.org/">Subversion</a> <a href="https://seth.intheinter.net:8081/svn/ivcall/">repository</a>.</p> -<p>The current release is <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ivcall/ivcall-@PACKAGE_VERSION@.tar.gz">@PACKAGE_VERSION@</a></p> <hr/> -<address>Lennart Poettering <mzvscyhtq [at] itaparica.org>, July 2003</address> -<div><i>$Id$</i></div> +<address class="grey">Lennart Poettering <@PACKAGE_BUGREPORT@>, January 2004</address> +<div class="grey"><i>$Id$</i></div> </body> </html> diff --git a/doc/style.css b/doc/style.css index 0a40aef..5b26014 100644 --- a/doc/style.css +++ b/doc/style.css @@ -1,12 +1,33 @@ /* $Id$ */ + +/*** + * This file is part of ivcall. + * + * ivcall 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. + * + * ivcall 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 ivcall; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + ***/ + body { color: black; background-color: white; margin: 0.5cm; } a:link, a:visited { color: #900000; } p { margin-left: 0.5cm; margin-right: 0.5cm; } div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; } p.news-text { margin-left: 1cm; } -ul { margin-left: .5cm; } -ol { margin-left: .5cm; } h1 { color: #00009F; } h2 { color: #00009F; } h3 { color: #00004F; margin-left: 0.5cm; } +ul { margin-left: .5cm; } +ol { margin-left: .5cm; } pre { margin-left: .5cm; background-color: #f0f0f0; padding: 0.4cm;} +.grey { color: #afafaf; } + diff --git a/man/Makefile.am b/man/Makefile.am index 10da8b5..883aaa9 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -18,13 +18,20 @@ man_MANS = ivcall.1 -EXTRA_DIST = $(man_MANS) ivcall.1.xml.in +noinst_DATA = ivcall.1.xml + +EXTRA_DIST = $(man_MANS) ivcall.1.xml.in xmltoman.css xmltoman.xsl xmltoman.dtd + +CLEANFILES = ivcall.1.xml + +ivcall.1.xml: ivcall.1.xml.in Makefile + sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' -e 's,@PACKAGE_URL\@,$(PACKAGE_URL),g' $< > $@ if USE_XMLTOMAN -CLEANFILES = $(man_MANS) +CLEANFILES += $(man_MANS) -ivcall.1: ivcall.1.xml.in Makefile - sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' $< | xmltoman - > $@ +ivcall.1: ivcall.1.xml Makefile + xmltoman $< > $@ endif diff --git a/man/ivcall.1.xml.in b/man/ivcall.1.xml.in index c861f27..1553b04 100644 --- a/man/ivcall.1.xml.in +++ b/man/ivcall.1.xml.in @@ -1,5 +1,6 @@ <?xml version="1.0" standalone='no'?> -<!DOCTYPE spec SYSTEM "man.dtd"> +<!DOCTYPE spec SYSTEM "xmltoman.dtd"> +<?xml-stylesheet type="text/xsl" href="xmltoman.xsl" ?> <!-- $Id$ --> @@ -99,7 +100,7 @@ <p>ivcall was written by Lennart Poettering <@PACKAGE_BUGREPORT@>. ivcall is available at <url - href="http://www.stud.uni-hamburg.de/users/lennart/projects/ivcall/"/> + href="@PACKAGE_URL@"/> </p> </section> diff --git a/man/xmltoman.css b/man/xmltoman.css new file mode 100644 index 0000000..fc3cf17 --- /dev/null +++ b/man/xmltoman.css @@ -0,0 +1,30 @@ +/* $Id$ */ + +/*** + This file is part of ivcall. + + ivcall 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. + + ivcall 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 ivcall; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +***/ + +body { color: black; background-color: white; margin: 0.5cm; } +a:link, a:visited { color: #900000; } +h1 { text-transform:uppercase; font-size: 18pt; color: #00009F; } +p { margin-left:1cm; margin-right:1cm; } +.cmd { font-family:monospace; } +.file { font-family:monospace; } +.arg { text-transform:uppercase; font-family:monospace; font-style: italic; } +.opt { font-family:monospace; font-weight: bold; } +.manref { font-family:monospace; } +.option .optdesc { margin-left:2cm; } diff --git a/man/xmltoman.dtd b/man/xmltoman.dtd new file mode 100644 index 0000000..e235e77 --- /dev/null +++ b/man/xmltoman.dtd @@ -0,0 +1,39 @@ +<!-- $Id$ --> + +<!-- + This file is part of ivcall. + + ivcall 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. + + ivcall 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 ivcall; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +--> + +<!ELEMENT manpage (synopsis | description | section | options | seealso)*> +<!ATTLIST manpage name CDATA #REQUIRED section CDATA #REQUIRED desc CDATA #IMPLIED> +<!ELEMENT arg (#PCDATA)> +<!ELEMENT p (#PCDATA | arg | url | manref | opt | file )*> +<!ELEMENT synopsis (cmd | p)+> +<!ELEMENT description (p)+> +<!ELEMENT section (p | option)*> +<!ATTLIST section name CDATA #REQUIRED> +<!ELEMENT option (#PCDATA | p | optdesc)*> +<!ELEMENT optdesc (#PCDATA | p )*> +<!ELEMENT cmd (#PCDATA | arg)*> +<!ELEMENT options (p | option)*> +<!ELEMENT seealso (p)*> +<!ELEMENT opt (#PCDATA)> +<!ELEMENT file (#PCDATA)> +<!ELEMENT manref EMPTY> +<!ATTLIST manref name CDATA #REQUIRED section CDATA #REQUIRED href CDATA #IMPLIED> +<!ELEMENT url EMPTY> +<!ATTLIST url href CDATA #REQUIRED> diff --git a/man/xmltoman.xsl b/man/xmltoman.xsl new file mode 100644 index 0000000..1927ff7 --- /dev/null +++ b/man/xmltoman.xsl @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> + +<!-- + This file is part of ivcall. + + ivcall 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. + + ivcall 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 ivcall; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +--> + +<xsl:template match="/manpage"> + <xsl:text disable-output-escaping="yes"> + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + </xsl:text> + <html> + + <head> + <title> + <xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>) + </title> + <link rel="stylesheet" type="text/css" href="xmltoman.css"/> + </head> + <body> + <h1>Name</h1> + <p><xsl:value-of select="@name"/> + <xsl:if test="string-length(@desc) > 0"> + - <xsl:value-of select="@desc"/> + </xsl:if> + </p> + <xsl:apply-templates /> + </body> + </html> +</xsl:template> + +<xsl:template match="p"> + <p> + <xsl:apply-templates/> + </p> +</xsl:template> + +<xsl:template match="cmd"> + <p class="cmd"> + <xsl:apply-templates/> + </p> +</xsl:template> + +<xsl:template match="arg"> + <span class="arg"><xsl:apply-templates/></span> +</xsl:template> + +<xsl:template match="opt"> + <span class="opt"><xsl:apply-templates/></span> +</xsl:template> + +<xsl:template match="file"> + <span class="file"><xsl:apply-templates/></span> +</xsl:template> + +<xsl:template match="optdesc"> + <div class="optdesc"> + <xsl:apply-templates/> + </div> +</xsl:template> + +<xsl:template match="synopsis"> + <h1>Synopsis</h1> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="seealso"> + <h1>Synopsis</h1> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="description"> + <h1>Description</h1> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="options"> + <h1>Options</h1> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="section"> + <h1><xsl:value-of select="@name"/></h1> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="option"> + <div class="option"><xsl:apply-templates/></div> +</xsl:template> + +<xsl:template match="manref"> + <xsl:choose> + <xsl:when test="string-length(@href) > 0"> + <a class="manref"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>)</a> + </xsl:when> + <xsl:otherwise> + <span class="manref"><xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>)</span> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="url"> + <a class="url"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:value-of select="@href"/></a> +</xsl:template> + +</xsl:stylesheet> diff --git a/src/ivcall.c b/src/ivcall.c index 7e953f9..5aca741 100644 --- a/src/ivcall.c +++ b/src/ivcall.c @@ -18,6 +18,10 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <termios.h> #include <fcntl.h> #include <stdlib.h> @@ -38,11 +42,6 @@ #include "util.h" #include "lock.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - // Those nifty DLE-sequences #define DLE 0x10 #define ETX 0x03 @@ -392,7 +391,7 @@ int go(void) { goto fail; } - snprintf(buf, sizeof(buf), "AT&E%s\n", source_msn); + snprintf(buf, sizeof(buf), "AT&L%s\n", source_msn); if (tty_command(fd, buf, "OK\r\n", COMMAND_TIMEOUT) < 0) { fprintf(stderr, "Initialisation failure.\n"); goto fail; @@ -18,6 +18,11 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + #include <unistd.h> #include <sys/stat.h> #include <stdio.h> @@ -29,6 +34,7 @@ #include <string.h> #include <assert.h> #include <pwd.h> +#include <inttypes.h> #include "lock.h" #include "util.h" @@ -40,69 +46,121 @@ static char* lockfile = NULL; -// Tries to lock a TTY-device, returns 0 on success -int device_lock(char *dev, char *appname) { - char buf[256], u[16]; - char path[PATH_MAX]; +static const char *get_lockfile(const char *dev) { + static char lockfile[PATH_MAX]; + snprintf(lockfile, sizeof(lockfile), "%s/LCK..%s", LOCK_DIR, basename((char*) dev)); + return lockfile; +} + +static const char *get_tempfile(const char *path) { + static char t[PATH_MAX]; + snprintf(t, sizeof(t), "%s.tmp.%lu", path, (unsigned long) getpid()); + return t; +} + + +int device_lock(const char *dev, const char *appname) { + struct stat st; int fd; - struct passwd *pwd; - char *username; + const char *path, *temp; + char buf[100]; + char uidbuf[32]; - assert(dev && !lockfile); - - if (access(LOCK_DIR, W_OK) < 0) + if (stat(LOCK_DIR, &st) != 0 || !S_ISDIR(st.st_mode)) { + fprintf(stderr, "Failed to lock device, directory "LOCK_DIR" not existent.\n"); return -1; + } + + path = get_lockfile(dev); + temp = get_tempfile(path); + + for (;;) { + mode_t u; + struct passwd* pw; + char *username; - snprintf(path, sizeof(path), "%s/LCK..%s", LOCK_DIR, basename(dev)); - - if ((fd = open(path, O_RDONLY)) >= 0) { - int n = loop_read(fd, buf, sizeof(buf) - 1); - close(fd); + if ((fd = open(path, O_RDONLY)) < 0) { + if (errno != ENOENT) { + fprintf(stderr, "Failed to open lock file: %s\n", strerror(errno)); + return -1; + } + } + + if (fd >= 0) { + ssize_t n; - if (n > 0) { - int pid; - - if (n == 4) - pid = *(int*) buf; - else { - buf[n] = 0; - sscanf(buf, "%d", &pid); + n = loop_read(fd, buf, sizeof(buf) - 1); + close(fd); + + if (n < 0) { + close(fd); + fprintf(stderr, "Failed to read from lock file: %s\n", strerror(errno)); + return -1; } - - if (pid > 0) { - if (kill((pid_t) pid, 0) < 0 && errno == ESRCH) { - fprintf(stderr, "Lockfile is stale. Overriding it.\n"); - unlink(path); - } else - return -1; + + if (n > 0) { + pid_t pid; + + if (n == 4) + pid = (pid_t) *((uint32_t*) buf); + else { + unsigned long v; + buf[n] = 0; + sscanf(buf, "%lu", &v); + pid = (pid_t) v; + } + + if (pid > 0) { + if (kill(pid, 0) < 0 && errno == ESRCH) { + fprintf(stderr, "Lockfile is stale. Overriding it.\n"); + /* Yes, here is a race condition */ + unlink(path); + } else + return 1; + } } } - } - if ((fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0) - return -1; - - if ((pwd = getpwuid(getuid()))) - username = pwd->pw_name; - else - snprintf(username = u, sizeof(u), "%u", getuid()); + u = umask(0033); + fd = open(temp, O_WRONLY | O_CREAT | O_EXCL, 0666); + umask(u); + + if (fd < 0) { + fprintf(stderr, "Failed to create temporary lock file: %s", strerror(errno)); + return -1; + } + + if ((pw = getpwuid(getuid()))) + username = pw->pw_name; + else + snprintf(username = uidbuf, sizeof(uidbuf), "%lu", (unsigned long) getuid()); + + snprintf(buf, sizeof(buf), "%10lu %s %.20s\n", (unsigned long) getpid(), appname, username); + if (loop_write(fd, buf, strlen(buf)) < 0) { + fprintf(stderr, "Failed to write to temporary lock file: %s", strerror(errno)); + close(fd); + return -1; + } - snprintf(buf, sizeof(buf), "%10ld %s %.20s\n", (long)getpid(), appname, username); - - if (loop_write(fd, buf, strlen(buf)) < 0) { close(fd); - return -1; - } - - close(fd); - lockfile = strdup(path); - - return 0; + if (link(temp, path) < 0) { + if (errno == EEXIST) + continue; + + fprintf(stderr, "Failed to link temporary lock file: %s", strerror(errno)); + } + + unlink(temp); + lockfile = strdup(path); + + return 0; + } } + // Tries to lock the first free device, returns 0 on success -int device_lock_first(char *appname, char *dev, size_t l) { +int device_lock_first(const char *appname, char *dev, size_t l) { int i, found = 0; for (i = 2; i <= 20; i++) { @@ -21,8 +21,8 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -int device_lock(char *dev, char*appname); -int device_lock_first(char*appname, char *dev, size_t l); +int device_lock(const char *dev, const char*appname); +int device_lock_first(const char*appname, char *dev, size_t l); void device_unlock(void); #endif @@ -18,6 +18,10 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <unistd.h> #include <termios.h> #include <string.h> |