bool readonly)
{
DIR *dir;
- struct dirent *file_info = NULL;
+ struct dirent *file_info;
int ret;
char file_path[BUFSZE];
char err_buf[BUFSZE];
_D("The directory for preloaded pkgs doesn't exist");
return 0;
} else {
- _E("Failed to access the [%s] because [%s]", directory,
+ _E("Failed to access [%s]: [%s]", directory,
strerror_r(errno, err_buf, sizeof(err_buf)));
return -1;
}
pid_t pid = fork();
if (pid == 0) {
execl(backend, backend, "-i", file_path,
- readonly? "--preload":"--preload-rw",
+ readonly ? "--preload" : "--preload-rw",
(char *)NULL);
} else if (pid < 0) {
_E("failed to fork and execute %s!", backend);
waitpid(pid, &status, 0);
}
- /* remove a file after installation */
- /* keep rw packages for factory-reset */
+ /* remove a file after installation,
+ * keep rw packages for factory-reset
+ */
if (readonly) {
ret = remove(file_path);
if (ret < 0) {
- _E("Failed to remove the file [%s] because [%s]",
+ _E("Failed to remove [%s]: [%s]",
file_path, strerror_r(errno, err_buf,
sizeof(err_buf)));
closedir(dir);
static int _is_authorized(uid_t uid)
{
/* install_preload_pkg should be called by as root privilege. */
- if ((uid_t) OWNER_ROOT == uid)
+ if ((uid_t)OWNER_ROOT == uid)
return 1;
else
return 0;
{
char err_msg[BUFSZE];
int handle = -1;
- int ret = 0;
+ int ret;
if (!_is_authorized(getuid())) {
_E("You are not an authorized user!");
_E("Failed to open error file");
return -1;
}
- snprintf(err_msg, sizeof(err_msg),
- "install_preload_pkg error!\n");
+ snprintf(err_msg, sizeof(err_msg), "install_preload_pkg error!\n");
ret = write(handle, err_msg, strlen(err_msg));
if (ret == -1)
_E("Failed to write an error message. (%d)", errno);