Reworked the file locking option as a command instead of as a
compile-time option. The behavior can now be controlled from within the program with "locking disable" or "locking enable".
This commit is contained in:
parent
6a78f4967e
commit
e4d1c29112
|
|
@ -54,6 +54,9 @@ void CmdPaintEraseButton();
|
||||||
|
|
||||||
extern Label *DefaultLabel;
|
extern Label *DefaultLabel;
|
||||||
|
|
||||||
|
/* See the "locking" command */
|
||||||
|
extern bool FileLocking;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
|
|
@ -527,7 +530,7 @@ CmdLoad(w, cmd)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function callback which continues the search through all cells for
|
* Function callback which continues the search through all cells for
|
||||||
* expansion/unexpansion.
|
* expansion/unexpansion, used by CmdLoad() above.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -538,6 +541,70 @@ keepGoing(use, clientdata)
|
||||||
return 0; /* keep the search going */
|
return 0; /* keep the search going */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* CmdLocking --
|
||||||
|
*
|
||||||
|
* Implement the "locking" command.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* locking [enable|disable]
|
||||||
|
*
|
||||||
|
* This command controls the behavior of file locking. If enabled, then
|
||||||
|
* every layout read from a .mag file will generate a file descriptor in
|
||||||
|
* the operating system, and the file will be held open for the duration
|
||||||
|
* of use. This is a fairly simple way of preventing two different
|
||||||
|
* processes of magic from attempting to write to the same .mag file.
|
||||||
|
* Generally speaking, the file locking should remain on at all times,
|
||||||
|
* and read/write behavior of any specific cell can be controlled with
|
||||||
|
* the "cellname writeable" command option. However, in some cases,
|
||||||
|
* layouts with many components may exceed the operating system's
|
||||||
|
* allotted number of open file descriptors, in which case the only real
|
||||||
|
* option is to disable file locking altogether using "locking disable".
|
||||||
|
*
|
||||||
|
* Results:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* Sets global boolean variable FileLocking.
|
||||||
|
*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
CmdLocking(w, cmd)
|
||||||
|
MagWindow *w;
|
||||||
|
TxCommand *cmd;
|
||||||
|
{
|
||||||
|
int option;
|
||||||
|
|
||||||
|
static char *cmdLockingYesNo[] = { "disable", "no", "false", "off", "0",
|
||||||
|
"enable", "yes", "true", "on", "1", 0 };
|
||||||
|
|
||||||
|
if (cmd->tx_argc <= 1)
|
||||||
|
{
|
||||||
|
#ifdef MAGIC_WRAPPER
|
||||||
|
/* Interpreter return value is the state of locking */
|
||||||
|
Tcl_SetResult(magicinterp, (FileLocking) ? "enabled" : "disabled",
|
||||||
|
TCL_VOLATILE);
|
||||||
|
#else
|
||||||
|
/* Print the status of file locking to the console */
|
||||||
|
TxPrintf("%s\n", (FileLocking) ? "enabled" : "disabled");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
option = Lookup(cmd->tx_argv[1], cmdLockingYesNo);
|
||||||
|
if (option < 0)
|
||||||
|
{
|
||||||
|
TxError("Unknown locking option \"%s\"\n", cmd->tx_argv[1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FileLocking = (option <= 4) ? FALSE : TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ extern void CmdDelete(), CmdDown(), CmdDrc(), CmdDrop(), CmdDump();
|
||||||
extern void CmdEdit(), CmdElement(), CmdErase(), CmdExpand(), CmdExtract();
|
extern void CmdEdit(), CmdElement(), CmdErase(), CmdExpand(), CmdExtract();
|
||||||
extern void CmdFeedback(), CmdFill(), CmdFindBox(), CmdFindLabel(), CmdFlush();
|
extern void CmdFeedback(), CmdFill(), CmdFindBox(), CmdFindLabel(), CmdFlush();
|
||||||
extern void CmdGetcell(), CmdGrid(), CmdIdentify();
|
extern void CmdGetcell(), CmdGrid(), CmdIdentify();
|
||||||
extern void CmdLabel(), CmdLoad();
|
extern void CmdLabel(), CmdLoad(), CmdLocking();
|
||||||
extern void CmdMove(), CmdNetlist(), CmdOrient(), CmdPaint(), CmdPath();
|
extern void CmdMove(), CmdNetlist(), CmdOrient(), CmdPaint(), CmdPath();
|
||||||
extern void CmdPlow(), CmdPolygon(), CmdPort(), CmdProperty();
|
extern void CmdPlow(), CmdPolygon(), CmdPort(), CmdProperty();
|
||||||
extern void CmdRandom(), CmdSave(), CmdScaleGrid(), CmdSee();
|
extern void CmdRandom(), CmdSave(), CmdScaleGrid(), CmdSee();
|
||||||
|
|
@ -369,6 +369,9 @@ DBWInitCommands()
|
||||||
WindAddCommand(DBWclientID,
|
WindAddCommand(DBWclientID,
|
||||||
"load [cellname] load a cell into a window",
|
"load [cellname] load a cell into a window",
|
||||||
CmdLoad, FALSE);
|
CmdLoad, FALSE);
|
||||||
|
WindAddCommand(DBWclientID,
|
||||||
|
"locking [enable|disable] enable or disable file locking",
|
||||||
|
CmdLocking, FALSE);
|
||||||
WindAddCommand(DBWclientID,
|
WindAddCommand(DBWclientID,
|
||||||
"move [dir [amount]] OR\n"
|
"move [dir [amount]] OR\n"
|
||||||
"move to x y move box and selection, either by amount\n\
|
"move to x y move box and selection, either by amount\n\
|
||||||
|
|
|
||||||
|
|
@ -6598,7 +6598,7 @@ if test $usingTcl ; then
|
||||||
# Find the version of "wish" that corresponds to TCL_EXEC_PREFIX
|
# Find the version of "wish" that corresponds to TCL_EXEC_PREFIX
|
||||||
# We really ought to run "ldd" to confirm that the linked libraries match.
|
# We really ought to run "ldd" to confirm that the linked libraries match.
|
||||||
|
|
||||||
if text "x${magic_with_wish_binary}" = "x" ; then
|
if test "x${magic_with_wish_binary}" = "x" ; then
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wish executable" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wish executable" >&5
|
||||||
$as_echo_n "checking for wish executable... " >&6; }
|
$as_echo_n "checking for wish executable... " >&6; }
|
||||||
for dir in \
|
for dir in \
|
||||||
|
|
@ -6844,15 +6844,8 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if test "x$enable_locking" = "xyes" ; then
|
if test "x$enable_locking" = "xno" ; then
|
||||||
case $target in
|
echo "File locking no longer set during configuration; ignoring option."
|
||||||
*cygwin*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
$as_echo "#define FILE_LOCKS 1" >>confdefs.h
|
|
||||||
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check whether --enable-calma was given.
|
# Check whether --enable-calma was given.
|
||||||
|
|
|
||||||
|
|
@ -705,7 +705,7 @@ if test $usingTcl ; then
|
||||||
# Find the version of "wish" that corresponds to TCL_EXEC_PREFIX
|
# Find the version of "wish" that corresponds to TCL_EXEC_PREFIX
|
||||||
# We really ought to run "ldd" to confirm that the linked libraries match.
|
# We really ought to run "ldd" to confirm that the linked libraries match.
|
||||||
|
|
||||||
if text "x${magic_with_wish_binary}" = "x" ; then
|
if test "x${magic_with_wish_binary}" = "x" ; then
|
||||||
AC_MSG_CHECKING([for wish executable])
|
AC_MSG_CHECKING([for wish executable])
|
||||||
for dir in \
|
for dir in \
|
||||||
${TK_EXEC_PREFIX}/bin \
|
${TK_EXEC_PREFIX}/bin \
|
||||||
|
|
@ -935,14 +935,8 @@ AC_ARG_ENABLE(locking,
|
||||||
[],
|
[],
|
||||||
[enable_locking=yes])
|
[enable_locking=yes])
|
||||||
|
|
||||||
if test "x$enable_locking" = "xyes" ; then
|
if test "x$enable_locking" = "xno" ; then
|
||||||
case $target in
|
echo "File locking no longer set during configuration; ignoring option."
|
||||||
*cygwin*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
AC_DEFINE(FILE_LOCKS)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(calma,
|
AC_ARG_ENABLE(calma,
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef FILE_LOCKS
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
@ -166,5 +164,3 @@ FILE *flock_open(filename, mode, is_locked)
|
||||||
done:
|
done:
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FILE_LOCKS */
|
|
||||||
|
|
|
||||||
42
utils/path.c
42
utils/path.c
|
|
@ -46,6 +46,8 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
||||||
static HashTable expansionTable;
|
static HashTable expansionTable;
|
||||||
static bool noTable = TRUE;
|
static bool noTable = TRUE;
|
||||||
|
|
||||||
|
bool FileLocking = TRUE;
|
||||||
|
|
||||||
/* Limit on how long a single file name may be: */
|
/* Limit on how long a single file name may be: */
|
||||||
|
|
||||||
#define MAXSIZE MAXPATHLEN
|
#define MAXSIZE MAXPATHLEN
|
||||||
|
|
@ -454,11 +456,10 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||||
p2 = file;
|
p2 = file;
|
||||||
if (PaExpand(&p2, &p1, MAXSIZE) < 0) return NULL;
|
if (PaExpand(&p2, &p1, MAXSIZE) < 0) return NULL;
|
||||||
|
|
||||||
#ifndef FILE_LOCKS
|
if (FileLocking)
|
||||||
return fopen(realName, mode);
|
return flock_open(realName, mode, is_locked);
|
||||||
#else
|
else
|
||||||
return flock_open(realName, mode, is_locked);
|
return fopen(realName, mode);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we were already given a full rooted file name,
|
/* If we were already given a full rooted file name,
|
||||||
|
|
@ -473,11 +474,11 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||||
{
|
{
|
||||||
(void) strncpy(realName, file, MAXSIZE-1);
|
(void) strncpy(realName, file, MAXSIZE-1);
|
||||||
realName[MAXSIZE-1] = '\0';
|
realName[MAXSIZE-1] = '\0';
|
||||||
#ifndef FILE_LOCKS
|
|
||||||
return fopen(realName, mode);
|
if (FileLocking)
|
||||||
#else
|
return flock_open(realName, mode, is_locked);
|
||||||
return flock_open(realName, mode, is_locked);
|
else
|
||||||
#endif
|
return fopen(realName, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now try going through the path, one entry at a time. */
|
/* Now try going through the path, one entry at a time. */
|
||||||
|
|
@ -485,11 +486,12 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||||
while (nextName(&path, file, realName, MAXSIZE) != NULL)
|
while (nextName(&path, file, realName, MAXSIZE) != NULL)
|
||||||
{
|
{
|
||||||
if (*realName == 0) continue;
|
if (*realName == 0) continue;
|
||||||
#ifndef FILE_LOCKS
|
|
||||||
f = fopen(realName, mode);
|
if (FileLocking)
|
||||||
#else
|
f = flock_open(realName, mode, is_locked);
|
||||||
f = flock_open(realName, mode, is_locked);
|
else
|
||||||
#endif
|
f = fopen(realName, mode);
|
||||||
|
|
||||||
if (f != NULL) return f;
|
if (f != NULL) return f;
|
||||||
|
|
||||||
// If any error other than "file not found" occurred,
|
// If any error other than "file not found" occurred,
|
||||||
|
|
@ -504,11 +506,11 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||||
if (library == NULL) return NULL;
|
if (library == NULL) return NULL;
|
||||||
while (nextName(&library, file, realName, MAXSIZE) != NULL)
|
while (nextName(&library, file, realName, MAXSIZE) != NULL)
|
||||||
{
|
{
|
||||||
#ifndef FILE_LOCKS
|
if (FileLocking)
|
||||||
f = fopen(realName, mode);
|
f = flock_open(realName, mode, is_locked);
|
||||||
#else
|
else
|
||||||
f = flock_open(realName, mode, is_locked);
|
f = fopen(realName, mode);
|
||||||
#endif
|
|
||||||
if (f != NULL) return f;
|
if (f != NULL) return f;
|
||||||
|
|
||||||
// If any error other than "file not found" occurred,
|
// If any error other than "file not found" occurred,
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,7 @@ extern bool StrIsNumeric(char *);
|
||||||
|
|
||||||
extern int SetNoisyBool(bool *, char *, FILE *);
|
extern int SetNoisyBool(bool *, char *, FILE *);
|
||||||
|
|
||||||
#ifdef FILE_LOCKS
|
|
||||||
extern FILE *flock_open();
|
extern FILE *flock_open();
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The following macro takes an integer and returns another integer that
|
/* The following macro takes an integer and returns another integer that
|
||||||
* is the same as the first except that all the '1' bits are turned off,
|
* is the same as the first except that all the '1' bits are turned off,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue