2 * Copyright (C) 2007 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.
24 #include <sys/socket.h>
25 #include <cutils/logger.h>
29 #define LOG_FILE_DIR "/dev/log/"
31 void write_log_entry(int fd
, struct logger_entry
*buf
);
33 void log_service(int fd
, void *cookie
)
35 /* get the name of the log filepath to read */
36 char * log_filepath
= cookie
;
38 /* open the log file. */
39 int logfd
= unix_open(log_filepath
, O_RDONLY
);
44 // temp buffer to read the entries
45 unsigned char buf
[LOGGER_ENTRY_MAX_LEN
+ 1] __attribute__((aligned(4)));
46 struct logger_entry
*entry
= (struct logger_entry
*) buf
;
51 ret
= unix_read(logfd
, entry
, LOGGER_ENTRY_MAX_LEN
);
53 if (errno
== EINTR
|| errno
== EAGAIN
)
55 // perror("logcat read");
59 // fprintf(stderr, "read: Unexpected EOF!\n");
63 /* NOTE: driver guarantees we read exactly one full entry */
65 entry
->msg
[entry
->len
] = '\0';
67 write_log_entry(fd
, entry
);
75 /* returns the full path to the log file in a newly allocated string */
76 char * get_log_file_path(const char * log_name
) {
77 char *log_device
= malloc(strlen(LOG_FILE_DIR
) + strlen(log_name
) + 1);
79 strcpy(log_device
, LOG_FILE_DIR
);
80 strcat(log_device
, log_name
);
86 /* prints one log entry into the file descriptor fd */
87 void write_log_entry(int fd
, struct logger_entry
*buf
)
89 size_t size
= sizeof(struct logger_entry
) + buf
->len
;
91 writex(fd
, buf
, size
);