X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fshared%2Fwait_op.c;h=927891d9dfe2afedc9208074a4ced970d43fd732;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=3e98d05eede0be3bb50655a448939d9a683d1c1e;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/shared/wait_op.c b/src/shared/wait_op.c old mode 100755 new mode 100644 index 3e98d05..927891d --- a/src/shared/wait_op.c +++ b/src/shared/wait_op.c @@ -1,5 +1,3 @@ -/* @(#) $Id$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -9,32 +7,28 @@ * Foundation */ - #include "shared.h" + #define LOCK_LOOP 5 -int __wait_lock = 0; +static int __wait_lock = 0; -/* Creates global lock */ + +/* Create global lock */ void os_setwait() { FILE *fp = NULL; - /* For same threads. */ + /* For same threads */ __wait_lock = 1; - - if(isChroot()) - { + if (isChroot()) { fp = fopen(WAIT_FILE, "w"); - } - else - { + } else { fp = fopen(WAIT_FILE_PATH, "w"); } - if(fp) - { + if (fp) { fprintf(fp, "l"); fclose(fp); } @@ -42,97 +36,83 @@ void os_setwait() return; } - -/* Removes global lock */ +/* Remove global lock */ void os_delwait() { __wait_lock = 0; - - if(isChroot()) - { + + if (isChroot()) { unlink(WAIT_FILE); - } - else - { + } else { unlink(WAIT_FILE_PATH); } return; } - - /* Check for the wait file. If present, wait. * Works as a simple inter process lock (only the main * process is allowed to lock). */ -#ifdef WIN32 +#ifdef WIN32 void os_wait() { - if(!__wait_lock) + if (!__wait_lock) { return; + } - - /* Wait until the lock is gone. */ + /* Wait until the lock is gone */ verbose(WAITING_MSG, __local_name); - while(1) - { - if(!__wait_lock) + while (1) { + if (!__wait_lock) { break; + } - /* Sleep LOCK_LOOP seconds and check it lock is gone. */ + /* Sleep LOCK_LOOP seconds and check if lock is gone */ sleep(LOCK_LOOP); } - verbose(WAITING_FREE, __local_name); return; } -#else +#else /* !WIN32 */ void os_wait() { struct stat file_status; - - /* If the wait file is not present, keep going. - */ - if(isChroot()) - { - if(stat(WAIT_FILE, &file_status) == -1) + /* If the wait file is not present, keep going */ + if (isChroot()) { + if (stat(WAIT_FILE, &file_status) == -1) { return; - } - else - { - if(stat(WAIT_FILE_PATH, &file_status) == -1) + } + } else { + if (stat(WAIT_FILE_PATH, &file_status) == -1) { return; + } } - - /* Wait until the lock is gone. */ + /* Wait until the lock is gone */ verbose(WAITING_MSG, __local_name); - while(1) - { - if(isChroot()) - { - if(stat(WAIT_FILE, &file_status) == -1) + while (1) { + if (isChroot()) { + if (stat(WAIT_FILE, &file_status) == -1) { break; - } - else - { - if(stat(WAIT_FILE_PATH, &file_status) == -1) + } + } else { + if (stat(WAIT_FILE_PATH, &file_status) == -1) { break; + } } - /* Sleep LOCK_LOOP seconds and check it lock is gone. */ + /* Sleep LOCK_LOOP seconds and check if lock is gone */ sleep(LOCK_LOOP); } verbose(WAITING_FREE, __local_name); return; } -#endif +#endif /* !WIN32 */ -/* EOF */