Skip to content

Commit

Permalink
Merge pull request #507 from jjnicola/flock
Browse files Browse the repository at this point in the history
Use flock to lock the feed lock file.
  • Loading branch information
mattmundell committed May 18, 2020
2 parents 6a91cfb + fca4091 commit d85e340
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Drop http feed sync. [#478](https://github.com/greenbone/openvas/pull/478)
- Add aligned summary to log at scan end. [#496](https://github.com/greenbone/openvas/pull/496)
- Unify log messages about start/end of scan and of hosts. [#500](https://github.com/greenbone/openvas/pull/500)
- Use flock to lock the feed lock file. [#507](https://github.com/greenbone/openvas/pull/507)

### Fixed
- Improve signal handling when update vhosts list. [#425](https://github.com/greenbone/openvas/pull/425)
Expand Down
28 changes: 10 additions & 18 deletions tools/greenbone-nvt-sync.in
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,6 @@ do_feedversion () {
fi
}

create_feed_lock_file ()
{
if [ -f $OPENVAS_RUN_DIR/feed-update.lock ] ; then
log_warning "Another process related to the feed update is already running"
FEED_LOCKED=1
else
touch $OPENVAS_RUN_DIR/feed-update.lock
FEED_LOCKED=0
fi
}

do_sync ()
{
do_self_test
Expand All @@ -513,13 +502,16 @@ do_sync ()
then
log_write "Feed is already current, skipping synchronization."
else
create_feed_lock_file
if [ $FEED_LOCKED -eq 1 ] ; then
exit 1
fi

sync_nvts
rm $OPENVAS_RUN_DIR/feed-update.lock
(
flock -n 9
if [ $? -eq 1 ] ; then
log_warning "Another process related to the feed update is already running"
exit 1
fi
date > $OPENVAS_RUN_DIR/feed-update.lock
sync_nvts
echo -n $OPENVAS_RUN_DIR/feed-update.lock
)9>$OPENVAS_RUN_DIR/feed-update.lock
fi
}

Expand Down

0 comments on commit d85e340

Please sign in to comment.