4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <sys/types.h>
30 #include <dbus/dbus-glib.h>
31 #include <dbus/dbus.h>
32 #include <dbus/dbus-glib-lowlevel.h>
33 #include <sys/statvfs.h>
35 #ifdef _SET_VIP_PROCESS
36 #include <sys/prctl.h>
38 #include <system_info.h>
39 #include <dd-display.h>
41 #ifndef _USE_DEVICED_DBUS
42 #include <usb-device.h>
45 #include "media-util.h"
46 #include "media-server-ipc.h"
47 #include "media-common-dbg.h"
48 #include "media-common-system.h"
49 #include "media-common-utils.h"
51 #define MS_DRM_CONTENT_TYPE_LENGTH 100
53 /* it's for 32bit file offset */
55 unsigned long int f_bsize;
56 unsigned long int f_frsize;
57 unsigned long int f_blocks;
58 unsigned long int f_bfree;
59 unsigned long int f_bavail;
60 unsigned long int f_files;
61 unsigned long int f_ffree;
62 unsigned long int f_favail;
63 unsigned long int f_fsid;
64 #ifdef _STATVFSBUF_F_UNUSED
67 unsigned long int f_flag;
68 unsigned long int f_namemax;
72 bool ms_is_mmc_inserted(void)
75 ms_stg_type_e stg_type = MS_STG_TYPE_MMC;
76 GArray *dev_list = NULL;
78 ret = ms_sys_get_device_list(stg_type, &dev_list);
79 if (ret == MS_MEDIA_ERR_NONE) {
80 if (dev_list != NULL) {
81 MS_DBG_ERR("MMC FOUND[%d]", dev_list->len);
82 ms_sys_release_device_list(&dev_list);
85 MS_DBG_ERR("MMC NOT FOUND");
88 MS_DBG_ERR("ms_sys_get_device_list failed");
94 static char* __media_get_path(uid_t uid)
96 char *result_passwd = NULL;
97 struct group *grpinfo = NULL;
99 grpinfo = getgrnam("users");
100 if (grpinfo == NULL) {
101 MS_DBG_ERR("getgrnam(users) returns NULL !");
105 if (uid == getuid()) {
106 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
107 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
109 struct passwd *userinfo = getpwuid(uid);
110 if (userinfo == NULL) {
111 MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
115 // Compare git_t type and not group name
116 if (grpinfo->gr_gid != userinfo->pw_gid) {
117 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
120 result_passwd = strndup(userinfo->pw_dir, strlen(userinfo->pw_dir));
123 return result_passwd;
126 ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid)
129 int ret = MS_MEDIA_ERR_NONE;
130 char * user_path = NULL;
133 return MS_MEDIA_ERR_INVALID_PATH;
135 #ifdef _USE_SENIOR_MODE
136 if(ms_is_support_senior_mode()) {
137 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0) {
138 return MS_STORAGE_EXTERNAL;
143 user_path = __media_get_path(uid);
144 if (user_path == NULL)
145 return MS_MEDIA_ERR_OUT_OF_MEMORY;
147 length_path = strlen(user_path);
149 if (strncmp(path, user_path, length_path) == 0) {
150 ret = MS_STORAGE_INTERNAL;
151 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
152 ret = MS_STORAGE_EXTERNAL;
153 } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
154 ret = MS_STORAGE_EXTERNAL_USB;
156 MS_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
157 ret = MS_MEDIA_ERR_INVALID_PATH;
160 MS_SAFE_FREE(user_path);
165 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
168 int real_size = size - 1;
170 if (!res || !pattern || !str1 || !str2)
171 return MS_MEDIA_ERR_INVALID_PARAMETER;
173 if (real_size < (int)(strlen(str1) + strlen(str2)))
174 return MS_MEDIA_ERR_INVALID_PARAMETER;
176 len = snprintf(res, real_size, pattern, str1, str2);
178 return MS_MEDIA_ERR_INVALID_PARAMETER;
183 return MS_MEDIA_ERR_NONE;
186 int ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
189 int real_size = size;
191 if (!res || !pattern || !str1) {
192 MS_DBG_ERR("parameta is invalid");
193 return MS_MEDIA_ERR_INVALID_PARAMETER;
196 if (real_size < (int)(strlen(str1))) {
197 MS_DBG_ERR("size is wrong");
198 return MS_MEDIA_ERR_INVALID_PARAMETER;
201 len = snprintf(res, real_size, pattern, str1);
203 MS_DBG_ERR("snprintf failed");
204 return MS_MEDIA_ERR_INVALID_PARAMETER;
209 return MS_MEDIA_ERR_NONE;
212 bool ms_config_get_int(const char *key, int *value)
216 if (!key || !value) {
217 MS_DBG_ERR("Arguments key or value is NULL");
221 err = vconf_get_int(key, value);
227 MS_DBG_ERR("Unexpected error code: %d", err);
232 bool ms_config_set_int(const char *key, int value)
237 MS_DBG_ERR("Arguments key is NULL");
241 err = vconf_set_int(key, value);
247 MS_DBG_ERR("Unexpected error code: %d", err);
252 bool ms_config_get_str(const char *key, char **value)
256 if (key == NULL || value == NULL) {
257 MS_DBG_ERR("Arguments key or value is NULL");
261 res = vconf_get_str(key);
262 if (MS_STRING_VALID(res)) {
263 *value = strdup(res);
271 bool ms_config_set_str(const char *key, const char *value)
275 if (!key || !value) {
276 MS_DBG_ERR("Arguments key or value is NULL");
280 err = vconf_set_str(key, value);
284 MS_DBG_ERR("fail to vconf_set_str %d", err);
289 bool ms_config_get_bool(const char *key, int *value)
293 if (!key || !value) {
294 MS_DBG_ERR("Arguments key or value is NULL");
298 err = vconf_get_bool(key, value);
304 MS_DBG_ERR("Unexpected error code: %d", err);
309 static int get_memory_size(const char *path, struct statvfs_32 *buf)
314 ret = statvfs(path, &s);
316 MS_DBG_ERR("statvfs failed[%d]", ret);
318 return MS_MEDIA_ERR_INTERNAL;
321 buf->f_bsize = s.f_bsize;
322 buf->f_frsize = s.f_frsize;
323 buf->f_blocks = (unsigned long)s.f_blocks;
324 buf->f_bfree = (unsigned long)s.f_bfree;
325 buf->f_bavail = (unsigned long)s.f_bavail;
326 buf->f_files = (unsigned long)s.f_files;
327 buf->f_ffree = (unsigned long)s.f_ffree;
328 buf->f_favail = (unsigned long)s.f_favail;
329 buf->f_fsid = s.f_fsid;
330 buf->f_flag = s.f_flag;
331 buf->f_namemax = s.f_namemax;
333 return MS_MEDIA_ERR_NONE;
336 int ms_get_remain_space(double *free_space)
338 int ret = MS_MEDIA_ERR_NONE;
339 struct statvfs_32 temp;
341 ret = get_memory_size("/opt", &temp);
342 if (ret != MS_MEDIA_ERR_NONE) {
343 MS_DBG_ERR("fail to get memory size");
347 // MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
349 *free_space = (double)temp.f_bsize*temp.f_bavail;
354 #ifdef _USE_RECORDED_CONTENT
355 bool ms_is_support_pvr(void)
359 if (system_info_get_value_int(SYSTEM_INFO_KEY_PVR_SUPPORTED, &nSupportPVR) != SYSTEM_INFO_ERROR_NONE) {
360 MS_DBG_ERR("Get PVR Support failed");
364 MS_DBG("PVR Support : [%d]", nSupportPVR);
366 return (nSupportPVR != 0);
370 #ifdef _USE_SENIOR_MODE
371 bool ms_is_support_senior_mode()
373 bool bSupportSeniorMode = false;
375 if(system_info_get_value_bool(SYSTEM_INFO_KEY_GET_SENIOR_MODE_SUPPORTED, &bSupportSeniorMode) != SYSTEM_INFO_ERROR_NONE) {
376 MS_DBG_ERR("Get senior mode support failed");
380 MS_DBG("Senior mode support : [%d]", bSupportSeniorMode);
382 return bSupportSeniorMode;
386 int ms_check_file_path(const char *file_path, uid_t uid)
391 /* check location of file */
392 /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
393 if (!ms_is_valid_path(file_path, uid)) {
394 MS_DBG_ERR("Invalid path : %s", file_path);
395 return MS_MEDIA_ERR_INVALID_PATH;
398 /* check the file exits actually */
399 exist = open(file_path, O_RDONLY);
401 MS_DBG_ERR("[%s]open files");
402 return MS_MEDIA_ERR_INVALID_PATH;
406 /* check type of the path */
407 /* It must be a regular file */
408 memset(&file_st, 0, sizeof(struct stat));
409 if (stat(file_path, &file_st) == 0) {
410 if (!S_ISREG(file_st.st_mode)) {
411 /* In this case, it is not a regula file */
412 MS_DBG_ERR("this path is not a file");
413 return MS_MEDIA_ERR_INVALID_PATH;
416 MS_DBG_STRERROR("stat failed");
417 return MS_MEDIA_ERR_INVALID_PATH;
420 return MS_MEDIA_ERR_NONE;
423 int ms_check_ignore_dir(const char *full_path, uid_t uid)
425 int ret = MS_MEDIA_ERR_NONE;
426 char *dir_path = NULL;
427 char *leaf_path = NULL;
428 char *usr_path = NULL;
430 ret = ms_check_file_path(full_path, uid);
431 if (ret != MS_MEDIA_ERR_NONE) {
432 MS_DBG_ERR("invalid path : %s", full_path);
433 return MS_MEDIA_ERR_INVALID_PATH;
436 dir_path = g_path_get_dirname(full_path);
437 if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
438 MS_DBG_ERR("getting directory path is failed : %s", full_path);
439 MS_SAFE_FREE(dir_path);
440 return MS_MEDIA_ERR_INVALID_PATH;
443 usr_path = ms_get_path(uid);
444 if (usr_path == NULL) {
445 MS_DBG_ERR("ms_get_path() fail");
446 MS_SAFE_FREE(dir_path);
447 return MS_MEDIA_ERR_INTERNAL;
451 if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
452 ret = MS_MEDIA_ERR_INVALID_PATH;
456 #ifdef _USE_SENIOR_MODE
457 if(ms_is_support_senior_mode()) {
458 if(strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
462 if (strcmp(dir_path, usr_path) == 0)
464 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
466 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
469 leaf_path = strrchr(dir_path, '/');
470 if (leaf_path != NULL) {
471 int seek_len = leaf_path -dir_path;
472 dir_path[seek_len] = '\0';
474 MS_DBG_ERR("Fail to find leaf path");
475 ret = MS_MEDIA_ERR_INVALID_PATH;
480 MS_SAFE_FREE(dir_path);
481 MS_SAFE_FREE(usr_path);
486 int ms_check_scan_ignore(char * path)
490 const char *ignore_path = "/.scan_ignore";
491 char *check_ignore_file = NULL;
492 int ret = MS_MEDIA_ERR_NONE;
494 if (strstr(path, "/.")) {
495 MS_DBG_ERR("hidden path");
496 ret = MS_MEDIA_ERR_INVALID_PATH;
500 fd = open(path, O_RDONLY | O_DIRECTORY);
502 MS_DBG_ERR("%s folder opendir fails", path);
503 ret = MS_MEDIA_ERR_INVALID_PATH;
505 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
506 MS_DBG_ERR("Fail to get USB path");
510 if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
511 if (errno == ENOENT) {
512 /*if the directory does not exist, check the device is unmounted*/
513 if (!ms_storage_mount_status(path)) {
514 MS_DBG_ERR("Device is unmounted[%s]", path);
515 ret = MS_MEDIA_ERR_USB_UNMOUNTED;
521 struct stat folder_st;
522 if (stat(path, &folder_st) == 0) {
523 MS_DBG_ERR("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
524 (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
526 MS_DBG_ERR("%s folder stat fails", path);
531 /* check the file exits actually */
534 path_len = strlen(path) + strlen(ignore_path) + 1;
535 check_ignore_file = malloc(path_len);
536 if (check_ignore_file != NULL) {
537 memset(check_ignore_file, 0x0, path_len);
538 snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
540 exist = open(check_ignore_file, O_RDONLY);
542 MS_DBG_ERR("scan_ignore exists [%s]", check_ignore_file);
543 ret = MS_MEDIA_ERR_INVALID_PATH;
546 MS_SAFE_FREE(check_ignore_file);
548 MS_DBG_ERR("malloc failed");
549 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
560 if (exist >= 0) close(exist);
565 char* ms_get_path(uid_t uid)
568 char *result_passwd = NULL;
571 struct group grpinfo;
572 struct group* grpresult = NULL;
575 grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
576 if (grpbufsize == -1) /* Value was indeterminate */
577 grpbufsize = 16384; /* Should be more than enough (16*1024) */
579 grpbuf = malloc(grpbufsize);
580 if (grpbuf == NULL) {
581 MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
585 ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
586 if((ret == 0) && (grpresult != NULL)) {
587 MS_DBG("getgrnam_r users success...\n");
589 MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
593 if (uid == getuid()) {
594 if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
595 result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
597 char passwd_str[MAX_FILEPATH_LEN] = {0, };
598 struct passwd pwdinfo;
599 struct passwd* pwdresult = NULL;
603 pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
604 if (pwdbufsize == -1) /* Value was indeterminate */
605 pwdbufsize = 16384; /* Should be more than enough (16*1024) */
607 pwdbuf = malloc(pwdbufsize);
608 if (pwdbuf == NULL) {
609 MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
613 ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
614 if((ret == 0) && (pwdresult != NULL)) {
615 MS_DBG("getpwuid uid[%d] success\n", uid);
617 MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
618 MS_SAFE_FREE(pwdbuf);
622 // Compare git_t type and not group name
623 if (grpinfo.gr_gid != pwdinfo.pw_gid) {
624 MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
628 len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", pwdinfo.pw_dir, MEDIA_CONTENT_PATH);
630 result_passwd = strndup(passwd_str, len);
634 MS_SAFE_FREE(grpbuf);
635 return result_passwd;
638 bool ms_storage_mount_status(const char* start_path)
641 #ifndef _USE_DEVICED_DBUS
644 usb_device_list_h list;
646 char *mount_path = NULL;
648 char *storage_path = NULL;
649 char *remain_path = NULL;
652 remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
653 if (remain_path != NULL)
654 remain_len = strlen(remain_path);
656 storage_path = strndup(start_path, strlen(start_path) - remain_len);
658 MS_DBG_ERR("storage_path [%s]", storage_path);
660 err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
662 count = usb_device_list_get_count(list);
664 err = usb_device_list_get_first(list, &device);
665 if(err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
666 mount_path = usb_device_get_mountpath(device);
667 if (mount_path != NULL) {
668 MS_DBG_ERR("mount_path [%s]", mount_path);
669 if (strlen(mount_path) == strlen(storage_path)) {
670 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
671 MS_DBG_ERR("start path is mounted [%s]", start_path);
679 while(usb_device_list_get_next(list, &device) == 0) {
681 mount_path = usb_device_get_mountpath(device);
682 if (mount_path != NULL) {
683 MS_DBG_ERR("mount_path [%s]", mount_path);
684 if (strlen(mount_path) == strlen(storage_path)) {
685 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
686 MS_DBG_ERR("start path is mounted [%s]", start_path);
697 usb_device_free_device_list(list);
699 MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
702 MS_SAFE_FREE(storage_path);
707 bool ms_is_valid_path(const char *path, uid_t uid)
710 char *usr_path = NULL;
715 usr_path = ms_get_path(uid);
716 if (usr_path == NULL)
719 #ifdef _USE_SENIOR_MODE
720 if(ms_is_support_senior_mode()) {
721 if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
726 if (strncmp(path, usr_path, strlen(usr_path)) == 0)
728 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
730 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
735 MS_SAFE_FREE(usr_path);
740 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
742 int res = MS_MEDIA_ERR_NONE;
745 if (status == MS_DB_UPDATING) {
746 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
747 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
748 MS_DBG_ERR("ms_config_set_int failed");
751 if (storage_type == MS_STORAGE_EXTERNAL) {
752 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
753 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
754 MS_DBG_ERR("ms_config_set_int failed");
758 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
759 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
760 MS_DBG_ERR("ms_config_set_int failed");
763 if (storage_type == MS_STORAGE_EXTERNAL) {
764 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
765 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
766 MS_DBG_ERR("ms_config_set_int failed");
771 err = ms_set_power_mode(status);
772 if (err != MS_MEDIA_ERR_NONE) {
773 MS_DBG_ERR("ms_set_power_mode fail");
780 int ms_set_power_mode(ms_db_status_type_t status)
782 int res = MS_MEDIA_ERR_NONE;
787 err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
789 res = MS_MEDIA_ERR_INTERNAL;
792 err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
794 res = MS_MEDIA_ERR_INTERNAL;
797 MS_DBG_ERR("Unacceptable type : %d", status);
804 void ms_trim_dir_path(char *dir_path)
806 /* need implementation */
807 /* if dir_path is not NULL terminated, this function will occure crash */
808 int len = strlen(dir_path);
810 if (dir_path[len -1] == '/')
811 dir_path[len -1] = '\0';
814 bool ms_check_folder_path(const char *folder_path)
818 dp = opendir(folder_path);
820 MS_DBG_ERR("Deleted folder path");
828 int ms_check_size_mediadb(uid_t uid, double *db_size)
830 int ret = MS_MEDIA_ERR_NONE;
831 char *db_path = NULL;
834 ret = media_db_get_media_db_path(uid, &db_path);
836 if(stat(db_path, &buf) == 0) {
837 *db_size = buf.st_size;
839 MS_DBG_STRERROR("stat failed");
840 ret = MS_MEDIA_ERR_INTERNAL;
843 MS_SAFE_FREE(db_path);
848 #ifdef _SET_VIP_PROCESS
849 #define PROC_OOM_SCORE_ADJ_PATH "/proc/%d/oom_score_adj"
850 #define VIP_OOM_SCORE_ADJ (-1000)
851 #define PROC_NAME_MAX 1024
852 #define PROC_BUF_MAX 64
854 static int ms_get_cmdline_from_proc(pid_t pid, char *cmdline)
856 char buf[PROC_BUF_MAX];
857 char cmdline_buf[PROC_NAME_MAX];
861 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
862 fp = fopen(buf, "r");
864 return MS_MEDIA_ERR_INTERNAL;
866 if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) {
868 return MS_MEDIA_ERR_INTERNAL;
872 filename = strrchr(cmdline_buf, '/');
873 if (filename == NULL)
874 filename = cmdline_buf;
876 filename = filename + 1;
878 strncpy(cmdline, filename, PROC_NAME_MAX-1);
880 return MS_MEDIA_ERR_NONE;
883 int ms_set_vip_process(void)
887 static pid_t pid = 0;
888 static char process_name[PROC_NAME_MAX] = {0};
889 static char *appid = NULL;
893 if (ms_get_cmdline_from_proc(pid, process_name)) {
894 MS_DBG_ERR("%s: Read process name failed pid[%d]\n", __func__, pid);
895 return MS_MEDIA_ERR_INTERNAL;
897 appid = process_name;
899 MS_DBG("Process name[%s]:Pid[%d]", appid, pid);
901 if (prctl(PR_GET_DUMPABLE) == 0)
902 prctl(PR_SET_DUMPABLE, 1);
904 snprintf(buf, sizeof(buf), PROC_OOM_SCORE_ADJ_PATH, pid);
905 id = open(buf, O_WRONLY, 0777);
907 MS_DBG_ERR("fopen %s failed errno:%d", buf, errno);
908 return MS_MEDIA_ERR_INTERNAL;
910 snprintf(buf, sizeof(buf), "%d", VIP_OOM_SCORE_ADJ);
911 if (write(id, buf, strlen(buf)) < 0) {
912 MS_DBG_ERR("write() failed errno=%d", errno);
914 return MS_MEDIA_ERR_INTERNAL;
917 return MS_MEDIA_ERR_NONE;