diff --git a/Makefile b/Makefile index eea390e..144b292 100644 --- a/Makefile +++ b/Makefile @@ -168,7 +168,7 @@ $(LTZ_SO): $(LTZ_SO_OBJS) $(CC) $(CFLAGS) -shared -Wl,-soname,$(LTZ_SO).$(LTZ_SO_MAJOR_VER).$(LTZ_SO_MINOR_VER) -o $@ $^ -lm dahdi_cfg: $(LTZ_A) -dahdi_cfg: LIBS+=-lm +dahdi_cfg: LIBS+=-lm -lpthread dahdi_pcap: $(CC) $(CFLAGS) dahdi_pcap.c -lpcap -o $@ $< diff --git a/dahdi_cfg.c b/dahdi_cfg.c index 0de1091..c86eaac 100644 --- a/dahdi_cfg.c +++ b/dahdi_cfg.c @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include #include @@ -794,7 +796,7 @@ static int setfiftysixkhdlc(char *keyword, char *args) return 0; } -static void apply_fiftysix(void) +static int apply_fiftysix(void) { int x; int rate; @@ -808,7 +810,7 @@ static void apply_fiftysix(void) fprintf(stderr, "Couldn't open /dev/dahdi/channel: %s\n", strerror(errno)); - exit(-1); + return -1; } if (ioctl(chanfd, DAHDI_SPECIFY, &x)) { @@ -829,6 +831,7 @@ static void apply_fiftysix(void) } close(chanfd); } + return 0; } static int setechocan(char *keyword, char *args) @@ -1530,6 +1533,9 @@ int main(int argc, char *argv[]) char *buf; char *key, *value; int x,found; + sem_t *lock = SEM_FAILED; + const char *SEM_NAME = "dahdi_cfg"; + int exit_code = 0; while((c = getopt(argc, argv, "fthc:vsd::C:S:")) != -1) { switch(c) { @@ -1656,6 +1662,20 @@ finish: printf("About to open Master device\n"); fflush(stdout); } + + lock = sem_open(SEM_NAME, O_CREAT, O_RDWR, 1); + if (SEM_FAILED == lock) { + error("Unable to create 'dahdi_cfg' mutex.\n"); + exit_code = 1; + goto release_sem; + } + + if (-1 == sem_wait(lock)) { + error("Failed to wait for dahdi_cfg mutex.\n"); + exit_code = 1; + goto release_sem; + } + for (x=0;x