Skip to content

Commit 1cf376e

Browse files
committed
Better lock opening (#14).
1 parent 0d7ee47 commit 1cf376e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

arx_control/aspCommon.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,16 @@ bool ATmega::open() {
9090

9191
return found;
9292
} else {
93-
_lock = sem_open(_sn.c_str(), O_CREAT, 0666, 1);
93+
mode_t omsk = umask(0);
94+
_lock = sem_open(_sn.c_str(), O_CREAT | O_EXCL, 0666, 1);
95+
umask(omsk);
9496
if( _lock == SEM_FAILED ) {
95-
_lock = NULL;
96-
return false;
97+
if( errno == EEXIST ) {
98+
_lock = sem_open(_sn.c_str(), 0);
99+
} else {
100+
_lock = NULL;
101+
return false;
102+
}
97103
}
98104

99105
double elapsed_time = 0.0;

0 commit comments

Comments
 (0)