Merge branch 'zms_socket_lock' into multi-server
This commit is contained in:
commit
6d605362fc
|
@ -286,6 +286,23 @@ void StreamBase::openComms()
|
|||
{
|
||||
if ( connkey > 0 )
|
||||
{
|
||||
|
||||
snprintf( sock_path_lock, sizeof(sock_path_lock), "%s/zms-%06d.lock", config.path_socks, connkey);
|
||||
|
||||
lock_fd = open(sock_path_lock, O_CREAT|O_WRONLY, S_IRUSR | S_IWUSR);
|
||||
if (lock_fd <= 0 || flock(lock_fd, LOCK_SH|LOCK_NB) != 0)
|
||||
{
|
||||
Error("Unable to lock sock lock file %s: %s", sock_path_lock, strerror(errno) );
|
||||
|
||||
close(lock_fd);
|
||||
lock_fd = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( 1, "We have obtained a read lock on %s fd: %d", sock_path_lock, lock_fd);
|
||||
}
|
||||
|
||||
|
||||
sd = socket( AF_UNIX, SOCK_DGRAM, 0 );
|
||||
if ( sd < 0 )
|
||||
{
|
||||
|
@ -321,6 +338,11 @@ void StreamBase::closeComms()
|
|||
{
|
||||
unlink( loc_sock_path );
|
||||
}
|
||||
if (lock_fd > 0)
|
||||
{
|
||||
loc_sock_path[0] = '\0';
|
||||
close(lock_fd); //close it rather than unlock it incase it got deleted.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ protected:
|
|||
struct sockaddr_un loc_addr;
|
||||
char rem_sock_path[PATH_MAX];
|
||||
struct sockaddr_un rem_addr;
|
||||
char sock_path_lock[PATH_MAX];
|
||||
int lock_fd;
|
||||
|
||||
protected:
|
||||
bool paused;
|
||||
|
@ -127,6 +129,7 @@ public:
|
|||
|
||||
connkey = 0;
|
||||
sd = -1;
|
||||
lock_fd = 0;
|
||||
memset( &loc_sock_path, 0, sizeof(loc_sock_path) );
|
||||
memset( &loc_addr, 0, sizeof(loc_addr) );
|
||||
memset( &rem_sock_path, 0, sizeof(rem_sock_path) );
|
||||
|
|
Loading…
Reference in New Issue