2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/types.h>
21 #define LOG_TAG "ClatdController"
22 #include <cutils/log.h>
24 #include "ClatdController.h"
26 ClatdController::ClatdController() {
30 ClatdController::~ClatdController() {
33 int ClatdController::startClatd(char *interface) {
37 ALOGE("clatd already running");
42 ALOGD("starting clatd");
44 if ((pid = fork()) < 0) {
45 ALOGE("fork failed (%s)", strerror(errno));
50 char **args = (char **)malloc(sizeof(char *) * 4);
51 args[0] = (char *)"/system/bin/clatd";
52 args[1] = (char *)"-i";
56 if (execv(args[0], args)) {
57 ALOGE("execv failed (%s)", strerror(errno));
59 ALOGE("Should never get here!");
64 ALOGD("clatd started");
70 int ClatdController::stopClatd() {
72 ALOGE("clatd already stopped");
76 ALOGD("Stopping clatd");
78 kill(mClatdPid, SIGTERM);
79 waitpid(mClatdPid, NULL, 0);
82 ALOGD("clatd stopped");
87 bool ClatdController::isClatdStarted() {
92 waitpid_status = waitpid(mClatdPid, NULL, WNOHANG);
93 if(waitpid_status != 0) {
94 mClatdPid = 0; // child exited, don't call waitpid on it again
96 return waitpid_status == 0; // 0 while child is running