mirror of
https://github.com/openNDS/openNDS.git
synced 2026-05-04 03:01:32 -04:00
Merge pull request #411 from nodogsplash/ndsctl-fix
ndsctl: prevent deadlock with multiple concurrent instances
This commit is contained in:
@@ -681,6 +681,12 @@ config_read(const char *filename)
|
||||
char line[MAX_BUF], *s, *p1, *p2;
|
||||
int linenum = 0, opcode, value;
|
||||
struct stat sb;
|
||||
char lockfile[] = "/tmp/ndsctl.lock";
|
||||
|
||||
//Remove ndsctl lock file if it exists
|
||||
if (fd = fopen(lockfile, "r")) {
|
||||
remove(lockfile);
|
||||
}
|
||||
|
||||
debug(LOG_INFO, "Reading configuration file '%s'", filename);
|
||||
|
||||
|
||||
18
src/ndsctl.c
18
src/ndsctl.c
@@ -161,6 +161,21 @@ ndsctl_do(const char *socket, const struct argument *arg, const char *param)
|
||||
char request[128];
|
||||
int len, rlen;
|
||||
int ret;
|
||||
char lockfile[] = "/tmp/ndsctl.lock";
|
||||
FILE *fd;
|
||||
|
||||
setlogmask(LOG_UPTO (LOG_NOTICE));
|
||||
|
||||
if (fd = fopen(lockfile, "r")) {
|
||||
openlog ("ndsctl", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||
syslog (LOG_NOTICE, "ndsctl is locked by another process - try again later...");
|
||||
closelog ();
|
||||
fclose(fd);
|
||||
return -1;
|
||||
} else {
|
||||
//Create lock
|
||||
fd = fopen(lockfile, "w");
|
||||
}
|
||||
|
||||
sock = connect_to_server(socket);
|
||||
if (sock < 0) {
|
||||
@@ -206,7 +221,8 @@ ndsctl_do(const char *socket, const struct argument *arg, const char *param)
|
||||
|
||||
shutdown(sock, 2);
|
||||
close(sock);
|
||||
|
||||
fclose(fd);
|
||||
remove(lockfile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user