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.
19 #include <sys/types.h>
22 #define LOG_TAG "ClatdController"
23 #include <cutils/log.h>
25 #include "ClatdController.h"
27 ClatdController::ClatdController() {
31 ClatdController::~ClatdController() {
34 int ClatdController::startClatd(char *interface) {
38 ALOGE("clatd already running");
43 ALOGD("starting clatd");
45 if ((pid = fork()) < 0) {
46 ALOGE("fork failed (%s)", strerror(errno));
51 char **args = (char **)malloc(sizeof(char *) * 4);
52 args[0] = (char *)"/system/bin/clatd";
53 args[1] = (char *)"-i";
57 if (execv(args[0], args)) {
58 ALOGE("execv failed (%s)", strerror(errno));
60 ALOGE("Should never get here!");
65 ALOGD("clatd started");
71 int ClatdController::stopClatd() {
73 ALOGE("clatd already not running");
77 ALOGD("Stopping clatd");
79 kill(mClatdPid, SIGTERM);
80 waitpid(mClatdPid, NULL, 0);
83 ALOGD("clatd stopped");
88 bool ClatdController::isClatdRunning() {
93 waitpid_status = waitpid(mClatdPid, NULL, WNOHANG);
94 if(waitpid_status != 0) {
95 // child exited or stopped, don't call waitpid on it again
98 return waitpid_status == 0; // 0 while child is running