#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
+#include <sys/syscall.h>
#include <unistd.h>
#include <pkgmgr-info.h>
#include "package_manager_internal.h"
#define MAX_SMACK_LABEL_LEN 255
+#define gettid() syscall(SYS_gettid)
typedef struct _foreach_pkg_context_ {
package_manager_package_info_cb callback;
char uid[10];
char *session;
const char *privilege;
+ unsigned long pid = getpid();
+ unsigned long tid = gettid();
- fd = open("/proc/self/attr/current", O_RDONLY);
+ if (pid == tid) {
+ fd = open("/proc/self/attr/current", O_RDONLY);
+ } else {
+ // Check current thread smack label.
+ char path[256] = { 0 };
+ pid = tid;
+ snprintf(path, sizeof(path), "/proc/%lu/attr/current", tid);
+ fd = open(path, O_RDONLY);
+ }
if (fd < 0) {
LOGE("open failed: %d", errno);
return PACKAGE_MANAGER_ERROR_IO_ERROR;
}
snprintf(uid, 10, "%d", getuid());
- session = cynara_session_from_pid(getpid());
+ session = cynara_session_from_pid(pid);
switch (type) {
case PRIVILEGE_PACKAGE_MANAGER_INFO: