int fd;
fd = open("/dev/null", O_RDONLY);
- dup2(fd, 0);
+ if(fd >= 0)
+ {
+ dup2(fd, 0);
+ close(fd);
+ }
fd = open(DEBUG_LOGFILE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
if(fd < 0) {
fd = open("/dev/null", O_WRONLY);
- }
+ if(fd < 0)
+ return;
+ }
dup2(fd, 1);
dup2(fd, 2);
fprintf(stderr, "--- daemon starting (pid %d) ---\n", getpid());
+ close(fd);
}
#else
void initialize_log()
msg_t log;
// host log format xxx|length|str
- recvLen = recv(manager.host.control_socket, recvBuf, RECV_BUF_MAX, 0);
+ recvLen = recv(manager.host.control_socket, recvBuf, DA_MSG_MAX, 0);
if (recvLen > 0)
{
else if(events[i].data.fd == manager.host.data_socket)
{
char recvBuf[32];
- recvLen = recv(manager.host.data_socket, recvBuf, RECV_BUF_MAX, MSG_DONTWAIT);
+ recvLen = recv(manager.host.data_socket, recvBuf, 32, MSG_DONTWAIT);
if(recvLen == 0)
{ // close data socket
epoll_ctl(efd, EPOLL_CTL_DEL, manager.host.data_socket, NULL);
{
writeToPortfile(ERR_ALREADY_RUNNING);
LOGE("another instance of daemon is already running");
+ close(fd);
return -1;
}
+ close(fd);
return 0;
}
brightness_status = get_file_status(&brightnessfd, fullpath);
}
}
+ closedir(dir_info);
}
else
{
max_brightness = get_file_status(&maxbrightnessfd, fullpath);
}
}
+ closedir(dir_info);
}
else
{
if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
{
LOGE("Failed to read from " PROCMEMINFO "\n");
+ close(meminfo_fd);
return 0;
}
buf[num] = '\0';
}
#endif
- // any message before MSG_PID message arrived did not be sent to host
+ // do not send any message to host until MSG_PID message arrives
if(unlikely(pass == 0))
{
while(manager.target[index].initial_log == 0)
static void* samplingThread(void* data)
{
- int err, signo, i;
+ int err, signo, i, res;
int pidarray[MAX_TARGET_COUNT];
int pidcount;
sigset_t waitsigmask;
pidarray[pidcount++] = manager.target[i].pid;
}
- log.length = get_resource_info(log.data, DA_MSG_MAX, pidarray, pidcount);
- if(log.length >= 0)
+ res = get_resource_info(log.data, DA_MSG_MAX, pidarray, pidcount);
+ if(res >= 0)
{
log.type = MSG_RESOURCE;
+ log.length = res;
sendDataToHost(&log);
}
}
}
else
{
- // not happened
- LOGE("This should not be happend in sampling thread\n");
+ // never happen
+ LOGE("This should never happen in sampling thread\n");
}
}
if(setgroups(sizeof(groups) / sizeof(groups[0]), groups) != 0)
{
fprintf(stderr, "set groups failed errno: %d\n", errno);
+ close(fd);
exit(1);
}
}
+ close(fd);
}
int get_smack_label(const char* execpath, char* buffer, int buflen)
static int get_input_id(char* inputname)
{
static int query_cmd_type = 0; // 1 if /lib/udev/input_id, 2 if udevadm
- FILE* cmd_fp;
+ FILE* cmd_fp = NULL;
char buffer[BUF_SIZE];
char command[MAX_FILENAME];
int ret = -1;
{
query_cmd_type = 2;
}
- pclose(cmd_fp);
+ if(cmd_fp != NULL)
+ pclose(cmd_fp);
}
// make command string
ret = INPUT_ID_TOUCH;
}
- pclose(cmd_fp);
+ if(cmd_fp != NULL)
+ pclose(cmd_fp);
return ret;
}
dp = opendir("/sys/class/input");
- while((d = readdir(dp)) != NULL)
+ if(dp != NULL)
{
- if(!strncmp(d->d_name, "event", 5)) // start with "event"
+ while((d = readdir(dp)) != NULL)
{
- // event file
- if(input_id == get_input_id(d->d_name))
+ if(!strncmp(d->d_name, "event", 5)) // start with "event"
{
- sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
- dev[count].fd = open(dev[count].fileName, O_RDWR);
- count++;
+ // event file
+ if(input_id == get_input_id(d->d_name))
+ {
+ sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
+ dev[count].fd = open(dev[count].fileName, O_RDWR);
+ count++;
+ }
}
}
- }
-
- closedir(dp);
+ closedir(dp);
+ }
dev[count].fd = ARRAY_END; // end of input_dev array
}