X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;ds=sidebyside;f=src%2Fshared%2Fwait_op.c;h=927891d9dfe2afedc9208074a4ced970d43fd732;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=53bc664ab8282834dcc1eea770a00dcdcfdb913c;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b;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 53bc664..927891d --- a/src/shared/wait_op.c +++ b/src/shared/wait_op.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/shared/wait_op.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -10,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); } @@ -43,25 +36,19 @@ 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). @@ -69,71 +56,63 @@ void os_delwait() #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 */