return 0;
}
-int __make_size_info_file(char *req_key, long long size)
+static int __write_size_info_fifo(char *req_key, long long size)
{
- FILE *file;
- int fd = 0;
- char buf[MAX_PKG_BUF_LEN];
- char info_file[MAX_PKG_BUF_LEN];
+ int fd;
+ char buf[MAX_LONGLONG_LENGTH];
+ char fifo_path[PATH_MAX];
+ int ret = 0;
if (req_key == NULL)
return -1;
- snprintf(info_file, sizeof(info_file), "%s/%s", PKG_SIZE_INFO_PATH,
- req_key);
- LOGD("File path = (%s), size = (%lld)", info_file, size);
+ snprintf(fifo_path, sizeof(fifo_path), "/tmp/pkgmgr/%s", req_key);
+ LOGD("fifo path = (%s), size = (%lld)", fifo_path, size);
- file = fopen(info_file, "w");
- if (file == NULL) {
- LOGE("Couldn't open the file %s", info_file);
+ fd = open(fifo_path, O_WRONLY);
+ if (fd < 0) {
+ LOGE("failed to open, errno(%d)", errno);
return -1;
}
snprintf(buf, MAX_LONGLONG_LENGTH, "%lld", size);
- fwrite(buf, 1, strlen(buf), file);
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ LOGE("failed to write, ret(%d), errno(%d)", ret, errno);
+ close(fd);
+ return -1;
+ }
- fflush(file);
- fd = fileno(file);
- fsync(fd);
- fclose(file);
+ close(fd);
return 0;
}
long long size = 0;
pkgmgr_installer *pi;
pkg_size_info_t info = {0, };
+ int fifo_exist = 0;
/* argv has bellowed meaning */
/* argv[1] = pkgid */
/* argv[3] = caller uid */
/* argv[5] = req_key */
/* argv[7] = target uid */
+ /* argv[8] = sync flag */
if (argv[1] == NULL) {
LOGE("pkgid is NULL");
caller_uid = atoi(argv[3]);
req_key = argv[5];
+ if (argv[8] && !strcmp("--sync", argv[8])) {
+ fifo_exist = 1;
+ }
+
pi = pkgmgr_installer_new();
if (pi == NULL) {
LOGE("failed to create installer");
+ if (fifo_exist) {
+ if (__write_size_info_fifo(req_key, -1) < 0)
+ LOGE("failed to write to fifo");
+ }
return -1;
}
pkgmgr_installer_receive_request(pi, argc, argv);
target_uid = pkgmgr_installer_get_uid(pi);
LOGD("start get size : [pkgid=%s, request type=%d, target_uid=%d, "
- "caller_uid=%d]",
- pkgid, get_type, target_uid, caller_uid);
+ "caller_uid=%d, fifo_exist=%d]",
+ pkgid, get_type, target_uid, caller_uid, fifo_exist);
switch (get_type) {
case PM_GET_TOTAL_SIZE:
if (ret < 0)
LOGW("failed to get size of some path");
size = info.app_size + info.data_size + info.cache_size;
- ret = __make_size_info_file(req_key, size);
break;
case PM_GET_DATA_SIZE:
/* send result to file */
if (ret < 0)
LOGW("failed to get size of some path");
size = info.data_size + info.cache_size;
- ret = __make_size_info_file(req_key, size);
break;
case PM_GET_ALL_PKGS:
/* send result to file */
LOGE("failed to get all packages");
else
size = info.app_size + info.data_size + info.cache_size;
- ret = __make_size_info_file(req_key, size);
break;
case PM_GET_SIZE_INFO:
/* send each result to signal */
pi, target_uid);
if (ret < 0)
LOGE("failed to get all packages");
- ret = __make_size_info_file(req_key, 0);
break;
case PM_GET_PKG_SIZE_INFO:
/* send result to signal */
/* always send a result */
ret = __send_result_to_signal(pi, req_key,
pkgid, &info);
- ret = __make_size_info_file(req_key, size);
break;
case PM_GET_TOTAL_PKG_SIZE_INFO:
/* send result to signal */
/* always send a result */
ret = __send_result_to_signal(pi, req_key,
PKG_SIZE_INFO_TOTAL, &info);
- ret = __make_size_info_file(req_key, size);
break;
default:
ret = -1;
break;
}
+ if (fifo_exist) {
+ if (__write_size_info_fifo(req_key, size) < 0)
+ LOGE("failed to write to fifo");
+ }
+
/* Only PM_GET_SIZE_INFO type needs 'end' signal,
* because the result is sent on each package's calculation.
* So, the callback needs to know the end of results.