/*
- * Copyright (C) 2014 Intel Corporation.
+ * Copyright (C) 2014-2015 Intel Corporation.
*/
#include <stdio.h>
#include <dlfcn.h>
#include <pthread.h>
#include <errno.h>
+#include <signal.h>
#include <hardware/sensors.h>
#include <utils/Log.h>
fprintf(f, "event: step_detector=%10.2f\n", e->data[0]);
break;
case SENSOR_TYPE_STEP_COUNTER:
- fprintf(f, "event: step_detector=%llu\n",
+ fprintf(f, "event: step_counter=%llu\n",
(unsigned long long)e->u64.step_counter);
break;
}
}
}
+static void sig_pipe(int sig)
+{
+ client = NULL;
+}
+
static void *run_sensors_thread(void *arg __attribute((unused)))
{
+
+ signal(SIGPIPE, sig_pipe);
+
switch (dev->version) {
case SENSORS_DEVICE_API_VERSION_0_1:
default:
} else if (!strcmp(argv[0], "poll")) {
pthread_mutex_lock(&client_mutex);
+ if (client)
+ fclose(client);
client = f;
pthread_mutex_unlock(&client_mutex);
.msg_controllen = sizeof(cmsg_buffer),
};
FILE *f =NULL;
+ struct cmsghdr *cmsg;
conn = accept(sock, NULL, NULL);
if (conn < 0) {
continue;
}
- while (1) {
- struct cmsghdr *cmsg;
-
- err = recvmsg(conn, &msg, 0);
- if (err < 0) {
- ALOGE("error in recvmsg: %s", strerror(errno));
- break;
- }
-
- if (err == 0)
- break;
+ err = recvmsg(conn, &msg, 0);
+ if (err < 0) {
+ ALOGE("error in recvmsg: %s", strerror(errno));
+ close(conn);
+ continue;
+ }
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
- cmsg = CMSG_NXTHDR(&msg,cmsg)) {
- if (cmsg->cmsg_level == SOL_SOCKET
- && cmsg->cmsg_type == SCM_RIGHTS) {
- int *fd = (int *)CMSG_DATA(cmsg);
- f = fdopen(*fd, "w");
- break;
- }
- }
+ if (err == 0)
+ continue;
- if (data_buff[err - 1] != 0) {
- ALOGE("command is not NULL terminated\n");
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg,cmsg)) {
+ if (cmsg->cmsg_level == SOL_SOCKET
+ && cmsg->cmsg_type == SCM_RIGHTS) {
+ int *fd = (int *)CMSG_DATA(cmsg);
+ f = fdopen(*fd, "w");
break;
}
+ }
- err = dispatch_cmd(data_buff, f);
- if (err < 0) {
- ALOGE("error dispatching command: %d", err);
- break;
- }
+ if (data_buff[err - 1] != 0) {
+ ALOGE("command is not NULL terminated\n");
+ close(conn);
+ continue;
+ }
- /* send ack */
- if (!err)
- write(conn, data_buff, 1);
+ err = dispatch_cmd(data_buff, f);
+ if (err < 0) {
+ ALOGE("error dispatching command: %d", err);
+ close(conn);
+ continue;
}
- pthread_mutex_lock(&client_mutex);
- client = NULL;
- pthread_mutex_unlock(&client_mutex);
+ /* send ack */
+ if (!err) {
+ write(conn, data_buff, 1);
+ fclose(f);
+ }
- fclose(f); close(conn);
+ close(conn);
}
}
int main(int argc, char **argv)
{
- char cmd[1024], *tmp;
+ char cmd[1024];
int sock, i;
struct iovec buff = {
.iov_base = cmd,