file lock

svn path=/trunk/boinc/; revision=749
This commit is contained in:
David Anderson 2002-12-16 23:51:33 +00:00
parent 234d704761
commit ceaa3521e8
9 changed files with 57 additions and 8 deletions

View File

@ -2625,3 +2625,15 @@ David Dec 11 2002
tools_work.html
test/
*wu
David Dec 13 2002
- use lock file mechanism to prevent multiple instances of
core client from running in same directory
configure
configure.in
client/
file_names.h
main.C
lib/
util.C,y

View File

@ -48,3 +48,4 @@ extern bool is_account_file(char*);
#define STDERR_FILE_NAME "stderr.txt"
#define STDOUT_FILE_NAME "stdout.txt"
#define TIME_TESTS_FILE_NAME "time_tests.xml"
#define LOCK_FILE_NAME "lockfile"

View File

@ -75,6 +75,10 @@ int main(int argc, char** argv) {
int retval;
setbuf(stdout, 0);
if (lock_file(LOCK_FILE_NAME)) {
fprintf(stderr, "Another copy of BOINC is already running\n");
exit(1);
}
read_log_flags();
gstate.parse_cmdline(argc, argv);
retval = gstate.init();

12
configure vendored
View File

@ -1888,8 +1888,6 @@ main() {
r.ru_majflt = r.ru_minflt = 0;
switch (fork()) {
case 0: /* Child. */
/* Unless we actually _do_ something, the kernel sometimes doesn't chalk up any system time to this process. */
if(fork()) { i = 123; wait(NULL); } else { i = 234; exit(0); }
sleep(1); /* Give up the CPU. */
_exit(0);
case -1: _exit(0); /* What can we do? */
@ -1901,7 +1899,7 @@ main() {
}
}
EOF
if { (eval echo configure:1905: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
if { (eval echo configure:1903: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_wait3_rusage=yes
else
@ -1923,15 +1921,15 @@ EOF
fi
for ac_func in gethostname gettimeofday mkdir select socket strstr uname
for ac_func in gethostname gettimeofday mkdir select socket strstr uname lockf flock
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:1930: checking for $ac_func" >&5
echo "configure:1928: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 1935 "configure"
#line 1933 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@ -1954,7 +1952,7 @@ $ac_func();
; return 0; }
EOF
if { (eval echo configure:1958: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:1956: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else

View File

@ -40,6 +40,6 @@ dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
AC_CHECK_FUNCS(gethostname gettimeofday mkdir select socket strstr uname)
AC_CHECK_FUNCS(gethostname gettimeofday mkdir select socket strstr uname lockf flock)
AC_OUTPUT(RSAEuro/source/Makefile apps/Makefile db/Makefile sched/Makefile lib/Makefile tools/Makefile Makefile api/Makefile)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -20,6 +20,9 @@
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _WIN32
#include <time.h>
@ -147,3 +150,29 @@ int parse_command_line(char* p, char** argv) {
return argc;
}
int lock_file(char* filename) {
int retval;
// some systems have both!
#ifdef HAVE_LOCKF
int lock = open(filename, O_WRONLY|O_CREAT, 0644);
retval = lockf(lock, F_TLOCK, 1);
// must leave fd open
#else
#ifdef HAVE_FLOCK
int lock = open(filename, O_WRONLY|O_CREAT, 0644);
retval = flock(lock, LOCK_EX|LOCK_NB);
#endif
#endif
#ifdef _WIN32
HANDLE hfile = CreateFile(
filename, GENERIC_WRITE,
0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
);
if (hfile == INVALID_HANDLE_VALUE) retval = 1;
else retval = 0;
#endif
return retval;
}

View File

@ -23,6 +23,7 @@ extern int double_to_ydhms (double x, int smallest_timescale, char *buf);
extern double dtime();
extern void boinc_sleep( int seconds );
extern int parse_command_line( char *, char ** );
extern int lock_file(char*);
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))

4
todo
View File

@ -1,3 +1,7 @@
write garbage collector
prevent 2 core clients from running at once
support for HTTP and SOCKS proxies
make get_local_ip_addr() work in all cases
est_time_to_completion doesn't work for non-running tasks