summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoon.c.baek <joon.c.baek@samsung.com>2016-08-08 17:30:05 +0900
committerjoon.c.baek <joon.c.baek@samsung.com>2016-08-08 17:35:21 +0900
commit6e14080fd7f113bbbacdd9bc15c500c659015a47 (patch)
treef85beb35904c2031e6c5f6de159dfc118bf6c602
parent94b5ed42497a3c6136f62541327590c27d40bc70 (diff)
downloadttrace-Refs/for/tizen.tar.gz
ttrace-Refs/for/tizen.tar.bz2
ttrace-Refs/for/tizen.zip
Apply UID/GID to ttrace filesRefs/for/tizen
Apply UID/GID 'system_fw' to ttrace binary and resources. Remove exec-ttrace-marker, It was moved to inside of atrace --init_exec. Change-Id: I8c9c30a0d73e997eeeb712dbf80d55468ced8457 Signed-off-by: joon.c.baek <joon.c.baek@samsung.com>
-rwxr-xr-xpackaging/exec-ttrace-marker131
-rw-r--r--[-rwxr-xr-x]packaging/ttrace-marker.service2
-rw-r--r--[-rwxr-xr-x]packaging/ttrace.spec8
-rwxr-xr-xsrc/atrace/atrace.cpp103
4 files changed, 78 insertions, 166 deletions
diff --git a/packaging/exec-ttrace-marker b/packaging/exec-ttrace-marker
deleted file mode 100755
index ef52ffb..0000000
--- a/packaging/exec-ttrace-marker
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/bin/bash
-# Note: This file has been deprecated
-tag="/tmp/ttrace_tag"
-conf="/etc/ttrace.conf"
-change_permission="--update"
-
-function init_perms(){
- chown root:developer /tmp/ttrace_tag
- chmod 0664 /tmp/ttrace_tag
- chsmack -a '*' /tmp/ttrace_tag
-
- chmod 0755 /sys/kernel/debug
- chown root:developer /sys/kernel/debug/tracing/trace_marker
- chmod 0222 /sys/kernel/debug/tracing/trace_marker
- chsmack -a '*' /sys/kernel/debug/tracing/trace_marker
-
- chown root:developer /sys/kernel/debug/tracing/trace_clock
- chmod 0664 /sys/kernel/debug/tracing/trace_clock
- chsmack -a '*' /sys/kernel/debug/tracing/trace_clock
-
- chown root:developer /sys/kernel/debug/tracing/buffer_size_kb
- chmod 0664 /sys/kernel/debug/tracing/buffer_size_kb
- chsmack -a '*' /sys/kernel/debug/tracing/buffer_size_kb
-
- chown root:developer /sys/kernel/debug/tracing/options/overwrite
- chmod 0664 /sys/kernel/debug/tracing/options/overwrite
- chsmack -a '*' /sys/kernel/debug/tracing/options/overwrite
-
- chown root:developer /sys/kernel/debug/tracing/options/print-tgid
- chmod 0664 /sys/kernel/debug/tracing/options/print-tgid
- chsmack -a '*' /sys/kernel/debug/tracing/options/print-tgid
-
- chown root:developer /sys/kernel/debug/tracing/events/sched/sched_switch/enable
- chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/sched/sched_switch/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
- chmod 0664 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
- chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
- chmod 0664 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
- chmod 0664 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/power/cpu_idle/enable
- chmod 0664 /sys/kernel/debug/tracing/events/power/cpu_idle/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/power/cpu_idle/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
- chmod 0664 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
- chmod 0664 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
- chmod 0664 /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
- chmod 0664 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/mmc/enable
- chmod 0664 /sys/kernel/debug/tracing/events/mmc/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/mmc/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/sync/enable
- chmod 0664 /sys/kernel/debug/tracing/events/sync/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/sync/enable
-
- chown root:developer /sys/kernel/debug/tracing/events/workqueue/enable
- chmod 0664 /sys/kernel/debug/tracing/events/workqueue/enable
- chsmack -a '*' /sys/kernel/debug/tracing/events/workqueue/enable
-
- chown root:developer /sys/kernel/debug/tracing/current_tracer
- chmod 0664 /sys/kernel/debug/tracing/current_tracer
- chsmack -a '*' /sys/kernel/debug/tracing/current_tracer
-
- chown root:developer /sys/kernel/debug/tracing/tracing_on
- chmod 0664 /sys/kernel/debug/tracing/tracing_on
- chsmack -a '*' /sys/kernel/debug/tracing/tracing_on
-
- chown root:developer /sys/kernel/debug/tracing/trace
- chmod 0660 /sys/kernel/debug/tracing/trace
- chsmack -a '*' /sys/kernel/debug/tracing/trace
-
- chown root:developer /usr/bin/atrace
- chmod 0755 /usr/bin/atrace
-}
-
-
-if [ -e "$tag" ]
-then
- echo "$tag was created already!!!"
- exit 0
-else
- # create ttrace tag
- atrace --init_exec
-
- # initialize permission, smack rule for ttrace_tag, sysfs nodes
- init_perms
-fi
-
-if [ -e "$conf" ]
-then
- echo "$conf was found!!!"
-
- while read line
- do
- options=$line
- echo "File name is - $conf"
- echo "Options is - $options"
- done < "$conf"
- # below script is not available on TV profile
- change-booting-mode.sh "$change_permission"
- $options
- rm "$conf"
-else
- echo "$conf was NOT found!!!"
-fi
-exit 0
diff --git a/packaging/ttrace-marker.service b/packaging/ttrace-marker.service
index 7b8caae..98422cd 100755..100644
--- a/packaging/ttrace-marker.service
+++ b/packaging/ttrace-marker.service
@@ -4,6 +4,8 @@ DefaultDependencies=no
After=sys-kernel-debug.mount
[Service]
+User=system_fw
+Group=system_fw
Type=simple
ExecStart=/usr/bin/atrace --init_exec
SmackProcessLabel=System
diff --git a/packaging/ttrace.spec b/packaging/ttrace.spec
index 14ca0c4..7f3df2c 100755..100644
--- a/packaging/ttrace.spec
+++ b/packaging/ttrace.spec
@@ -73,14 +73,14 @@ cp LICENSE %{buildroot}/usr/share/license/%{name}
%files
%manifest ttrace.manifest
-%defattr(-,root,root,-)
+%defattr(644,root,root,-)
%{_libdir}/libttrace.so.*
%{_unitdir}/ttrace-marker.service
%{_unitdir}/ttrace-marker.service.wants/
-%attr(755,root,users) %{_bindir}/atrace
-%attr(755,root,users) %{_bindir}/atrace-1.1
+%attr(755,system_fw,system_fw) %{_bindir}/atrace
+%attr(755,system_fw,system_fw) %{_bindir}/atrace-1.1
%{_unitdir}/sys-kernel-debug.mount.wants/ttrace-marker.service
-%attr(755,root,root) %{_bindir}/atrace-bootup.sh
+%attr(755,system_fw,system_fw) %{_bindir}/atrace-bootup.sh
/usr/share/license/%{name}
%files devel
diff --git a/src/atrace/atrace.cpp b/src/atrace/atrace.cpp
index dad1fa6..10fa9ba 100755
--- a/src/atrace/atrace.cpp
+++ b/src/atrace/atrace.cpp
@@ -26,6 +26,7 @@
#include <sys/sendfile.h>
#include <time.h>
#include <zlib.h>
+#include <pwd.h>
#ifdef DEVICE_TYPE_TIZEN
#include <stdint.h>
@@ -81,30 +82,30 @@ typedef enum {
} commonNodeIdx;
static const CommonNode commonNodes[] = {
- { ENABLED_TAG_FILE, 0664 },
- { "/sys/kernel/debug", 0755 },
- { "/sys/kernel/debug/tracing", 0755 },
- { "/sys/kernel/debug/tracing/trace_marker", 0222 },
- { "/sys/kernel/debug/tracing/trace_clock", 0666 },
- { "/sys/kernel/debug/tracing/buffer_size_kb", 0666 },
- { "/sys/kernel/debug/tracing/current_tracer", 0666 },
- { "/sys/kernel/debug/tracing/tracing_on", 0666 },
- { "/sys/kernel/debug/tracing/trace", 0666 },
- { "/sys/kernel/debug/tracing/options/overwrite", 0666 },
- { "/sys/kernel/debug/tracing/options/print-tgid", 0666 },
- { "/sys/kernel/debug/tracing/events/sched/sched_switch/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/power/cpu_frequency/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/memory_bus/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/power/cpu_idle/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/block/block_rq_issue/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/block/block_rq_complete/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/mmc/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/cpufreq_interactive/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/sync/enable", 0666 },
- { "/sys/kernel/debug/tracing/events/workqueue/enable", 0666 },
+ { ENABLED_TAG_FILE, 0666},
+ { "/sys/kernel/debug", 0755},
+ { "/sys/kernel/debug/tracing", 0755},
+ { "/sys/kernel/debug/tracing/trace_marker", 0222},
+ { "/sys/kernel/debug/tracing/trace_clock", 0666},
+ { "/sys/kernel/debug/tracing/buffer_size_kb", 0666},
+ { "/sys/kernel/debug/tracing/current_tracer", 0666},
+ { "/sys/kernel/debug/tracing/tracing_on", 0666},
+ { "/sys/kernel/debug/tracing/trace", 0666},
+ { "/sys/kernel/debug/tracing/options/overwrite", 0666},
+ { "/sys/kernel/debug/tracing/options/print-tgid", 0666},
+ { "/sys/kernel/debug/tracing/events/sched/sched_switch/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/sched/sched_wakeup/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/power/cpu_frequency/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/memory_bus/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/power/cpu_idle/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable",0666},
+ { "/sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/block/block_rq_issue/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/block/block_rq_complete/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/mmc/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/cpufreq_interactive/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/sync/enable", 0666},
+ { "/sys/kernel/debug/tracing/events/workqueue/enable", 0666},
};
struct TracingCategory {
@@ -222,12 +223,16 @@ static bool g_init_exec = false;
static bool g_append_trace = false;
static bool g_backup_trace = false;
static struct group group_dev;
+static struct passwd passwd_dev;
#if TTRACE_TIZEN_VERSION_MAJOR < 3
+#define TTRACE_USER_NAME "root"
#define TTRACE_GROUP_NAME "developer"
#else
-#define TTRACE_GROUP_NAME "users"
+#define TTRACE_USER_NAME "system_fw"
+#define TTRACE_GROUP_NAME "system_fw"
#endif
static struct group* group_ptr;
+static struct passwd* passwd_ptr;
#endif
@@ -283,7 +288,7 @@ static bool fileIsWritable(const char* filename) {
static bool setFilePermission (const char *path, const mode_t perms) {
//fprintf(stderr, "path: %s, perms: %d, gid: %d\n", path,perms, group_dev.gr_gid);
- if (0 > chown(path, 0, group_dev.gr_gid)) return false;
+ if (0 > chown(path, passwd_dev.pw_uid, group_dev.gr_gid)) return false;
if (0 > chmod(path, perms)) return false;
if (0 > smack_setlabel(path, "*", SMACK_LABEL_ACCESS)) return false;
@@ -511,11 +516,13 @@ static bool setTagsProperty(uint64_t tags)
size_t bufSize = DEF_GR_SIZE;
char buf[DEF_GR_SIZE];
int ret = 0;
+ bool isInvalid = false;
if(fileExists(ENABLED_TAG_FILE)) {
fprintf(stderr, "[Info] T-trace has been already initailized\n");
return false; //atrace has been already initailized.
}
+
ret = getgrnam_r(TTRACE_GROUP_NAME, &group_dev, buf, bufSize, &group_ptr);
if (ret != 0 && ret != ERANGE)
@@ -523,8 +530,8 @@ static bool setTagsProperty(uint64_t tags)
fprintf(stderr, "Fail to group[%s] info: %s(%d)\n", TTRACE_GROUP_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
return false;
}
-
- bool isInvalid = false;
+
+ isInvalid = false;
while(ret == ERANGE)
{
long int tmpSize = -1;
@@ -532,7 +539,7 @@ static bool setTagsProperty(uint64_t tags)
if(!isInvalid)
tmpSize = sysconf(_SC_GETGR_R_SIZE_MAX);
- if (tmpSize == -1)
+ if (tmpSize == -1)
{
bufSize *= 2;
}
@@ -548,7 +555,41 @@ static bool setTagsProperty(uint64_t tags)
if(ret == ERANGE) isInvalid = true;
free(dynbuf);
}
- fd = open("/tmp/tmp_tag", O_CREAT | O_RDWR | O_CLOEXEC, 0666);
+
+ ret = getpwnam_r(TTRACE_USER_NAME, &passwd_dev, buf, bufSize, &passwd_ptr);
+
+ if (ret != 0 && ret != ERANGE)
+ {
+ fprintf(stderr, "Fail to group[%s] info: %s(%d)\n", TTRACE_USER_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
+ return false;
+ }
+
+ isInvalid = false;
+ while(ret == ERANGE)
+ {
+ long int tmpSize = -1;
+
+ if(!isInvalid)
+ tmpSize = sysconf(_SC_GETGR_R_SIZE_MAX);
+
+ if (tmpSize == -1)
+ {
+ bufSize *= 2;
+ }
+ else bufSize = (size_t) tmpSize;
+
+ char *dynbuf = (char *) malloc(bufSize);
+ if(dynbuf == NULL)
+ {
+ fprintf(stderr, "Fail to allocate buffer for group[%s]: %s(%d)\n", TTRACE_GROUP_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
+ return false;
+ }
+ ret = getpwnam_r(TTRACE_USER_NAME, &passwd_dev, dynbuf, bufSize, &passwd_ptr);
+ if(ret == ERANGE) isInvalid = true;
+ free(dynbuf);
+ }
+
+ fd = open("/tmp/tmp_tag", O_CREAT | O_RDWR | O_CLOEXEC, 0666);
if(fd < 0){
fprintf(stderr, "Fail to open enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
return false;
@@ -613,7 +654,7 @@ static bool setTagsProperty(uint64_t tags)
}
//atrace normal mode
else {
- fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0666);
+ fd = open(ENABLED_TAG_FILE, O_RDWR | O_CLOEXEC, 0666);
if(fd < 0){
fprintf(stderr, "Fail to open enabled_tag file: %s(%d)\n", strerror_r(errno, str_error, sizeof(str_error)), errno);
return false;