aboutsummaryrefslogtreecommitdiff
path: root/libarmep/service.c
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-10-06 20:04:42 +0800
committerAndy Green <andy.green@linaro.org>2012-10-15 07:37:49 +0800
commit68d6c70d6b330941a5f22a35269d63d9d920064a (patch)
treeae26a7615239a3a67b30bb7d80e99dbee8e33a92 /libarmep/service.c
parente1d63c1dfceef029bff15eda57fce6255bd159eb (diff)
introduce aepd
Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'libarmep/service.c')
-rw-r--r--libarmep/service.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/libarmep/service.c b/libarmep/service.c
index c8d0208..2f85cff 100644
--- a/libarmep/service.c
+++ b/libarmep/service.c
@@ -563,8 +563,6 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[])
loop = 1;
- signal(SIGINT, sighandler);
-
init_interpolation();
/*
@@ -583,6 +581,10 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[])
sprintf(semname, "linaro.aep.%u\n", getpid());
aep_context->semaphore = sem_open(semname, O_CREAT | O_RDWR, 0600, 0);
+ if (aep_context->semaphore == SEM_FAILED) {
+ fprintf(stderr, "Failed to open sem %s\n", semname);
+ return -1;
+ }
/* fork off aep service loop */
@@ -590,6 +592,8 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[])
if (n)
return n;
+ signal(SIGINT, sighandler);
+
/*
* child process runs independently
* fills the named pipe fifo with sample packets
@@ -598,12 +602,16 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[])
if (argv)
strcpy(argv[0] + strlen(argv[0]), " - AEP server");
- aep_context->semaphore = sem_open(semname, O_CREAT | O_RDWR, 0600, 0);
+ aep_context->semaphore = sem_open(semname, O_RDWR, 0600, 0);
+ if (aep_context->semaphore == SEM_FAILED) {
+ fprintf(stderr, "Child failed to open sem %s\n", semname);
+ return -1;
+ }
aep_context->aep_shared->finished = 0;
aep_context->poll_timeout_ms = 10;
- while (!aep_context->aep_shared->finished) {
+ while (!aep_context->aep_shared->finished && loop && getppid() != 1) {
n = poll(aep_context->pollfds, aep_context->count_pollfds, aep_context->poll_timeout_ms);
if (n < 0)
@@ -674,6 +682,8 @@ struct aep_result * aep_wait_for_next_result(struct aep_context *aep_context)
if (aep_shared->tail == aep_shared->head)
return NULL;
+// fprintf(stderr, "%d %d, ", aep_shared->tail, aep_shared->head);
+
return &aep_shared->aep_result[aep_shared->tail];
}