summaryrefslogtreecommitdiff
path: root/xpp/astribank_is_starting.c
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-10-21 14:30:32 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2009-10-21 14:30:32 +0000
commit939ffb7577ce08dfc552ce0c112e9d51fd2b4519 (patch)
treeb109d414522a83530be7999b0aa9d13a61f5c739 /xpp/astribank_is_starting.c
parentee453cb6ce6863f1b3f87888bf4572d1f6455cb3 (diff)
Fix XPP_HOTPLUG_DAHDI: logic; end of init.d script
'Hotplug mode' was introduced in r7335. * The logic in the script was broken. - Negative logic is not such a grand idea to start with. * Interactive invocation of init.d ends when expected and not sooner. This change makes waitfor_xpds wait longer. Rather than waiting for all the Astribanks to load, it will now wait until the initialization of dahdi from the Astribanks hook script is run. This allows running e.g.: /etc/init.d/dahdi start; /etc/init.d/asterisk start It also means that 'astribank_is_starting' is actually used as a semaphore and not only as stamp file. As before, those changes have no effect if hotplug mode is not explicitly enabled (setting 'XPP_HOTPLUG_DAHDI=yes' in init.conf). git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@7409 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/astribank_is_starting.c')
-rw-r--r--xpp/astribank_is_starting.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/xpp/astribank_is_starting.c b/xpp/astribank_is_starting.c
index 3018904..9a1552b 100644
--- a/xpp/astribank_is_starting.c
+++ b/xpp/astribank_is_starting.c
@@ -10,10 +10,13 @@
static char *progname;
static const key_t key_astribanks = 0xAB11A0;
static int debug;
+static int verbose;
+static int timeout_seconds = 60;
+
static void usage(void)
{
- fprintf(stderr, "Usage: %s [-d] [-a] [-r]\n", progname);
+ fprintf(stderr, "Usage: %s [-d] [-t <seconds>] [-a|-r|-w]\n", progname);
exit(1);
}
@@ -41,6 +44,8 @@ static int absem_touch(void)
}
if(debug)
fprintf(stderr, "%s: touched absem\n", progname);
+ if(verbose)
+ printf("Astribanks initialization is starting\n");
return 0;
}
@@ -63,6 +68,47 @@ static int absem_remove(void)
}
if(debug)
fprintf(stderr, "%s: removed absem\n", progname);
+ if(verbose)
+ printf("Astribanks initialization is done\n");
+ return 0;
+}
+
+static int absem_wait(void)
+{
+ int absem;
+ struct sembuf sops;
+ long now;
+ long start_wait;
+ struct timespec timeout;
+
+ if((absem = absem_get(0)) < 0) {
+ perror(__FUNCTION__);
+ return absem;
+ }
+ sops.sem_num = 0;
+ sops.sem_op = -1;
+ sops.sem_flg = 0;
+ start_wait = time(NULL);
+ timeout.tv_sec = timeout_seconds;
+ timeout.tv_nsec = 0;
+ if(semtimedop(absem, &sops, 1, &timeout) < 0) {
+ switch(errno) {
+ case EIDRM: /* Removed -- OK */
+ break;
+ case EAGAIN: /* Timeout -- Report */
+ fprintf(stderr, "Astribanks waiting timed out\n");
+ return -errno;
+ default: /* Unexpected errors */
+ perror("semop");
+ return -errno;
+ }
+ /* fall-thgough */
+ }
+ now = time(NULL);
+ if(debug)
+ fprintf(stderr, "%s: waited on absem %d seconds\n", progname, now - start_wait);
+ if(verbose)
+ printf("Finished after %d seconds\n", now - start_wait);
return 0;
}
@@ -77,17 +123,20 @@ static int absem_detected(void)
}
if(debug)
fprintf(stderr, "%s: absem exists\n", progname);
+ if(verbose)
+ printf("Astribanks are initializing...\n");
return 0;
}
int main(int argc, char *argv[])
{
- const char options[] = "darh";
+ const char options[] = "dvarwt:h";
int val;
progname = argv[0];
while (1) {
int c;
+ int t;
c = getopt (argc, argv, options);
if (c == -1)
@@ -97,6 +146,19 @@ int main(int argc, char *argv[])
case 'd':
debug++;
break;
+ case 'v':
+ verbose++;
+ break;
+ case 't':
+ t = atoi(optarg);
+ if(t <= 0) {
+ fprintf(stderr,
+ "%s: -t expect a positive number of seconds: '%s'\n",
+ progname, optarg);
+ usage();
+ }
+ timeout_seconds = t;
+ break;
case 'a':
if((val = absem_touch()) < 0) {
fprintf(stderr, "%s: Add failed: %d\n", progname, val);
@@ -109,6 +171,12 @@ int main(int argc, char *argv[])
return 1;
}
return 0;
+ case 'w':
+ if((val = absem_wait()) < 0) {
+ fprintf(stderr, "%s: Wait failed: %d\n", progname, val);
+ return 1;
+ }
+ return 0;
case 'h':
default:
fprintf(stderr, "Unknown option '%c'\n", c);