#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
#include <signal.h>
#include <grp.h>
typedef struct {
uid_t uid;
char *cmd;
+ int pid;
} pkgcmd_data;
/*
}
#endif
-static void __make_pid_info_file(char *req_key, int pid, uid_t uid)
-{
- FILE* file;
- int fd;
- int ret;
- char buf[MAX_PKG_TYPE_LEN] = {0};
- char info_file[PATH_MAX] = {'\0'};
- struct passwd pwd;
- struct passwd *pwd_result;
-
- if (req_key == NULL)
- return;
-
- ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
- if (ret != 0 || pwd_result == NULL) {
- ERR("get uid failed(%d) for user(%d)", ret, uid);
- return;
- }
- DBG("uid(%d), gid(%d)", uid, pwd.pw_gid);
-
- snprintf(info_file, PATH_MAX, "/tmp/pkgmgr/%s", req_key);
-
- DBG("info_path(%s)", info_file);
- file = fopen(info_file, "w");
- if (file == NULL) {
- ERR("Couldn't open the file(%s)", info_file);
- return;
- }
-
- snprintf(buf, MAX_PKG_TYPE_LEN, "%d\n", pid);
- fwrite(buf, 1, strlen(buf), file);
-
- fflush(file);
- fd = fileno(file);
- if (fchmod(fd, 0777) < 0)
- ERR("chmod failed, errno(%d)", errno);
- if (fchown(fd, uid, pwd.pw_gid) < 0)
- ERR("chown failed, errno(%d)", errno);
- fsync(fd);
- fclose(file);
-}
-
static int __kill_app(char *appid, uid_t uid)
{
int ret;
char *appid;
char *exec;
int ret;
- int pid = -1;
pkgcmd_data *pdata = (pkgcmd_data *)user_data;
if (handle == NULL) {
}
if (strcmp(pdata->cmd, "kill") == 0) {
- pid = __check_app(appid, pdata->uid);
- if (pid > 0)
+ pdata->pid = __check_app(appid, pdata->uid);
+ if (pdata->pid > 0)
ret = __kill_app(appid, pdata->uid);
} else if (strcmp(pdata->cmd, "check") == 0) {
- pid = __check_app(appid, pdata->uid);
+ pdata->pid = __check_app(appid, pdata->uid);
}
- __make_pid_info_file(pkgid, pid, pdata->uid);
-
return 0;
}
{
int ret;
pkgmgrinfo_pkginfo_h handle;
- pkgcmd_data *pdata = NULL;
+ pkgcmd_data *pdata;
ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid,
&handle);
if (ret < 0) {
ERR("Failed to get handle");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
return -1;
}
pdata = calloc(1, sizeof(pkgcmd_data));
if (pdata == NULL) {
ERR("memory alloc failed");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
return -1;
}
pdata->cmd = strdup("kill");
if (pdata->cmd == NULL) {
ERR("out of memory");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
free(pdata);
- pdata = NULL;
return -1;
}
pdata->uid = item->uid;
ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
__pkgcmd_app_cb, pdata, item->uid);
+
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
+
free(pdata->cmd);
free(pdata);
- pdata = NULL;
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_list() failed");
{
int ret;
pkgmgrinfo_pkginfo_h handle;
- pkgcmd_data *pdata = NULL;
+ pkgcmd_data *pdata;
ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid,
&handle);
if (ret < 0) {
ERR("Failed to get handle");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ERROR, 0));
return -1;
}
pdata = calloc(1, sizeof(pkgcmd_data));
if (pdata == NULL) {
ERR("memory alloc failed");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
return -1;
}
pdata->cmd = strdup("check");
if (pdata->cmd == NULL) {
ERR("out of memory");
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
free(pdata);
- pdata = NULL;
return -1;
}
pdata->uid = item->uid;
ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP,
__pkgcmd_app_cb, pdata, item->uid);
+
+ __return_value_to_caller(item->req_id,
+ g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid));
+
free(pdata->cmd);
free(pdata);
- pdata = NULL;
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
if (ret < 0) {
ERR("pkgmgrinfo_appinfo_get_list() failed");
" <arg type='u' name='uid' direction='in'/>"
" <arg type='s' name='pkgid' direction='in'/>"
" <arg type='i' name='ret' direction='out'/>"
+ " <arg type='i' name='pid' direction='out'/>"
" </method>"
" <method name='check'>"
" <arg type='u' name='uid' direction='in'/>"
" <arg type='s' name='pkgid' direction='in'/>"
" <arg type='i' name='ret' direction='out'/>"
+ " <arg type='i' name='pid' direction='out'/>"
" </method>"
" <method name='generate_license_request'>"
" <arg type='s' name='resp_data' direction='in'/>"
{
uid_t target_uid = (uid_t)-1;
char *pkgid = NULL;
+ char *reqkey = NULL;
g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
if (target_uid == (uid_t)-1 || pkgid == NULL) {
g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ECOMM));
+ g_variant_new("(ii)", PKGMGR_R_ECOMM, 0));
return -1;
}
- if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "default",
- pkgid, "")) {
+ reqkey = __generate_reqkey(pkgid);
+ if (reqkey == NULL) {
g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
return -1;
}
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_OK));
+ if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_KILL,
+ "default", pkgid, "")) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
+ return -1;
+ }
+
+ if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+ (gpointer)invocation))
+ ERR("reqkey already exists");
return 0;
}
{
uid_t target_uid = (uid_t)-1;
char *pkgid = NULL;
+ char *reqkey = NULL;
g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
if (target_uid == (uid_t)-1 || pkgid == NULL) {
g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ECOMM));
+ g_variant_new("(ii)", PKGMGR_R_ECOMM, 0));
return -1;
}
- if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "default",
- pkgid, "")) {
+ reqkey = __generate_reqkey(pkgid);
+ if (reqkey == NULL) {
g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+ g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
return -1;
}
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_OK));
+ if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK,
+ "default", pkgid, "")) {
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
+ return -1;
+ }
+
+ if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+ (gpointer)invocation))
+ ERR("reqkey already exists");
return 0;
}