If remote debugging is activated, lock a file to tell the IDE we are alive.
[INTERPRETER] * NEW: If remote debugging is activated, lock a file to tell the IDE we are alive.
This commit is contained in:
parent
3771b2df30
commit
4681142810
3 changed files with 45 additions and 31 deletions
|
@ -112,6 +112,7 @@ void DEBUG_init(void)
|
|||
const char *dir;
|
||||
const char *fifo_name;
|
||||
int pid;
|
||||
int fd_lock;
|
||||
|
||||
if (!EXEC_debug)
|
||||
{
|
||||
|
@ -128,6 +129,13 @@ void DEBUG_init(void)
|
|||
if (!pid)
|
||||
return;
|
||||
|
||||
sprintf(COMMON_buffer, DEBUG_FIFO_PATTERN, getuid(), pid, "lock");
|
||||
fd_lock = open(COMMON_buffer, O_CREAT | O_WRONLY | O_CLOEXEC, 0666);
|
||||
if (fd_lock < 1)
|
||||
return;
|
||||
|
||||
STREAM_lock_all_fd(fd_lock); // On program end, that file will be automatically closed, and the lock released.
|
||||
|
||||
EXEC_debug = TRUE;
|
||||
EXEC_fifo = TRUE;
|
||||
|
||||
|
|
|
@ -1872,11 +1872,38 @@ int STREAM_handle(STREAM *stream)
|
|||
return (-1);
|
||||
}
|
||||
|
||||
int STREAM_lock_all_fd(int fd)
|
||||
{
|
||||
int64_t pos;
|
||||
|
||||
pos = lseek(fd, 0, SEEK_CUR);
|
||||
if (pos < 0)
|
||||
return errno;
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) < 0)
|
||||
return errno;
|
||||
|
||||
#ifdef F_TLOCK
|
||||
|
||||
if (lockf(fd, F_TLOCK, 0))
|
||||
return errno;
|
||||
|
||||
#else
|
||||
|
||||
return ENOTSUP;
|
||||
|
||||
#endif
|
||||
|
||||
if (lseek(fd, pos, SEEK_SET) < 0)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool STREAM_lock_all(STREAM *stream)
|
||||
{
|
||||
int64_t pos;
|
||||
int fd;
|
||||
int err;
|
||||
|
||||
if (STREAM_is_closed(stream))
|
||||
THROW(E_CLOSED);
|
||||
|
@ -1884,37 +1911,15 @@ bool STREAM_lock_all(STREAM *stream)
|
|||
fd = STREAM_handle(stream);
|
||||
if (fd < 0)
|
||||
return TRUE;
|
||||
|
||||
err = STREAM_lock_all_fd(fd);
|
||||
|
||||
if (err == 0)
|
||||
return FALSE;
|
||||
if (err == EAGAIN)
|
||||
return TRUE;
|
||||
|
||||
pos = lseek(fd, 0, SEEK_CUR);
|
||||
if (pos < 0)
|
||||
goto __ERROR;
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) < 0)
|
||||
goto __ERROR;
|
||||
|
||||
#ifdef F_TLOCK
|
||||
|
||||
if (lockf(fd, F_TLOCK, 0))
|
||||
{
|
||||
if (errno == EAGAIN)
|
||||
return TRUE;
|
||||
else
|
||||
goto __ERROR;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ERROR_warning("locking is not implemented");
|
||||
|
||||
#endif
|
||||
|
||||
if (lseek(fd, pos, SEEK_SET) < 0)
|
||||
goto __ERROR;
|
||||
|
||||
return FALSE;
|
||||
|
||||
__ERROR:
|
||||
THROW_SYSTEM(errno, NULL);
|
||||
THROW_SYSTEM(err, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -264,6 +264,7 @@ void STREAM_load(const char *path, char **buffer, int *len);
|
|||
bool STREAM_map(const char *path, char **paddr, int *plen);
|
||||
void STREAM_unmap(char *addr, int len);
|
||||
|
||||
int STREAM_lock_all_fd(int fd);
|
||||
bool STREAM_lock_all(STREAM *stream);
|
||||
|
||||
#define STREAM_is_closed(_stream) ((_stream)->type == NULL)
|
||||
|
|
Loading…
Reference in a new issue