<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[138165] trunk/base/src</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/138165">138165</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2015-06-30 13:58:44 -0700 (Tue, 30 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>base: rename pextlib flock to adv-flock to avoid conflict with TclX, closes #46733

This has come up a few times and is somehow related to the order in which the
packages are loaded, but I haven't been able to pinpoint why exactly the order
varies.

Let's avoid wasting any time on the dirty details and just rename our own
implementation. The new name is &quot;adv-flock&quot; for &quot;advisory file lock&quot;.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcpextlib10Makefilein">trunk/base/src/pextlib1.0/Makefile.in</a></li>
<li><a href="#trunkbasesrcpextlib10Pextlibc">trunk/base/src/pextlib1.0/Pextlib.c</a></li>
<li><a href="#trunkbasesrcport10portutiltcl">trunk/base/src/port1.0/portutil.tcl</a></li>
<li><a href="#trunkbasesrcregistry20registrytcl">trunk/base/src/registry2.0/registry.tcl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkbasesrcpextlib10advflockc">trunk/base/src/pextlib1.0/adv-flock.c</a></li>
<li><a href="#trunkbasesrcpextlib10advflockh">trunk/base/src/pextlib1.0/adv-flock.h</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkbasesrcpextlib10flockc">trunk/base/src/pextlib1.0/flock.c</a></li>
<li><a href="#trunkbasesrcpextlib10flockh">trunk/base/src/pextlib1.0/flock.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcpextlib10Makefilein"></a>
<div class="modfile"><h4>Modified: trunk/base/src/pextlib1.0/Makefile.in (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/Makefile.in        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/pextlib1.0/Makefile.in        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx">         Pextlib.o strsed.o fgetln.o md5cmd.o setmode.o xinstall.o \
</span><span class="cx">         fs-traverse.o strcasecmp.o vercomp.o filemap.o base32cmd.o \
</span><span class="cx">         sha1cmd.o curl.o rmd160cmd.o sha256cmd.o readline.o uid.o \
</span><del>-        tracelib.o tty.o readdir.o pipe.o flock.o system.o \
</del><ins>+        tracelib.o tty.o readdir.o pipe.o adv-flock.o system.o \
</ins><span class="cx">         mktemp.o realpath.o
</span><span class="cx"> ifneq (@ac_cv_func_strlcat@,yes)
</span><span class="cx"> OBJS+=strlcat.o
</span></span></pre></div>
<a id="trunkbasesrcpextlib10Pextlibc"></a>
<div class="modfile"><h4>Modified: trunk/base/src/pextlib1.0/Pextlib.c (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/Pextlib.c        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/pextlib1.0/Pextlib.c        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -89,7 +89,7 @@
</span><span class="cx"> #include &quot;strsed.h&quot;
</span><span class="cx"> #include &quot;readdir.h&quot;
</span><span class="cx"> #include &quot;pipe.h&quot;
</span><del>-#include &quot;flock.h&quot;
</del><ins>+#include &quot;adv-flock.h&quot;
</ins><span class="cx"> #include &quot;system.h&quot;
</span><span class="cx"> #include &quot;mktemp.h&quot;
</span><span class="cx"> #include &quot;realpath.h&quot;
</span><span class="lines">@@ -608,7 +608,7 @@
</span><span class="cx">         return TCL_ERROR;
</span><span class="cx"> 
</span><span class="cx">         Tcl_CreateObjCommand(interp, &quot;system&quot;, SystemCmd, NULL, NULL);
</span><del>-        Tcl_CreateObjCommand(interp, &quot;flock&quot;, FlockCmd, NULL, NULL);
</del><ins>+        Tcl_CreateObjCommand(interp, &quot;adv-flock&quot;, AdvFlockCmd, NULL, NULL);
</ins><span class="cx">         Tcl_CreateObjCommand(interp, &quot;readdir&quot;, ReaddirCmd, NULL, NULL);
</span><span class="cx">         Tcl_CreateObjCommand(interp, &quot;strsed&quot;, StrsedCmd, NULL, NULL);
</span><span class="cx">         Tcl_CreateObjCommand(interp, &quot;mkstemp&quot;, MkstempCmd, NULL, NULL);
</span></span></pre></div>
<a id="trunkbasesrcpextlib10advflockcfromrev138164trunkbasesrcpextlib10flockc"></a>
<div class="copfile"><h4>Copied: trunk/base/src/pextlib1.0/adv-flock.c (from rev 138164, trunk/base/src/pextlib1.0/flock.c) (0 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/adv-flock.c                                (rev 0)
+++ trunk/base/src/pextlib1.0/adv-flock.c        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -0,0 +1,256 @@
</span><ins>+/*
+ * adv-flock.c
+ * $Id$
+ *
+ * Copyright (c) 2009 The MacPorts Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The MacPorts Project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include &lt;config.h&gt;
+#endif
+
+/* needed to get struct sigaction on some platforms */
+#define _XOPEN_SOURCE 500L
+/* the above hides flock on OS X without _DARWIN_C_SOURCE */
+#define _DARWIN_C_SOURCE
+
+#if HAVE_SYS_FILE_H
+#include &lt;sys/file.h&gt;
+#endif
+
+#include &lt;errno.h&gt;
+#include &lt;inttypes.h&gt;
+#include &lt;signal.h&gt;
+#include &lt;string.h&gt;
+#include &lt;unistd.h&gt;
+
+#include &lt;tcl.h&gt;
+
+#include &quot;adv-flock.h&quot;
+
+static volatile int alarmReceived = 0;
+
+static void alarmHandler(int sig UNUSED) {
+    alarmReceived = 1;
+}
+
+int
+AdvFlockCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+    static const char errorstr[] = &quot;use one of \&quot;-shared\&quot;, \&quot;-exclusive\&quot;, or \&quot;-unlock\&quot;, and optionally \&quot;-noblock\&quot;&quot;;
+    int operation = 0, fd, i, ret, sigret = TCL_OK;
+    int errnoval = 0;
+    int oshared = 0, oexclusive = 0, ounlock = 0, onoblock = 0, retry = 0;
+#if defined(HAVE_LOCKF) &amp;&amp; !defined(HAVE_FLOCK)
+    off_t curpos;
+#endif
+    char *res;
+    Tcl_Channel channel;
+    ClientData handle;
+    struct sigaction sa_oldalarm, sa_alarm;
+
+    if (objc &lt; 3 || objc &gt; 4) {
+        Tcl_WrongNumArgs(interp, 1, objv, &quot;channelId switches&quot;);
+        return TCL_ERROR;
+    }
+
+    if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL) {
+        Tcl_SetResult(interp, &quot;error getting channel, result was NULL&quot;, TCL_STATIC);
+        return TCL_ERROR;
+    }
+
+    if (Tcl_GetChannelHandle(channel, TCL_READABLE | TCL_WRITABLE, &amp;handle) != TCL_OK) {
+        Tcl_SetResult(interp, &quot;error getting channel handle&quot;, TCL_STATIC);
+        return TCL_ERROR;
+    }
+    fd = (int)(intptr_t)handle;
+
+    for (i = 2; i &lt; objc; i++) {
+        char *arg = Tcl_GetString(objv[i]);
+        if (!strcmp(arg, &quot;-shared&quot;)) {
+            oshared = 1;
+        }
+        else if (!strcmp(arg, &quot;-exclusive&quot;)) {
+            oexclusive = 1;
+        }
+        else if (!strcmp(arg, &quot;-unlock&quot;)) {
+            ounlock = 1;
+        }
+        else if (!strcmp(arg, &quot;-noblock&quot;)) {
+            onoblock = 1;
+        }
+    }
+
+    /* verify the arguments */
+
+    if ((oshared + oexclusive + ounlock) != 1) {
+        /* only one of the options should have been specified */
+        Tcl_SetResult(interp, (void *) &amp;errorstr, TCL_STATIC);
+        return TCL_ERROR;
+    }
+
+    if (onoblock &amp;&amp; ounlock) {
+        /* should not be specified together */
+        Tcl_SetResult(interp, &quot;-noblock cannot be used with -unlock&quot;, TCL_STATIC);
+        return TCL_ERROR;
+    }
+
+    /* (re-)enable SIGALRM so we can use alarm(3) to specify a timeout for the
+     * locking, do some Tcl signal processing and restart the locking to solve
+     * #43388. */
+    memset(&amp;sa_alarm, 0, sizeof(struct sigaction));
+    sigemptyset(&amp;sa_alarm.sa_mask);
+    sa_alarm.sa_flags = 0; /* explicitly don't specify SA_RESTART, we want the
+                              following alarm(3) to interrupt the locking. */
+    sa_alarm.sa_handler = alarmHandler;
+    sigaction(SIGALRM, &amp;sa_alarm, &amp;sa_oldalarm);
+
+    do {
+        /* use a delay of one second */
+        retry = 0;
+        alarmReceived = 0;
+        alarm(1);
+#if HAVE_FLOCK
+        /* prefer flock if present */
+        if (oshared) {
+            operation |= LOCK_SH;
+        }
+
+        if (oexclusive) {
+            operation |= LOCK_EX;
+        }
+
+        if (ounlock) {
+            operation |= LOCK_UN;
+        }
+
+        if (onoblock) {
+            operation |= LOCK_NB;
+        }
+
+        ret = flock(fd, operation);
+        if (ret == -1) {
+            errnoval = errno;
+        }
+#else
+#if HAVE_LOCKF
+        if (ounlock) {
+            operation = F_ULOCK;
+        }
+
+        /* lockf semantics don't map to shared locks. */
+        if (oshared || oexclusive) {
+            if (onoblock) {
+                operation = F_TLOCK;
+            }
+            else {
+                operation = F_LOCK;
+            }
+        }
+
+        curpos = lseek(fd, 0, SEEK_CUR);
+        if (curpos == -1) {
+            Tcl_SetResult(interp, (void *) &quot;Seek error&quot;, TCL_STATIC);
+            return TCL_ERROR;
+        }
+
+        ret = lockf(fd, operation, 0); /* lock entire file */
+        if (ret == -1) {
+            errnoval = errno;
+        }
+
+        curpos = lseek(fd, curpos, SEEK_SET);
+        if (curpos == -1) {
+            Tcl_SetResult(interp, (void *) &quot;Seek error&quot;, TCL_STATIC);
+            return TCL_ERROR;
+        }
+#else
+#error no available locking implementation
+#endif /* HAVE_LOCKF */
+#endif /* HAVE_FLOCK */
+        /* disable the alarm timer */
+        alarm(0);
+
+        if (ret == -1) {
+            if (oshared || oexclusive) {
+                if (!onoblock &amp;&amp; alarmReceived &amp;&amp; errnoval == EINTR) {
+                    /* We were trying to lock, the lock was supposed to block,
+                     * it failed with EINTR and we processed a SIGALRM. This
+                     * probably means the call was interrupted by the timer.
+                     * Call Tcl signal processing functions and try again. */
+                    if (Tcl_AsyncReady()) {
+                        sigret = Tcl_AsyncInvoke(interp, TCL_OK);
+                        if (sigret != TCL_OK) {
+                            break;
+                        }
+                    }
+                    retry = 1;
+                    continue;
+                }
+
+                if (onoblock &amp;&amp; errnoval == EAGAIN) {
+                    /* The lock wasn't supposed to block, and the lock wasn't
+                     * successful because the lock is taken. On some systems
+                     * EAGAIN == EWOULDBLOCK, but let's play it safe. */
+                    errnoval = EWOULDBLOCK;
+                }
+            }
+        }
+    } while (retry);
+
+    /* Restore the previous handler for SIGALRM */
+    sigaction(SIGALRM, &amp;sa_oldalarm, NULL);
+
+    if (sigret != TCL_OK) {
+        /* We received a signal that raised an error. The file hasn't been
+         * locked. */
+        return sigret;
+    }
+
+    if (ret != 0) {
+        switch (errnoval) {
+            case EAGAIN:
+                res = &quot;EAGAIN&quot;;
+                break;
+            case EBADF:
+                res = &quot;EBADF&quot;;
+                break;
+            case EINVAL:
+                res = &quot;EINVAL&quot;;
+                break;
+            case EOPNOTSUPP:
+                res = &quot;EOPNOTSUPP&quot;;
+                break;
+            default:
+                res = strerror(errno);
+                break;
+        }
+        Tcl_SetResult(interp, (void *) res, TCL_STATIC);
+        return TCL_ERROR;
+    }
+    return TCL_OK;
+}
</ins></span></pre></div>
<a id="trunkbasesrcpextlib10advflockhfromrev137292trunkbasesrcpextlib10flockh"></a>
<div class="copfile"><h4>Copied: trunk/base/src/pextlib1.0/adv-flock.h (from rev 137292, trunk/base/src/pextlib1.0/flock.h) (0 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/adv-flock.h                                (rev 0)
+++ trunk/base/src/pextlib1.0/adv-flock.h        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+/*
+ * adv-flock.h
+ * $Id$
+ *
+ * Copyright (c) 2009 The MacPorts Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The MacPorts Project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+int AdvFlockCmd(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[]);
</ins></span></pre></div>
<a id="trunkbasesrcpextlib10flockc"></a>
<div class="delfile"><h4>Deleted: trunk/base/src/pextlib1.0/flock.c (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/flock.c        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/pextlib1.0/flock.c        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -1,256 +0,0 @@
</span><del>-/*
- * flock.c
- * $Id$
- *
- * Copyright (c) 2009 The MacPorts Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of The MacPorts Project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if HAVE_CONFIG_H
-#include &lt;config.h&gt;
-#endif
-
-/* needed to get struct sigaction on some platforms */
-#define _XOPEN_SOURCE 500L
-/* the above hides flock on OS X without _DARWIN_C_SOURCE */
-#define _DARWIN_C_SOURCE
-
-#if HAVE_SYS_FILE_H
-#include &lt;sys/file.h&gt;
-#endif
-
-#include &lt;errno.h&gt;
-#include &lt;inttypes.h&gt;
-#include &lt;signal.h&gt;
-#include &lt;string.h&gt;
-#include &lt;unistd.h&gt;
-
-#include &lt;tcl.h&gt;
-
-#include &quot;flock.h&quot;
-
-static volatile int alarmReceived = 0;
-
-static void alarmHandler(int sig UNUSED) {
-    alarmReceived = 1;
-}
-
-int
-FlockCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
-    static const char errorstr[] = &quot;use one of \&quot;-shared\&quot;, \&quot;-exclusive\&quot;, or \&quot;-unlock\&quot;, and optionally \&quot;-noblock\&quot;&quot;;
-    int operation = 0, fd, i, ret, sigret = TCL_OK;
-    int errnoval = 0;
-    int oshared = 0, oexclusive = 0, ounlock = 0, onoblock = 0, retry = 0;
-#if defined(HAVE_LOCKF) &amp;&amp; !defined(HAVE_FLOCK)
-    off_t curpos;
-#endif
-    char *res;
-    Tcl_Channel channel;
-    ClientData handle;
-    struct sigaction sa_oldalarm, sa_alarm;
-
-    if (objc &lt; 3 || objc &gt; 4) {
-        Tcl_WrongNumArgs(interp, 1, objv, &quot;channelId switches&quot;);
-        return TCL_ERROR;
-    }
-
-    if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL) {
-        Tcl_SetResult(interp, &quot;error getting channel, result was NULL&quot;, TCL_STATIC);
-        return TCL_ERROR;
-    }
-
-    if (Tcl_GetChannelHandle(channel, TCL_READABLE | TCL_WRITABLE, &amp;handle) != TCL_OK) {
-        Tcl_SetResult(interp, &quot;error getting channel handle&quot;, TCL_STATIC);
-        return TCL_ERROR;
-    }
-    fd = (int)(intptr_t)handle;
-
-    for (i = 2; i &lt; objc; i++) {
-        char *arg = Tcl_GetString(objv[i]);
-        if (!strcmp(arg, &quot;-shared&quot;)) {
-            oshared = 1;
-        }
-        else if (!strcmp(arg, &quot;-exclusive&quot;)) {
-            oexclusive = 1;
-        }
-        else if (!strcmp(arg, &quot;-unlock&quot;)) {
-            ounlock = 1;
-        }
-        else if (!strcmp(arg, &quot;-noblock&quot;)) {
-            onoblock = 1;
-        }
-    }
-
-    /* verify the arguments */
-
-    if ((oshared + oexclusive + ounlock) != 1) {
-        /* only one of the options should have been specified */
-        Tcl_SetResult(interp, (void *) &amp;errorstr, TCL_STATIC);
-        return TCL_ERROR;
-    }
-
-    if (onoblock &amp;&amp; ounlock) {
-        /* should not be specified together */
-        Tcl_SetResult(interp, &quot;-noblock cannot be used with -unlock&quot;, TCL_STATIC);
-        return TCL_ERROR;
-    }
-
-    /* (re-)enable SIGALRM so we can use alarm(3) to specify a timeout for the
-     * locking, do some Tcl signal processing and restart the locking to solve
-     * #43388. */
-    memset(&amp;sa_alarm, 0, sizeof(struct sigaction));
-    sigemptyset(&amp;sa_alarm.sa_mask);
-    sa_alarm.sa_flags = 0; /* explicitly don't specify SA_RESTART, we want the
-                              following alarm(3) to interrupt the locking. */
-    sa_alarm.sa_handler = alarmHandler;
-    sigaction(SIGALRM, &amp;sa_alarm, &amp;sa_oldalarm);
-
-    do {
-        /* use a delay of one second */
-        retry = 0;
-        alarmReceived = 0;
-        alarm(1);
-#if HAVE_FLOCK
-        /* prefer flock if present */
-        if (oshared) {
-            operation |= LOCK_SH;
-        }
-
-        if (oexclusive) {
-            operation |= LOCK_EX;
-        }
-
-        if (ounlock) {
-            operation |= LOCK_UN;
-        }
-
-        if (onoblock) {
-            operation |= LOCK_NB;
-        }
-
-        ret = flock(fd, operation);
-        if (ret == -1) {
-            errnoval = errno;
-        }
-#else
-#if HAVE_LOCKF
-        if (ounlock) {
-            operation = F_ULOCK;
-        }
-
-        /* lockf semantics don't map to shared locks. */
-        if (oshared || oexclusive) {
-            if (onoblock) {
-                operation = F_TLOCK;
-            }
-            else {
-                operation = F_LOCK;
-            }
-        }
-
-        curpos = lseek(fd, 0, SEEK_CUR);
-        if (curpos == -1) {
-            Tcl_SetResult(interp, (void *) &quot;Seek error&quot;, TCL_STATIC);
-            return TCL_ERROR;
-        }
-
-        ret = lockf(fd, operation, 0); /* lock entire file */
-        if (ret == -1) {
-            errnoval = errno;
-        }
-
-        curpos = lseek(fd, curpos, SEEK_SET);
-        if (curpos == -1) {
-            Tcl_SetResult(interp, (void *) &quot;Seek error&quot;, TCL_STATIC);
-            return TCL_ERROR;
-        }
-#else
-#error no available locking implementation
-#endif /* HAVE_LOCKF */
-#endif /* HAVE_FLOCK */
-        /* disable the alarm timer */
-        alarm(0);
-
-        if (ret == -1) {
-            if (oshared || oexclusive) {
-                if (!onoblock &amp;&amp; alarmReceived &amp;&amp; errnoval == EINTR) {
-                    /* We were trying to lock, the lock was supposed to block,
-                     * it failed with EINTR and we processed a SIGALRM. This
-                     * probably means the call was interrupted by the timer.
-                     * Call Tcl signal processing functions and try again. */
-                    if (Tcl_AsyncReady()) {
-                        sigret = Tcl_AsyncInvoke(interp, TCL_OK);
-                        if (sigret != TCL_OK) {
-                            break;
-                        }
-                    }
-                    retry = 1;
-                    continue;
-                }
-
-                if (onoblock &amp;&amp; errnoval == EAGAIN) {
-                    /* The lock wasn't supposed to block, and the lock wasn't
-                     * successful because the lock is taken. On some systems
-                     * EAGAIN == EWOULDBLOCK, but let's play it safe. */
-                    errnoval = EWOULDBLOCK;
-                }
-            }
-        }
-    } while (retry);
-
-    /* Restore the previous handler for SIGALRM */
-    sigaction(SIGALRM, &amp;sa_oldalarm, NULL);
-
-    if (sigret != TCL_OK) {
-        /* We received a signal that raised an error. The file hasn't been
-         * locked. */
-        return sigret;
-    }
-
-    if (ret != 0) {
-        switch (errnoval) {
-            case EAGAIN:
-                res = &quot;EAGAIN&quot;;
-                break;
-            case EBADF:
-                res = &quot;EBADF&quot;;
-                break;
-            case EINVAL:
-                res = &quot;EINVAL&quot;;
-                break;
-            case EOPNOTSUPP:
-                res = &quot;EOPNOTSUPP&quot;;
-                break;
-            default:
-                res = strerror(errno);
-                break;
-        }
-        Tcl_SetResult(interp, (void *) res, TCL_STATIC);
-        return TCL_ERROR;
-    }
-    return TCL_OK;
-}
</del></span></pre></div>
<a id="trunkbasesrcpextlib10flockh"></a>
<div class="delfile"><h4>Deleted: trunk/base/src/pextlib1.0/flock.h (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/flock.h        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/pextlib1.0/flock.h        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -1,33 +0,0 @@
</span><del>-/*
- * flock.h
- * $Id$
- *
- * Copyright (c) 2009 The MacPorts Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of The MacPorts Project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-int FlockCmd(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[]);
</del></span></pre></div>
<a id="trunkbasesrcport10portutiltcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/port1.0/portutil.tcl (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/port1.0/portutil.tcl        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/port1.0/portutil.tcl        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -1817,10 +1817,10 @@
</span><span class="cx"> 
</span><span class="cx">     set fd [open $statefile a+]
</span><span class="cx">     if {![tbool ports_dryrun]} {
</span><del>-        if {[catch {flock $fd -exclusive -noblock} result]} {
</del><ins>+        if {[catch {adv-flock $fd -exclusive -noblock} result]} {
</ins><span class="cx">             if {&quot;$result&quot; == &quot;EAGAIN&quot;} {
</span><span class="cx">                 ui_notice &quot;Waiting for lock on $statefile&quot;
</span><del>-                flock $fd -exclusive
</del><ins>+                adv-flock $fd -exclusive
</ins><span class="cx">             } elseif {&quot;$result&quot; == &quot;EOPNOTSUPP&quot;} {
</span><span class="cx">                 # Locking not supported, just return
</span><span class="cx">                 return $fd
</span></span></pre></div>
<a id="trunkbasesrcregistry20registrytcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/registry2.0/registry.tcl (138164 => 138165)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/registry2.0/registry.tcl        2015-06-30 20:47:25 UTC (rev 138164)
+++ trunk/base/src/registry2.0/registry.tcl        2015-06-30 20:58:44 UTC (rev 138165)
</span><span class="lines">@@ -395,10 +395,10 @@
</span><span class="cx">         }
</span><span class="cx">         set lockfd [::open $lockpath w]
</span><span class="cx">     }
</span><del>-    if {[catch {flock $lockfd -exclusive -noblock} result]} {
</del><ins>+    if {[catch {adv-flock $lockfd -exclusive -noblock} result]} {
</ins><span class="cx">         if {$result eq &quot;EAGAIN&quot;} {
</span><span class="cx">             ui_msg &quot;Waiting for lock on $lockpath&quot;
</span><del>-            flock $lockfd -exclusive
</del><ins>+            adv-flock $lockfd -exclusive
</ins><span class="cx">         } elseif {$result eq &quot;EOPNOTSUPP&quot;} {
</span><span class="cx">             # Locking not supported, just return
</span><span class="cx">             ui_debug &quot;flock not supported, not locking registry&quot;
</span><span class="lines">@@ -420,7 +420,7 @@
</span><span class="cx">     }
</span><span class="cx">     if {[info exists lockfd]} {
</span><span class="cx">         # not much point trying to handle errors
</span><del>-        catch {flock $lockfd -unlock}
</del><ins>+        catch {adv-flock $lockfd -unlock}
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>