diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-08-13 15:15:49 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-08-13 15:15:49 +0000 |
commit | a114167f3ee6db22217d70a48267871ee08e6c4b (patch) | |
tree | 681330f32689007ff556b2d3372a391b840f812d /xpp | |
parent | abe5babe4742bf03b49971407b82ec3bc02fb14c (diff) |
xpp: Add astribank_is_starting:
astribank_is_running is used to tell when we may have an Astribank that
is initializing (and may be re-enumerating and thus not listed as a
device).
It uses a semaphore as we can always write to one and we can't always
write to a file.
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6987 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp')
-rw-r--r-- | xpp/Makefile | 6 | ||||
-rw-r--r-- | xpp/astribank_is_starting.c | 120 | ||||
-rwxr-xr-x | xpp/waitfor_xpds | 12 | ||||
-rw-r--r-- | xpp/xpp_fxloader | 3 |
4 files changed, 139 insertions, 2 deletions
diff --git a/xpp/Makefile b/xpp/Makefile index 111bb6d..921416f 100644 --- a/xpp/Makefile +++ b/xpp/Makefile @@ -65,8 +65,9 @@ TARGETS += fpga_load \ astribank_tool \ astribank_hexload \ astribank_allow \ + astribank_is_starting \ test_parse -PROG_INSTALL += fpga_load astribank_tool astribank_hexload astribank_allow +PROG_INSTALL += fpga_load astribank_tool astribank_hexload astribank_allow astribank_is_starting endif ifneq (,$(PERLLIBDIR)) PROG_INSTALL += $(PERL_SCRIPTS) @@ -113,6 +114,9 @@ astribank_tool: $(ABTOOL_OBJS) astribank_allow: $(ABALLOW_OBJS) $(CC) -L. -o $@ $(ABALLOW_OBJS) $(EXTRA_LIBS) $(USB_LIB) +astribank_is_starting: astribank_is_starting.o + $(CC) -L. -o $@ $^ $(EXTRA_LIBS) + fpga_load.o: CFLAGS+=-D_GNU_SOURCE # We use memrchr() test_parse: test_parse.o hexfile.o diff --git a/xpp/astribank_is_starting.c b/xpp/astribank_is_starting.c new file mode 100644 index 0000000..3018904 --- /dev/null +++ b/xpp/astribank_is_starting.c @@ -0,0 +1,120 @@ +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> +#include <errno.h> +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static char *progname; +static const key_t key_astribanks = 0xAB11A0; +static int debug; + +static void usage(void) +{ + fprintf(stderr, "Usage: %s [-d] [-a] [-r]\n", progname); + exit(1); +} + +static int absem_get(int createit) +{ + int flags = (createit) ? IPC_CREAT | 0644 : 0; + int absem; + + if((absem = semget(key_astribanks, 1, flags)) < 0) + absem = -errno; + return absem; +} + +static int absem_touch(void) +{ + int absem; + + if((absem = absem_get(1)) < 0) { + perror(__FUNCTION__); + return absem; + } + if(semctl(absem, 0, SETVAL, 0) < 0) { + perror("SETVAL"); + return -errno; + } + if(debug) + fprintf(stderr, "%s: touched absem\n", progname); + return 0; +} + +static int absem_remove(void) +{ + int absem; + + if((absem = absem_get(0)) < 0) { + if(absem == -ENOENT) { + if(debug) + fprintf(stderr, "%s: absem already removed\n", progname); + return 0; + } + perror(__FUNCTION__); + return absem; + } + if(semctl(absem, 0, IPC_RMID, 0) < 0) { + perror("RMID"); + return -errno; + } + if(debug) + fprintf(stderr, "%s: removed absem\n", progname); + return 0; +} + +static int absem_detected(void) +{ + int absem; + + if((absem = absem_get(0)) < 0) { + if(debug) + fprintf(stderr, "%s: absem does not exist\n", progname); + return absem; + } + if(debug) + fprintf(stderr, "%s: absem exists\n", progname); + return 0; +} + +int main(int argc, char *argv[]) +{ + const char options[] = "darh"; + int val; + + progname = argv[0]; + while (1) { + int c; + + c = getopt (argc, argv, options); + if (c == -1) + break; + + switch (c) { + case 'd': + debug++; + break; + case 'a': + if((val = absem_touch()) < 0) { + fprintf(stderr, "%s: Add failed: %d\n", progname, val); + return 1; + } + return 0; + case 'r': + if((val = absem_remove()) < 0) { + fprintf(stderr, "%s: Remove failed: %d\n", progname, val); + return 1; + } + return 0; + case 'h': + default: + fprintf(stderr, "Unknown option '%c'\n", c); + usage(); + } + } + val = absem_detected(); + return (val == 0) ? 0 : 1; +} diff --git a/xpp/waitfor_xpds b/xpp/waitfor_xpds index 1e213eb..26a6ab5 100755 --- a/xpp/waitfor_xpds +++ b/xpp/waitfor_xpds @@ -40,7 +40,14 @@ if ! dahdi_hardware="`which dahdi_hardware 2>/dev/null`"; then echo >&2 "$0: Missing dahdi_hardware" exit 0 fi -if [ "`$dahdi_hardware | grep xpp_usb`" = "" ]; then +if ! astribank_is_starting="`which astribank_is_starting 2>/dev/null`"; then + echo >&2 "$0: Missing astribank_is_starting" + exit 0 +fi +if [ "`$dahdi_hardware | grep xpp_usb`" != "" ]; then + astribank_is_starting -a +fi +if ! astribank_is_starting; then exit 0 fi @@ -70,3 +77,6 @@ do oldab="$ab" cat $ab done + +# Handled astribanks +astribank_is_starting -r diff --git a/xpp/xpp_fxloader b/xpp/xpp_fxloader index ea159de..dac5910 100644 --- a/xpp/xpp_fxloader +++ b/xpp/xpp_fxloader @@ -257,6 +257,9 @@ usage() { echo "$0 help : this text." } +# We have a potential astribank +astribank_is_starting -a + ######################### ## ## Manual run |