platform/core/system/pass.git
8 weeks agopass-rescon: Get scenario_level_list inside critical section sandbox/dwlee08/fix_coverity
Dongwoo Lee [Thu, 7 Mar 2024 09:03:57 +0000 (18:03 +0900)]
pass-rescon: Get scenario_level_list inside critical section

Change-Id: Ia371058c6ad4419da4ef48c569bdef6bf43fbe2a
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
8 weeks agomonitor: Prevent possible deadlock and psuedo wakeup
Dongwoo Lee [Thu, 7 Mar 2024 06:53:19 +0000 (15:53 +0900)]
monitor: Prevent possible deadlock and psuedo wakeup

Change-Id: I040e53817b102cb5db6c557fec914912f450302e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
8 weeks agolib: resource-monitor: Fix missing mutual exclusion
Dongwoo Lee [Thu, 7 Mar 2024 06:41:29 +0000 (15:41 +0900)]
lib: resource-monitor: Fix missing mutual exclusion

Since find_client_by_id() walks g_pass_resource_monitor_client_head
list which is prevented by critical section, it should be mutually
exclusive, thus mutex lock/unlock is added to former/later of loop.

Change-Id: I6ea2dad42ff9dd08dec331db7ea4c9de550da618
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
4 months agoresource-monitor: Add a body of the dbus request message for applying the change... 24/302824/1
Sung-hun Kim [Thu, 14 Dec 2023 07:57:24 +0000 (16:57 +0900)]
resource-monitor: Add a body of the dbus request message for applying the change of enlightenment

Due to the change of enlightenment, the dbus request message should have
a body which includes a string type argument.

For understanding the change of enlightenment, please refer the below commit:

 https://review.tizen.org/gerrit/gitweb?p=platform/upstream/enlightenment.git;a=commit;h=fa89f84645623c0522c1d6327ec60c45648da0af

Change-Id: Ida0553cfd0bb2172ae3145f03d89e53d290b72e7
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
4 months agomonitor: Add error handling codes 07/302807/3
Sung-hun Kim [Thu, 14 Dec 2023 01:49:34 +0000 (10:49 +0900)]
monitor: Add error handling codes

Since the request-handler code does not handle error cases,
the pass daemon killed with segmentation fault.

See the below gdb output:

 Program terminated with signal SIGSEGV, Segmentation fault.
 #0  handle_request (client=client@entry=0x7f680008d0, request=request@entry=0x7f72ffc270 "17") at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:877
 877 /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c: No such file or directory.
 [Current thread is 1 (LWP 5465)]
 >>> bt
 #0  handle_request (client=client@entry=0x7f680008d0, request=request@entry=0x7f72ffc270 "17") at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:877
 #1  0x000000558df6eda0 in request_handler_func (data=0x7f680008d0, result=<optimized out>) at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:1012
 #2  0x000000558df5bb28 in __thread_loop_main (_ctx=0x7f68001170) at /usr/src/debug/pass-2.0.0-1.aarch64/src/util/thread.c:45
 #3  0x0000007f833b882c in ?? () from /lib64/libpthread.so.0
 #4  0x0000007f83319eac in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

I added an error handling code with NULL check for the variable
`array`.

Change-Id: I93bc4a23903c2c7d7fc9315d238d2c5addddc445
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
7 months agopass: Get rid of CAP_DAC_OVERRIDE capability from systemd service 28/298628/1 accepted/tizen_8.0_unified accepted/tizen/8.0/unified/20231005.093825 accepted/tizen/unified/20230913.091617 tizen_8.0_m2_release
Dongwoo Lee [Tue, 12 Sep 2023 02:16:31 +0000 (11:16 +0900)]
pass: Get rid of CAP_DAC_OVERRIDE capability from systemd service

CAP_SYS_RESOURCE is enough to write the psi nodes, CAP_DAC_OVERRIDED
is no more needed. Thus, it is removed.

Change-Id: Ie51f967eae11260114e940692edd10e0216b26f4
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
7 months agopass: Add CAP_SYS_RESOURCE capability to allow write in psi nodes 09/298609/1 accepted/tizen/unified/20230912.171559
Dongwoo Lee [Mon, 11 Sep 2023 10:38:22 +0000 (19:38 +0900)]
pass: Add CAP_SYS_RESOURCE capability to allow write in psi nodes

Since linux kernel 5.13, CAP_SYS_RESOURCE is required to write in psi
nodes with unprivileged process. Thus this adds it to systemd service
file.

Change-Id: Ie8027e8f99aa616770eda9d0718604e2e0189041
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
8 months agopass: thermal: Fix possible null deference in thermal_free() 55/296955/2 accepted/tizen_unified_riscv accepted/tizen/unified/20230808.170202 accepted/tizen/unified/riscv/20230809.013248
Seung-Woo Kim [Tue, 8 Aug 2023 02:39:33 +0000 (11:39 +0900)]
pass: thermal: Fix possible null deference in thermal_free()

When there is no thermal scenario, thermal can not be initialized
and g_thermal is null. Exiting pass from the status, in
thermal_free(), there is null deference. Fix the possible null
deference.

Change-Id: I69ab200ea3d182adc628913d89306db6fe3ebcff
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
8 months agopass: thermal: Fix typo in thermal_free() 54/296954/2
Seung-Woo Kim [Tue, 8 Aug 2023 02:36:47 +0000 (11:36 +0900)]
pass: thermal: Fix typo in thermal_free()

There was a typo in thermal_free(), so fix it.

Change-Id: I94c49f98b58bb20481e4fe4bd02ccb0cfa352744
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
13 months agotests: unittest: Add pass-resmon-unittests 07/289707/5 accepted/tizen/unified/20230322.080545
Chanwoo Choi [Tue, 14 Mar 2023 10:39:56 +0000 (19:39 +0900)]
tests: unittest: Add pass-resmon-unittests

Add support of pass-resmon-unittests
to test Resource Monitor module (pass-resmon).

[Test result of pass-resmon-unittests]
[   33s] 1: Test command: /home/abuild/rpmbuild/BUILD/pass-2.0.0/tests/unittest/pass-resmon/pass-resmon-unittests
[   33s] 1: Working Directory: /home/abuild/rpmbuild/BUILD/pass-2.0.0/tests/unittest/pass-resmon
[   33s] 1: Test timeout computed to be: 10000000
[   33s] 1: [==========] Running 12 tests from 2 test suites.
[   33s] 1: [----------] Global test environment set-up.
[   33s] 1: [----------] 2 tests from PassResmonInitExitTest
[   33s] 1: [ RUN      ] PassResmonInitExitTest.pass_resmon_prepare_init_and_exit_unprepare_valid
[   33s] 1: [       OK ] PassResmonInitExitTest.pass_resmon_prepare_init_and_exit_unprepare_valid (0 ms)
[   33s] 1: [ RUN      ] PassResmonInitExitTest.pass_resmon_prepare_init_and_exit_unprepare_invalid
[   33s] 1: [       OK ] PassResmonInitExitTest.pass_resmon_prepare_init_and_exit_unprepare_invalid (0 ms)
[   33s] 1: [----------] 2 tests from PassResmonInitExitTest (0 ms total)
[   33s] 1:
[   33s] 1: [----------] 10 tests from PassResmonTest
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_register_timer
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_register_timer (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_register_timer_invalid
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_register_timer_invalid (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_unregister_timer
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_unregister_timer (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_unregister_timer_invalid
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_unregister_timer_invalid (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_update_timer_interval
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_update_timer_interval (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_update_timer_interval_invalid
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_update_timer_interval_invalid (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_register_uevent
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_register_uevent (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_register_uevent_invalid
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_register_uevent_invalid (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_unregister_uevent
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_unregister_uevent (0 ms)
[   33s] 1: [ RUN      ] PassResmonTest.pass_resmon_unregister_uevent_invalid
[   33s] 1: [       OK ] PassResmonTest.pass_resmon_unregister_uevent_invalid (0 ms)
[   33s] 1: [----------] 10 tests from PassResmonTest (3 ms total)
[   33s] 1:
[   33s] 1: [----------] Global test environment tear-down
[   33s] 1: [==========] 12 tests from 2 test suites ran. (3 ms total)
[   33s] 1: [  PASSED  ] 12 tests.
[   33s] 1/1 Test #1: pass-resmon-unittests ............   Passed    0.01 sec
[   33s]
[   33s] 100% tests passed, 0 tests failed out of 1
[   33s]
[   33s] Total Test time (real) =   0.01 sec

Change-Id: Idcb8bac8d5d69862d898a810ddf0f802452b6883
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
13 months agopass: resmon: Add missing exception handling to check parameter 06/289706/5
Chanwoo Choi [Wed, 8 Mar 2023 21:12:59 +0000 (06:12 +0900)]
pass: resmon: Add missing exception handling to check parameter

Add missing exception handling to check whether parameter is valid  or not

And fix the wrong function prototype of pass_resmon_unregister_uevent
with the the wrong error log information.

Change-Id: I50d857d00bec6fd4f2404f05a8f392dd36d062b3
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
13 months agopass: resmon: Move private pass_resmon structure for encapsulation 05/289705/4
Chanwoo Choi [Tue, 21 Feb 2023 08:51:04 +0000 (17:51 +0900)]
pass: resmon: Move private pass_resmon structure for encapsulation

The struct pass_resmon is private data structure and the other module
cannot access the data of struct pass_resmon directly. In order to
protect the data, move private pass_resmon structure into pass_resmon
module and then provide the proper getter/setter function to handle the
data.

Change-Id: Ic4d1d8d0d11294e173ba19cc08b50a459a878492
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
13 months agopass: rescon: Fix GET functions to work properly 64/289764/2 accepted/tizen/unified/20230315.093502
Dongwoo Lee [Tue, 14 Mar 2023 06:44:36 +0000 (15:44 +0900)]
pass: rescon: Fix GET functions to work properly

Change-Id: Ifc48198bbc6fe8736671a192fe1883a02aa90852
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
13 months agopass: resmon: Add RESMON_TIMER_UNKNOWN enum 04/289704/1
Chanwoo Choi [Wed, 8 Mar 2023 21:01:48 +0000 (06:01 +0900)]
pass: resmon: Add RESMON_TIMER_UNKNOWN enum

In order to test the invalid case of pass-resmon unittest,
add RESMON_TIMER_UNKNOWN enum.

Change-Id: I64d3f21fb6a7ee95c250d134b75310d105cd6f48
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
14 months agomonitor: request-handler: Apply API for creating monitor 89/289189/1 accepted/tizen/unified/20230310.062654
Youngjae Cho [Thu, 2 Mar 2023 08:49:22 +0000 (17:49 +0900)]
monitor: request-handler: Apply API for creating monitor

Change-Id: I81786d80861a741039bd20719831597912c48cc6
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
14 months agopass: monitor: Apply libsyscommon resource-monitor changes 97/288497/2 accepted/tizen/unified/20230306.172219
Dongwoo Lee [Fri, 17 Feb 2023 07:37:46 +0000 (16:37 +0900)]
pass: monitor: Apply libsyscommon resource-monitor changes

Change-Id: I5da0095f9840d613f8962bcf3be824848c09e60f
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agoresource: system: Fix possible vulnerability 58/288558/1
Dongwoo Lee [Mon, 20 Feb 2023 02:34:02 +0000 (11:34 +0900)]
resource: system: Fix possible vulnerability

Change-Id: Ic6c261ea13e1a85086a15376ad360deb05f5d6cd
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agotests: unittest: Add pass-rescon-unittests 04/283604/5
Chanwoo Choi [Tue, 13 Sep 2022 23:17:18 +0000 (08:17 +0900)]
tests: unittest: Add pass-rescon-unittests

[Test result of pass-rescon-unittests]
[    2s] 1: Test command: /home/abuild/rpmbuild/BUILD/pass-2.0.0/tests/unittest/pass-rescon/pass-rescon-unittests
[    2s] 1: Test timeout computed to be: 10000000
[    2s] 1: [==========] Running 22 tests from 2 test suites.
[    2s] 1: [----------] Global test environment set-up.
[    2s] 1: [----------] 1 test from PassResconInitExitTest
[    2s] 1: [ RUN      ] PassResconInitExitTest.pass_rescon_prepare_and_init_and_exit
[    2s] 1: [       OK ] PassResconInitExitTest.pass_rescon_prepare_and_init_and_exit (0 ms)
[    2s] 1: [----------] 1 test from PassResconInitExitTest (0 ms total)
[    2s] 1:
[    2s] 1: [----------] 21 tests from PassResconTest
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_init_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_init_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_curr_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_curr_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_prev_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_prev_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_min_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_min_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_max_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_max_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_init_scenario_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_init_scenario_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_get_init_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_get_init_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_get_curr_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_get_curr_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_get_prev_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_get_prev_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_get_min_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_get_min_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_get_max_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_get_max_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_level_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_level_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_level_and_pass_rescon_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_level_and_pass_rescon_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_scenario_level_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_scenario_level_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_scenario_set_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_scenario_set_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_set_scenario_level_and_pass_rescon_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_set_scenario_level_and_pass_rescon_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_unset_scenario_level_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_unset_scenario_level_sync (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_unset_scenario_level
[    2s] 1: [       OK ] PassResconTest.pass_rescon_unset_scenario_level (0 ms)
[    2s] 1: [ RUN      ] PassResconTest.pass_rescon_unset_scenario_level_and_pass_rescon_sync
[    2s] 1: [       OK ] PassResconTest.pass_rescon_unset_scenario_level_and_pass_rescon_sync (0 ms)
[    2s] 1: [----------] 21 tests from PassResconTest (5 ms total)
[    2s] 1:
[    2s] 1: [----------] Global test environment tear-down
[    2s] 1: [==========] 22 tests from 2 test suites ran. (6 ms total)
[    2s] 1: [  PASSED  ] 22 tests.
[    2s] 1/1 Test #1: pass-rescon-unittests ............   Passed    0.01 sec

Change-Id: Ifcf5dc54805e3e40346d6486cae411eb5b8e99c6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
14 months agoresource: system: Add is_supported ops for memory pressure level attribute 49/288349/1
Dongwoo Lee [Wed, 15 Feb 2023 10:43:14 +0000 (19:43 +0900)]
resource: system: Add is_supported ops for memory pressure level attribute

Change-Id: I5730b241965213563552f37ea5aa670968e5eaed
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agotools: resource-monitor: Fix wrong attribute name description 48/288348/1
Dongwoo Lee [Wed, 15 Feb 2023 10:43:14 +0000 (19:43 +0900)]
tools: resource-monitor: Fix wrong attribute name description

Change-Id: I3cb5e7b253e33930d90c80127511037241e9fb5e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agopass: Fix build warnings 80/288280/1
Dongwoo Lee [Tue, 14 Feb 2023 10:42:59 +0000 (19:42 +0900)]
pass: Fix build warnings

Change-Id: I326e9f47c14b14312553ef49b6b5d180f3cf7bb9
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agoutil: thread: Prevent to run thread before creation finished 18/287918/4 accepted/tizen/unified/20230221.031435
Dongwoo Lee [Tue, 7 Feb 2023 16:50:33 +0000 (08:50 -0800)]
util: thread: Prevent to run thread before creation finished

Currently thread can be terminated before creation process is over,
and it can either cause wrong memory access on thread context. To
prevent this situation, thread lock is acquired before creating
thread, and thus the new thread cannot acquire lock and is suspended
until lock is released after creation is over.

Change-Id: Ic769c4dfa522e115959cf25c2c0c78779d176743
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agopass: Add capability for writing to procfs node 17/287917/1
Dongwoo Lee [Tue, 31 Jan 2023 03:08:28 +0000 (12:08 +0900)]
pass: Add capability for writing to procfs node

In order to use global memory pressure stall information, pass can
write to the node '/proc/pressure/memory' and it requires
'CAP_DAC_OVERRIDE' capability. Thus, this adds the capability to
service file.

Change-Id: I35f865e503678826459e32f723a46a6812529d34
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
14 months agoresource: system: Add MEMORY_PRESSURE_LEVEL attribute 16/287916/1
Dongwoo Lee [Thu, 12 Jan 2023 12:39:12 +0000 (21:39 +0900)]
resource: system: Add MEMORY_PRESSURE_LEVEL attribute

This adds the new attribute for representing pressure level of memory
as follows:
- Name: SYSTEM_ATTR_MEMORY_PRESSURE_LEVEL
- Type: SYSCOMMON_RESMAN_DATA_TYPE_INT
- Description:
    this attribute represents the current stall level for memory,
    which means how long delays memory allocation due to memory
    leakage. The level ranges between 0 and 4 (higher is worse).

Change-Id: Ibdce4a983384743e2316967744ac843a6ebb15e2
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
16 months agotests: unittest: Add pass-hal-mock class for unittest 03/283603/2
Chanwoo Choi [Tue, 13 Sep 2022 23:16:48 +0000 (08:16 +0900)]
tests: unittest: Add pass-hal-mock class for unittest

Change-Id: I0862b7cfdbf300a4ef906f073ef34c0acf670570
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
16 months agotests: unittest: Move pass-unittests into pass-hal-and-parser and rename it 02/283602/2
Chanwoo Choi [Mon, 12 Sep 2022 20:36:12 +0000 (05:36 +0900)]
tests: unittest: Move pass-unittests into pass-hal-and-parser and rename it

The existing pass-unittests have been tested pass-hal module.
When I tried to add pass-hal mocking class for testing pass-rescon module,
the multiple definition build error happen. So that I split out the unittest
like this.

Change-Id: If0927b34197caebec579a52359df76faa1c0308d
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
16 months agopass: rescon: Encapsulate struct pass_rescon to prevent direct access 01/283601/2
Chanwoo Choi [Sun, 4 Sep 2022 17:03:22 +0000 (02:03 +0900)]
pass: rescon: Encapsulate struct pass_rescon to prevent direct access

Any modules are able to access the internal fields of struct pass_rescon
directly. It might make the problem on later and the current method
is not proper. So that move the defintion of struct pass_rescon
into src/pass/pass-rescon.c to prevent the direct access.
Instead, provide the getter/setter function for fields of struct pass_rescon.

Change-Id: I801452d0b8ae98146a74f2ebd1926f6cc4c8c47a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
17 months agoresource: Operate based on resource id 20/283920/4 accepted/tizen/unified/20221206.170546
Youngjae Cho [Mon, 7 Nov 2022 07:29:01 +0000 (16:29 +0900)]
resource: Operate based on resource id

The resource-manager of libsyscommon has been revamped to work based on
resource id instead of actual instance. Therefore the pass doesn't need
to manage actual resource instance of libsyscommon anymore. Instead, the
only thing to do is managing id of resource instance, which can be used
in any place to which resource instance could have been used.

Change-Id: I5b47eb6ad9b5743fdb4a71f21cfe32af83300957
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
18 months agoresource: Apply system resource manager library 09/283209/5
Dongwoo Lee [Wed, 12 Oct 2022 03:28:25 +0000 (12:28 +0900)]
resource: Apply system resource manager library

Now resource utilities is removed, and new resource manger library in
libsyscommon which is extract from pass is used instead.

Change-Id: I0ec3403ce297ef1c6d3899987bcb6fd5ad96abbd
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
18 months agoresource: Resolve dependency of HAL devices 08/283208/5
Dongwoo Lee [Thu, 13 Oct 2022 03:23:24 +0000 (12:23 +0900)]
resource: Resolve dependency of HAL devices

To include resource device related features to the resource library,
this separates it from pass core.

Change-Id: I35327b1932de35f5af2a516f361552160215b088
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
18 months agoresource: extract resource core from monitor 07/283207/5
Dongwoo Lee [Wed, 12 Oct 2022 09:41:39 +0000 (18:41 +0900)]
resource: extract resource core from monitor

To make resource-related features into library, this extracts core
part of resource util from resource monitor.

Change-Id: I69930d9b7a83e87b3f67fd507360464eea7d4b44
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
18 months agopackaging: libpass-resource-monitor: Fix typo 22/283222/2
Dongwoo Lee [Thu, 20 Oct 2022 10:10:24 +0000 (19:10 +0900)]
packaging: libpass-resource-monitor: Fix typo

Change-Id: I85a5a119b7a293670c0f66a93625a7ddb259494f
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agopass: thermal: Fix to return proper value for dbus signal handler 97/281897/1 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.063429 accepted/tizen/7.0/unified/hotfix/20221116.105751 accepted/tizen/unified/20220927.132311 tizen_7.0_m2_release
Seung-Woo Kim [Fri, 23 Sep 2022 02:09:52 +0000 (11:09 +0900)]
pass: thermal: Fix to return proper value for dbus signal handler

From the dbus-stub generated code, signal handler should return
TRUE if it handles invocation. Even ret value is error, fix to
return TRUE after handling invocation.

Below is dbus-stub comment about signal handler:
  If a signal handler returns %TRUE, it means the signal handler
  will handle the invocation and no other signal handlers will
  run. If no signal handler handles the invocation, the
  %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
  Returns: %G_DBUS_METHOD_INVOCATION_HANDLED or %TRUE if the
   invocation was handled,
   %G_DBUS_METHOD_INVOCATION_UNHANDLED or %FALSE to let
   other signal handlers run.

NOTE: GLIB related asan heap-buffer-overflow issue is from the
wrong return.

Change-Id: I4db508aafba556406dce63bb0309d55c9f8a4696
Suggested-by: Sangjung Woo <sangjung.woo@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
19 months agopmqos: Fix to return proper value for dbus signal handler 96/281896/1
Seung-Woo Kim [Fri, 23 Sep 2022 02:09:02 +0000 (11:09 +0900)]
pmqos: Fix to return proper value for dbus signal handler

From the dbus-stub generated code, signal handler should return
TRUE if it handles invocation. Even ret value is error, fix to
return TRUE after handling invocation.

Below is dbus-stub comment about signal handler:
  If a signal handler returns %TRUE, it means the signal handler
  will handle the invocation and no other signal handlers will
  run. If no signal handler handles the invocation, the
  %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
  Returns: %G_DBUS_METHOD_INVOCATION_HANDLED or %TRUE if the
   invocation was handled,
   %G_DBUS_METHOD_INVOCATION_UNHANDLED or %FALSE to let
   other signal handlers run.

NOTE: GLIB related asan heap-buffer-overflow issue is from the
wrong return.

Change-Id: I070c4a3fd12d5421cc52e69e6ada25b2ec772e6f
Suggested-by: Sangjung Woo <sangjung.woo@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
19 months agopass: Fix to return proper value for dbus signal handler 95/281895/1
Seung-Woo Kim [Fri, 23 Sep 2022 02:03:57 +0000 (11:03 +0900)]
pass: Fix to return proper value for dbus signal handler

From the dbus-stub generated code, signal handler should return
TRUE if it handles invocation. Even ret value is error, fix to
return TRUE after handling invocation.

Below is dbus-stub comment about signal handler:
  If a signal handler returns %TRUE, it means the signal handler
  will handle the invocation and no other signal handlers will
  run. If no signal handler handles the invocation, the
  %G_DBUS_ERROR_UNKNOWN_METHOD error is returned.
  Returns: %G_DBUS_METHOD_INVOCATION_HANDLED or %TRUE if the
           invocation was handled,
           %G_DBUS_METHOD_INVOCATION_UNHANDLED or %FALSE to let
           other signal handlers run.

NOTE: GLIB related asan heap-buffer-overflow issue is from the
wrong return.

Change-Id: I11e684101efb68e625a742b4d0655056299fd106
Suggested-by: Sangjung Woo <sangjung.woo@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
19 months agopass: parser: Change num_of_cpus and first_cpu into signed type 68/281568/1 accepted/tizen/unified/20220922.114008
Dongwoo Lee [Tue, 20 Sep 2022 03:22:01 +0000 (12:22 +0900)]
pass: parser: Change num_of_cpus and first_cpu into signed type

Since two variable is unsigned so it can be never be less than zero,
but in order to check error case they are needed to be negative.

Change-Id: Ib60fafeee7c1352d6cf3d63e8e4f9c6e6e7f68ce
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agopass: parser: Check NULL before reference 67/281567/1
Dongwoo Lee [Tue, 20 Sep 2022 03:21:01 +0000 (12:21 +0900)]
pass: parser: Check NULL before reference

Change-Id: Ifae8c9ae87a9f79bae5b79450b504d3025ecee24
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agomonitor: Use the systemd Unix socket 82/281482/2 accepted/tizen/unified/20220920.110715
Sung-hun Kim [Mon, 19 Sep 2022 10:51:54 +0000 (19:51 +0900)]
monitor: Use the systemd Unix socket

Systemd creates an Unix socket when the system is booted on
by using existing configuration files in /usr/lib/systemd.

Previously, the resource monitor always creates a new Unix
socket whether the socket exists or not. From now on, the
resource monitor checks that the Unix socket is existed on
the given path. If so, it uses the Unix socket instead of
open a newer one. By doing so, the permission of the Unix
socket can follow the given configuration denoted in the
Systemd socket configuration file.

Change-Id: I1eab46cd238340cc9700e1a2d52481270c06b8b1
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
19 months agoresource-monitor-tests: Prevent possible memory leaks 37/281437/2
Sung-hun Kim [Mon, 19 Sep 2022 04:42:34 +0000 (13:42 +0900)]
resource-monitor-tests: Prevent possible memory leaks

Change-Id: I9ff9c4bd7ef970ca1541c756fd1b11c5506980f9
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
19 months agoresource: Fix missing NULL check 39/281339/1
Dongwoo Lee [Thu, 15 Sep 2022 10:51:18 +0000 (19:51 +0900)]
resource: Fix missing NULL check

Change-Id: I8a9f2d5139ad6298788d373485d24110e9d85979
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agoresource: Pass error result directly from resource creation accepted/tizen/unified/20220917.094318 accepted/tizen/unified/20220919.013232
Dongwoo Lee [Thu, 15 Sep 2022 02:15:27 +0000 (11:15 +0900)]
resource: Pass error result directly from resource creation

Previously, it was lost by returning NULL instead of the error code
that occurred during the resource creation process, but now the error
code is passed directly so that the caller can know the exact reason.

Change-Id: Iffc25c266186195d23ef0f61bba989ff5e36b4d7
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agosystemd: Fix socket file path 70/281270/1
Sung-hun Kim [Thu, 15 Sep 2022 05:56:02 +0000 (14:56 +0900)]
systemd: Fix socket file path

Change from a invalid socket file path /run/.pass.socket
to a valid socket file path /run/.pass-resource-monitor.socket

Change-Id: I197c24710ba76ffc5b8fe195129d6057cd0e2035
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
19 months agomonitor: Add dbus interface for turning on/off debug mode 67/281167/3
Dongwoo Lee [Tue, 13 Sep 2022 06:00:28 +0000 (15:00 +0900)]
monitor: Add dbus interface for turning on/off debug mode

In order to provide the way to change debug mode dynamically, the new
dbus interface is now applied as below:
 - dbus path: /Org/Tizen/System/Pass/Monitor
 - dbus interface: org.tizen.system.pass.monitor
 - dbus method:  org.tizen.system.pass.monitor.SetDebug
 - parameter:  boolean value for representing debug mode is enabled

Change-Id: I431182809d23b1b7ee795c392bdeb84f9ef741bf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agomonitor: providing ip socket server when debug mode is enabled 66/281166/3
Dongwoo Lee [Tue, 13 Sep 2022 08:08:54 +0000 (17:08 +0900)]
monitor: providing ip socket server when debug mode is enabled

To protect against attacks using network socket vulnerabilities, open
the TCP/IP based socket interface only when debug mode is enabled.

Change-Id: Ie8b3d392b783c63225f30f6dc611524ccb7c6a09
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
19 months agopass: parser: Add get_property_set to simplify getting properties 55/280755/5
Chanwoo Choi [Wed, 31 Aug 2022 14:28:33 +0000 (23:28 +0900)]
pass: parser: Add get_property_set to simplify getting properties

And get_property_set function to reduce the get_property function call.
It makes the getting propertis more simpler than before

Also, get the property value from json configuration file
and then stored them to local variables. And fill out the allocated
memory of structure with local variables. But, local variables
are not necessary. In order to reduce the LOC (line of code),
get property value directly without local variables.

Change-Id: Ib993d11d6ad22d3fd12fca54a591ae30cd3b9b20
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
19 months agotests: unittest: Add pass-parser invalid test 54/280754/4
Chanwoo Choi [Mon, 27 Jun 2022 09:30:13 +0000 (18:30 +0900)]
tests: unittest: Add pass-parser invalid test

Add pass-parser invalid unittests for each section
- Test for invalid level section
- Test for invalid pmqos section
- Test for invalid thermal section
- Test for invalid header section
- Test for invalid battery h/w resource type
- Test for invalid memory h/w resource type

Change-Id: Ibdf109751560fc130ce3d8680867c9ac81be1c56
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
19 months agoutil: kernel: Fix possible vulnerability 41/280941/1 accepted/tizen/unified/20220908.013431
Dongwoo Lee [Wed, 7 Sep 2022 03:05:52 +0000 (12:05 +0900)]
util: kernel: Fix possible vulnerability

Change-Id: I14a31746037d78670418b2b3b615e042b9a6aab4
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agomonitor: lib: Support Unix domain socket (UDS) and TCP/IP socket concurrently 03/280803/3
Sung-hun Kim [Fri, 2 Sep 2022 05:41:47 +0000 (14:41 +0900)]
monitor: lib: Support Unix domain socket (UDS) and TCP/IP socket concurrently

Previous TCP/IP socket-based IPC has a security issue that
anyone can access the opened port without credential. Since
UDS is exported as a file, we can apply file-based access
control to it. So, we use UDS instead of TCP/IP socket by
default.

At the same time, we also support TCP/IP socket for
resource-monitor-tool which is a web-based monitoring tool
in user space. In the future, we will support TCP/IP socket
only in debugging mode which is turned on/off by root-
privileged command line tool.

Change-Id: Id46a5e7560cf95d09f31222e5022ce3ea209753a
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agolib: resource-monitor: Remove unneeded privilege check 28/280628/2 accepted/tizen/unified/20220904.214045 submit/tizen/20220902.091829
Chanwoo Choi [Thu, 1 Sep 2022 10:10:50 +0000 (19:10 +0900)]
lib: resource-monitor: Remove unneeded privilege check

commit fccfb02d128c("lib: resource-monitor: Check systemmonitor privilege")
added the unneeded privilege check code. In result, cynara is running by
preempting CPU resource. So that remove unneeded privilege check code.
Only check the privilege when pass_resource_monitor_init() call.

Change-Id: I0a9c7b2ca76a781dcf88ab19ddf0ec597c98b6a5
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotests: resource-monitor-tests: Fix test fail by changing the return value 22/280622/3 accepted/tizen/unified/20220902.020129 submit/tizen/20220901.084153
Chanwoo Choi [Thu, 1 Sep 2022 08:32:01 +0000 (17:32 +0900)]
tests: resource-monitor-tests: Fix test fail by changing the return value

commit b5d308519f73("util: resource: Change error code from -EPERM to
-EACCES") changed the return value from -EPERM to -EACCESS.
In order to pass the test, change the return value
according to commit b5d308519f73.

Change-Id: I2e3261fe80ceea0fd70645484778916a928e8872
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agolib: resource-monitor: Check systemmonitor privilege 10/280610/5
Chanwoo Choi [Thu, 1 Sep 2022 06:36:41 +0000 (15:36 +0900)]
lib: resource-monitor: Check systemmonitor privilege

In order to prevent the unauthorized client,
check the systemmonitor privilege[1] .
[1] http://tizen.org/privilege/systemmonitor

For example of rejection when don't have systemmonitor privilege
- Connect sdb without root and then executes resource-monitor/resource-monitor-tests.
  In result, cannot use the resource monitor. I checked it the log as following:

E/PASS    ( 1395): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor
E/PASS    ( 1395): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor
(snip)
E/PASS    ( 1429): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor-tests
E/PASS    ( 1429): privilege.c: is_privilege_supported(69) > 'http://tizen.org/privilege/systemmonitor' privilege is not supported on resource-monitor-tests

Change-Id: I77531ca1717b3592f0803cc585e0f205c46edcee
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoutil: privilege: Add is_privilege_supported function 09/280609/6
Chanwoo Choi [Thu, 1 Sep 2022 06:34:57 +0000 (15:34 +0900)]
util: privilege: Add is_privilege_supported function

is_privilege_supported checks privilege permission of self process.

Change-Id: Ife85a74a494e12de1e1418036d8c84d389518c4b
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoutil: resource: Change error code from -EPERM to -EACCES 90/280590/1
Sung-hun Kim [Thu, 1 Sep 2022 05:02:05 +0000 (14:02 +0900)]
util: resource: Change error code from -EPERM to -EACCES

To match Tizen error code, I changed -EPERM to -EACCES.
Which corresponds to TIZEN_ERROR_PERMISSION_DENIED.

Change-Id: I1d3675435eba319637710c4cef3981398e7ab96a
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agomonitor: request-handler: Fix build error 54/280554/1 submit/tizen/20220901.025125
Chanwoo Choi [Wed, 31 Aug 2022 13:48:39 +0000 (22:48 +0900)]
monitor: request-handler: Fix build error

Fix the following build error by using the proper output type
when printing the error log.

45s] /home/abuild/rpmbuild/BUILD/pass-2.0.0/src/monitor/request-handler.c:295:31: note: format string is defined here
[   45s]   295 |   _E("failed to set flag to %lx, client(%d) | res:name(%s)id(%d)\n",
[   45s]       |                             ~~^
[   45s]       |                               |
[   45s]       |                               long unsigned int
[   45s]       |                             %llx

Change-Id: I401b2b912ed71d40b8e4a0f06d42d6b9b01c4837
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotests: resource-monitor-tests: Add a test for pass_resource_monitor_set_resource_flag 74/280374/7 submit/tizen/20220831.101713
Sung-hun Kim [Mon, 29 Aug 2022 06:41:39 +0000 (15:41 +0900)]
tests: resource-monitor-tests: Add a test for pass_resource_monitor_set_resource_flag

Add a test for newly added operation which is used for
distinguishing PRIVATE and PUBLIC resources.

Change-Id: I56d6eed1e68a292aee8075041d402bc7a8a6bb6c
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agolib: Add pass_resource_monitor_set_resource_flag 73/280373/7
Sung-hun Kim [Tue, 23 Aug 2022 11:45:57 +0000 (20:45 +0900)]
lib: Add pass_resource_monitor_set_resource_flag

By using the added function, the user of libpass can
set the resource as PUBLIC. Note that, the error will
be thrown at pass_resource_monitor_set_resource_attr,
not at pass_resource_monitor_set_resource_flag.

Change-Id: Id012ca5cf2eca90653a17c85b86e6a1913b86d35
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agomonitor: Add a handler function for REQUEST_SET_RESOURCE_FLAG 72/280372/7
Sung-hun Kim [Tue, 23 Aug 2022 11:27:56 +0000 (20:27 +0900)]
monitor: Add a handler function for REQUEST_SET_RESOURCE_FLAG

For users of capi, some information such as process information
does not be provided. To distinguish users, we set the visibility
of each resource to PUBLIC or PRIVATE due to the user's context.

When an user sets the visibility of the resource to PUBLIC and
then sets the interest of the resource attribute which has PRIVATE
visibility, the pass daemon will reject it and return -EPERM error.

Change-Id: I23a6b279aa2983aeb6e88cd51458d0c430e8692b
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agoresource: Add a new property "flag" to attributes 71/280371/4
Sung-hun Kim [Tue, 23 Aug 2022 11:13:57 +0000 (20:13 +0900)]
resource: Add a new property "flag" to attributes

To distinguish visibility of resource attributes, a new property
is added to each attribute. The visibility of each attribute is
pre-defined. Pass allows or rejects user's request for setting
interested attributes depends on the combination of the
visibility of each resource and the visibility of each attribute.

We used a flag variable for representing the visibility of the
resource attribute. The flag variable can extend to represent
other properties of the resource attribute.

Change-Id: Ie48f00f89ec6095e05e9f8fcf395e1ea0da026bb
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agotests: resource-monitor: Consider failure of monitor_init as fatal 48/280448/1 accepted/tizen/unified/20220830.133638 submit/tizen/20220830.081307
Dongwoo Lee [Tue, 30 Aug 2022 06:57:18 +0000 (23:57 -0700)]
tests: resource-monitor: Consider failure of monitor_init as fatal

Change-Id: Ifd7c90e2e92e7623d01928d933ed3ce7165a567c
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
20 months agotools: resource-monitor: Fix to use proper loop bound 47/280447/1
Dongwoo Lee [Tue, 30 Aug 2022 06:49:49 +0000 (23:49 -0700)]
tools: resource-monitor: Fix to use proper loop bound

Change-Id: I06f4561ea5ba3a626b03da5c8b4e7c6212b0bb9b
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
20 months agoutil: kernel: Get the name of smaps entry with limited width 30/280230/2
Dongwoo Lee [Thu, 25 Aug 2022 05:11:42 +0000 (14:11 +0900)]
util: kernel: Get the name of smaps entry with limited width

Since sscanf has no limitation for buffer width and thus it can cause
overflows for name buffer, this limits the number of reading
characters.

Change-Id: I83128e01d9b840d41bb14bfda022e27ee80dd78e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoutil: kernel: Use snprintf() instead of sprintf() 35/280235/2
Dongwoo Lee [Thu, 25 Aug 2022 08:06:18 +0000 (17:06 +0900)]
util: kernel: Use snprintf() instead of sprintf()

Change-Id: Ibb145e0928f2b582088a302788a33c586ccc4625
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agopass: Remove unnecessarily included headers 33/280233/2
Dongwoo Lee [Thu, 25 Aug 2022 07:34:51 +0000 (16:34 +0900)]
pass: Remove unnecessarily included headers

Change-Id: I165330bec604d60a46ebb4fca175671cda701b51
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agopass: Change the unit for gov_timeout into milliseconds from seconds 34/280234/2
Dongwoo Lee [Thu, 25 Aug 2022 08:04:01 +0000 (17:04 +0900)]
pass: Change the unit for gov_timeout into milliseconds from seconds

Since comparing two floating point number variable causes unintended
result, it converts type of gov_timeout from double to int, and keeps
precison by using unint as milliseconds instead of seconds.
for instance, 0.2sec can represent as 200ms, so despite of converting
type, users can setup gov_timeout with same precision.

Change-Id: Ib8efbca7e5d044a6871e2ef6c23274518cf1875e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource-monitor: Fix coverity issue 12/280112/3 submit/tizen/20220830.033447
Chanwoo Choi [Wed, 24 Aug 2022 05:29:31 +0000 (14:29 +0900)]
resource-monitor: Fix coverity issue

Change-Id: I1df8b406efd54de3154d3e26f74b97f5f57b8160
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotools: resource-monitor: Check validation of '-n' option argument 32/280232/3 submit/tizen/20220830.030501
Dongwoo Lee [Thu, 25 Aug 2022 05:47:00 +0000 (14:47 +0900)]
tools: resource-monitor: Check validation of '-n' option argument

Change-Id: I28dc6a85d44455043a56c49bdee824d2590757c0
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agotools: resource-monitor: Use strncat() instead of strcat() 31/280231/2
Dongwoo Lee [Thu, 25 Aug 2022 05:30:01 +0000 (14:30 +0900)]
tools: resource-monitor: Use strncat() instead of strcat()

Change-Id: I24ed13b38bdec088d2230b473033ef4888802893
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoresource: disk: Remove unnecessary pre-checking for opening file 36/280236/2
Dongwoo Lee [Thu, 25 Aug 2022 08:15:24 +0000 (17:15 +0900)]
resource: disk: Remove unnecessary pre-checking for opening file

Instead of checking file existence before opening, now just try to
open file. If the file does not exist, it makes errors though.
This also fixes the vulnerability reports about TOCTOU race condition
(CWE-367).

Change-Id: I10affc264666566b635e1cd8b91ad34fe5613845
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotests: unittest: pass: Use proper type for iteration index 29/280229/2
Dongwoo Lee [Thu, 25 Aug 2022 04:57:27 +0000 (13:57 +0900)]
tests: unittest: pass: Use proper type for iteration index

This fixes to use proper type for iteration index, and also refactor
the part of clear progress with same code for both success and failure
cases.

Change-Id: Ide70626a93328ef2bc9668addbf4ede73a345dca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotests: resource-monitor-tests: Fix wrong expected value on invalid test 13/280113/3 accepted/tizen/unified/20220830.032644 submit/tizen/20220829.102006
Chanwoo Choi [Wed, 24 Aug 2022 05:30:03 +0000 (14:30 +0900)]
tests: resource-monitor-tests: Fix wrong expected value on invalid test

commit 5f56fe2eddb0("lib: resource-monitor: Change
pass_resourced_monitor_is_resource_attr_supported prototype")
added the wrong expected value in
pass_resource_monitor_is_resource_attr_supported_invalid test case.

For invalid case test, the expected value is not same with 0 (zero).
Fix wrong expected value on pass_resource_monitor_is_resource_attr_supported_invalid.

Change-Id: I2a564f4b548b86733b265c9b64217653133697dc
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoresource: process: Fix to convert to double before integer division 28/280228/1
Dongwoo Lee [Thu, 25 Aug 2022 04:46:28 +0000 (13:46 +0900)]
resource: process: Fix to convert to double before integer division

In order to prevent losing floating point number for the result of
integer division, integer value is coverted to double before
calculation.

Change-Id: I38c19c1468167ed1203417f03d187dcf0893e6ca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: system: Fix to check NULL for private data 27/280227/1
Dongwoo Lee [Thu, 25 Aug 2022 04:44:44 +0000 (13:44 +0900)]
resource: system: Fix to check NULL for private data

Change-Id: I70cb0cfd108ec165d8a863cf6c4c35ea42571b69
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoutil: kernel: Use proper data type for the id of cpu stat 26/280226/1
Dongwoo Lee [Thu, 25 Aug 2022 04:38:58 +0000 (13:38 +0900)]
util: kernel: Use proper data type for the id of cpu stat

To represent 'cpu' case in '/proc/stat' which has summation for all
cpus, the number of cpu is set to -1, but data type of number is
unsigned int. This corrects data type and change the name of member
from 'cpu' to 'id' for understanding meaning easily.
In addition, since 'id' is used as index of cpu stat array, it also
checks that the index is in the proper range.

Change-Id: I7e368176257c695d59420e7b4906d5bdb6d8aadf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agomonitor: Add a missing request name 75/280075/3 accepted/tizen/unified/20220824.042352 submit/tizen/20220823.090210
Sung-hun Kim [Tue, 23 Aug 2022 07:20:48 +0000 (16:20 +0900)]
monitor: Add a missing request name

Change-Id: I9016d95e8dd2391fc9a6bd2f35fd6b2ef1798c54
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agoutil: common: Add missing case break 82/280082/1
Seung-Woo Kim [Tue, 23 Aug 2022 08:50:00 +0000 (17:50 +0900)]
util: common: Add missing case break

Non fall through case has no break. Add the missing
case break.

Change-Id: I45876a7c36b6d4c9642f0534d9b82aa3e54fa928
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
20 months agoresource: system: Calculate average cpu utilization with per-cpu stat 84/279984/3
Dongwoo Lee [Fri, 19 Aug 2022 10:05:05 +0000 (19:05 +0900)]
resource: system: Calculate average cpu utilization with per-cpu stat

In a situation where the number of online cpus is dynamically changed,
measuring the total system cpu usage by using the sum of the online
cpus usage time located at the top of '/proc/stat' will result in
inaccurate results. For example, suppose that the number of online
cpus changed from 2 to 1 between two time intervals. In this case, the
sum of the cpu time measured later is rather reduced than the sum of
the cpu time measured first, and if the cpu usage rate is calculated
using the difference between these two cpu times, a negative result
will come out. To prevent this situation, the average usage is
calculated by summing the usage time of each CPU; assuming that the
usage rate is 0% for offline CPUs.

Change-Id: I93e4561f525b54488df46bf0f895fa76b3b710ca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoutil: kernel: Fix to return valid result on getting cpu stat 83/279983/3
Dongwoo Lee [Fri, 19 Aug 2022 10:03:59 +0000 (19:03 +0900)]
util: kernel: Fix to return valid result on getting cpu stat

In the case of the target which supports cpu hotplug, the number of
possible online cpus can be changed and thus __get_cpu_stat can be
failed for offline cpus. At worst case if the last __get_cpu_stat is
resulted in negative, kernel_get_per_cpu_stat can return error even
though it is not actual failure. To prevent this situation, this
ignores the case that __get_cpu_stat returns failure.

Change-Id: I5d33e740b2451e7c644b407c1f92785a1e570585
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: Distinguish driver initalization from instance creation 82/279982/2 submit/sandbox/chanwoochoi/tizen/20220823.070906 submit/tizen/20220823.075403
Dongwoo Lee [Fri, 19 Aug 2022 09:21:57 +0000 (18:21 +0900)]
resource: Distinguish driver initalization from instance creation

In the previous commits, each resource driver has the distinguished
operation for both initialization and creation. This makes the codes
are properly distributed into two operations.

Change-Id: Ia3d72914a3277e0d6d18634dff60a9e9763ec362
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: Initialize all resource drivers at start up 81/279981/2
Dongwoo Lee [Fri, 19 Aug 2022 07:30:29 +0000 (16:30 +0900)]
resource: Initialize all resource drivers at start up

Instead of initalizing common or permanent data for resource drivers
at creation, now all initialization will be done at start up once.

Change-Id: Idf673d3997c3567b572bcc9ea6dae5e887a0d3f3
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: Add the new device ops create/delete 80/279980/2
Dongwoo Lee [Thu, 18 Aug 2022 11:23:56 +0000 (20:23 +0900)]
resource: Add the new device ops create/delete

To separate initialization and instance creation on resource driver,
the new ops create/delete are introduced. Now, each operation is
used as below:
 - init: Setup the common contexts for resource (called once)
 - exit: Clear the init-ed contexts (called once)
 - create: Create resource instance with an individual context
 - delete: Free own context and remove resource instance

Change-Id: I4987f26afd6de7e7ec0b1d8ed6a724acbf55e374
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agopass: Include resource header inside pass.c 40/280040/1
Dongwoo Lee [Mon, 22 Aug 2022 23:27:57 +0000 (08:27 +0900)]
pass: Include resource header inside pass.c

Currently resource.h is only used in pass.c, but it is included in
pass.h and it rather prevents using "delete" keyword due to be used
in haltests which is built by cpp compiler. So, this makes resource
header be only included in pass.c directly.

Change-Id: I3360ceb217ec5d95a75f17a65f2b39bf10e12af6
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agomonitor: Restructure request server 79/279979/3
Dongwoo Lee [Thu, 18 Aug 2022 11:09:54 +0000 (20:09 +0900)]
monitor: Restructure request server

In order to make all initialization about resource monitor handled
in monitor module, convert request-server and request-handler from
the distinguish module to a part of monitor module.

Change-Id: I820147add2b44c40fb0ce1d8e9223c708037adc1
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agolib: resource-monitor: Change pass_resourced_monitor_is_resource_attr_supported prototype 11/280011/2 accepted/tizen/unified/20220823.005726 submit/tizen/20220822.094833 submit/tizen/20220822.102536
Chanwoo Choi [Mon, 22 Aug 2022 07:59:08 +0000 (16:59 +0900)]
lib: resource-monitor: Change pass_resourced_monitor_is_resource_attr_supported prototype

Change pass_resourced_monitor_is_resource_attr_supported prototype
to express the various error case and then get the value from l-value
style parameter.

[Before]
bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id);

[After]
int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported);

Change-Id: If4943e034db0a180807a85700ac2db7c87ecef5a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agolib: resource-monitor: Replace with TIZNE_ERROR_* defintion to handle error 27/279927/1
Chanwoo Choi [Fri, 19 Aug 2022 06:00:06 +0000 (15:00 +0900)]
lib: resource-monitor: Replace with TIZNE_ERROR_* defintion to handle error

Replace with TIZNE_ERROR_* defintion to handle error as following:

 0       : TIZEN_ERROR_NONE (success)
 -EINVAL : TIZEN_ERROR_INVALID_PARAMETER
 -EIO    : TIZEN_ERROR_NO_DATA
 -ENOMEM : TIZEN_ERROR_OUT_OF_MEMORY

Change-Id: I1d14719c21c3a4f6f2224c9f76e00ff762b8c889
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotools: resource-monitor: Keep the alignment of resource attribute name 56/279856/1 accepted/tizen/unified/20220818.230237 submit/tizen/20220818.160813
Chanwoo Choi [Thu, 18 Aug 2022 09:39:51 +0000 (18:39 +0900)]
tools: resource-monitor: Keep the alignment of resource attribute name

commit f59279ad7f63 ("resource: Change bytes unit attributes to kilo-bytes")
changed the attribute name of both PROCESS_GROUP_ATTR_DISK_READ_PER_SEC
and PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC. So that break the alignment
when print the resource attribute name by resource-monitor cli tool.

Extend the width length for resource attribute name to keep the printing
alignement.

- Before change:
 7: 2|         PROCESS_GROUP_ATTR_CPU_UTIL |                                     0.27 | %     | Process-group CPU utilization
 7: 3| PROCESS_GROUP_ATTR_DISK_READ_PER_SEC |                                     0.00 | kB/s  | Process-group disk read per second
 7: 4| PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC |                                     0.00 | kB/s  | Process-group disk write per second
 7: 5|         PROCESS_GROUP_ATTR_MEM_VIRT |                                132923188 | kB    | Process-group VIRT memory size

- After change:
 7: 2|              PROCESS_GROUP_ATTR_CPU_UTIL |                                     0.21 | %     | Process-group CPU utilization
 7: 3|     PROCESS_GROUP_ATTR_DISK_READ_PER_SEC |                                     0.00 | kB/s  | Process-group disk read per second
 7: 4|    PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC |                                     0.00 | kB/s  | Process-group disk write per second
 7: 5|              PROCESS_GROUP_ATTR_MEM_VIRT |                                135495517 | kB    | Process-group VIRT memory size

Change-Id: I62a937f1edb9c85979cd6f309b12e94256dbeaed
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoresource: process: Fix to use proper attribute name 66/279766/3
Dongwoo Lee [Wed, 17 Aug 2022 08:45:58 +0000 (17:45 +0900)]
resource: process: Fix to use proper attribute name

Change-Id: Icef625156eb2036672f2798f4f0d65d943e3ab6f
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: process: Handle the case that target cannot support taskstats 65/279765/3
Dongwoo Lee [Wed, 17 Aug 2022 08:42:43 +0000 (17:42 +0900)]
resource: process: Handle the case that target cannot support taskstats

Since PROCESS resource has some attributes which require taskstats,
those attributes are mark to unsupported or provided by other methods
when the target does not support taskstats.

Change-Id: I83a0eab243367f59c518d1b1c422b741f3e611bb
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoresource: process-group: Handle the case that target cannot support taskstats 64/279764/3
Dongwoo Lee [Wed, 17 Aug 2022 06:33:18 +0000 (15:33 +0900)]
resource: process-group: Handle the case that target cannot support taskstats

all attributes in PROCESS_GROUP resource require taskstats, all
attributes are mark to unsupported when the target does not support
taskstats.

Change-Id: I21a36949e34e7cf3fb050694b1cbddd31e954247
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoutil: kernel: Add check whether taskstats is supported 63/279763/1
Dongwoo Lee [Wed, 17 Aug 2022 06:31:53 +0000 (15:31 +0900)]
util: kernel: Add check whether taskstats is supported

Since taskstats has various version by kernel, handling it should be
taken by considering versions. However, some task accounting is not
supported by older kernel, we should check whether it is supported or
not. This adds check procedure into constructor.

Change-Id: Ib18f01b1a3060baaba3212fdc728cd7a7ff77849
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
20 months agoPASS v2.0.0 85/279585/1 accepted/tizen/unified/20220817.153742 submit/tizen/20220812.041529 submit/tizen/20220813.015631 submit/tizen/20220813.034544 submit/tizen/20220817.021541
Chanwoo Choi [Fri, 12 Aug 2022 02:48:03 +0000 (11:48 +0900)]
PASS v2.0.0

Changes from v1.2.0
1. Add new resource-monitor framework with daemon and various resource drivers
2. Provide libpass-resource-monitor library for resource monitoring
3. Provide resource-monitor tool and resource-monitor-tests

Change-Id: I5d6ccbeb08d29a15181e2c74112b509f99769c58
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotests: resource-monitor-tests: Add missing array data type if DATA_TYPE_ARRAY 43/279543/2
Chanwoo Choi [Thu, 11 Aug 2022 07:29:49 +0000 (16:29 +0900)]
tests: resource-monitor-tests: Add missing array data type if DATA_TYPE_ARRAY

Change-Id: I3606a29597ba9cd16c47defba5b99055b25b5d22
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agotools: resource-monitor: Add missing BATTERY_ATTR_ONLINE attribute 29/279429/4
Chanwoo Choi [Tue, 9 Aug 2022 06:00:23 +0000 (15:00 +0900)]
tools: resource-monitor: Add missing BATTERY_ATTR_ONLINE attribute

Change-Id: I37cea2d7cfd3b5f3b4478d152c1fa84682da021e
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agolib: resource-monitor: Add missing request for the readability 28/279428/4
Chanwoo Choi [Mon, 8 Aug 2022 19:41:13 +0000 (04:41 +0900)]
lib: resource-monitor: Add missing request for the readability

Add missing request for the readability to switch statement
to improve the readability when handling the request.

Change-Id: I1b322bd30d4db913fd438394089e95b4716133a6
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agolib: resource-monitor: Add pass_resource_monitor_is_resource_attr_set 27/279427/4
Chanwoo Choi [Wed, 20 Jul 2022 08:53:37 +0000 (17:53 +0900)]
lib: resource-monitor: Add pass_resource_monitor_is_resource_attr_set

Provide pass_resource_monitor_is_resource_attr_set function
to check whether some attributes are set or not.

And fix the comment of pass_resource_monitor_is_resource_attr_supported.

Change-Id: I3b1372ecc1138d2244da66e79745ca6454ff67eb
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoutil: resource: Add resource flag to express the specific features 26/279426/4
Chanwoo Choi [Mon, 8 Aug 2022 18:46:42 +0000 (03:46 +0900)]
util: resource: Add resource flag to express the specific features

Each resource are able to have the non-common features.
The resource flag will be used to indicate the characteristics
of resource.

- RESOURCE_FLAG_COUNT_ONLY_ONE
  : Some resource's resource count is only one on all board such as system and
  memory resources. Add this flag when want to return 1 as resource count.
- RESOURCE_FLAG_PROCESS
  : process and process-group are not physical resource like CPU/GPU/Memory.
  Sometimes, it should be handled by the different handling. In order to
  separate out them, use this flag.

Change-Id: Ic7df2cae2105b14382c0f084c30fbbcde5efdac4
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agolib: resource-monitor: Change prototype of pass_resource_monitor_get_resource_count 47/279547/1
Chanwoo Choi [Fri, 5 Aug 2022 17:31:24 +0000 (02:31 +0900)]
lib: resource-monitor: Change prototype of pass_resource_monitor_get_resource_count

Almost get_value functions get the value by using l-value parameter.
In order to keep the consistent function prototype stule,
change the prototype of pass_resource_monitor_get_resource_count function
as following:

- before: int pass_resource_monitor_get_resource_count(int id, int resource_type);
- after : int pass_resource_monitor_get_resource_count(int id, int resource_type, int *resource_count);

Change-Id: Ic18f45a1ee4bbd4f9320751541cf00b3f4d9f5c8
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
20 months agoresource: display: Add a display monitor thread to deal with multiple clients 18/279418/9
Sung-hun Kim [Tue, 9 Aug 2022 05:45:55 +0000 (14:45 +0900)]
resource: display: Add a display monitor thread to deal with multiple clients

When multiple clients request to get fps concurrently,
unacceptable delays (upto tens of seconds for hundred
clients) are incurred. I guess that the dbus function
g_dbus_connection_send_message_with_reply_sync() cannot
deal with multiple concurrent calls.

This patch added a monitor thread to read current fps
value via dbus. The thread shares read fps value to
clients. By doing so, multiple clients can get the fps
value without delays.

Change-Id: I726092658ef79af3610baa6fa356d8a54c6cf299
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agoutil: thread: Use wait_for_completion without result
Sung-hun Kim [Tue, 9 Aug 2022 02:01:48 +0000 (11:01 +0900)]
util: thread: Use wait_for_completion without result

Change-Id: I3969491c2ce9d8ecccfdb064bc65274cb05cb53f
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
20 months agoresource: Change bytes unit attributes to kilo-bytes
Dongwoo Lee [Tue, 9 Aug 2022 01:53:47 +0000 (18:53 -0700)]
resource: Change bytes unit attributes to kilo-bytes

In order to sync up with attributes of disk resource, the remaining
memory- and disk-related attributes are changed to use kilo-bytes unit
from now on. As following the unit changes, the name of attributes are
either changed as belows:
 - PROCESS_ATTR_DISK_READ_BPS -> PROCESS_ATTR_DISK_READ_PER_SEC
 - PROCESS_ATTR_DISK_WRITE_BPS -> PROCESS_ATTR_DISK_WRITE_PER_SEC
 - PROCESS_GROUP_ATTR_DISK_READ_BPS -> PROCESS_GROUP_ATTR_DISK_READ_PER_SEC
 - PROCESS_GROUP_ATTR_DISK_WRITE_BPS -> PROCESS_GROUP_ATTR_DISK_WRITE_PER_SEC

Change-Id: I2c09a6f4ef9511c2add3a559efa19f94d0253216
Signed-off-by: Dongwoo Lee <dwlee08@gmail.com>
20 months agolib: resource-monitor: Extract common function for readability and remove duplicate... submit/tizen/20220809.025855
Chanwoo Choi [Wed, 20 Jul 2022 08:52:13 +0000 (17:52 +0900)]
lib: resource-monitor: Extract common function for readability and remove duplicate code

Almost resource-monitor functions are composed with the following steps
to communicate with resource-monitor daemon. It means that there are
the many similiar code to support resource-monitor feature.
1. send request
2. recv response
3. parse data from response
4. validate the data

In order to reduece the duplicate code and improve the readability,
extract the common functions as handle_request with struct request_data.

Change-Id: I413e3dd157093507d099892b0d3123bcf0641f4b
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>