fix invalid format argument types for dlog
[platform/core/multimedia/media-server.git] / src / common / media-common-utils.c
1 /*
2  * Media Server
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <sys/types.h>
23 #include <fcntl.h>
24 #include <errno.h>
25 #include <vconf.h>
26 #include <aul/aul.h>
27 #include <grp.h>
28 #include <pwd.h>
29 #include <dbus/dbus-glib.h>
30 #include <dbus/dbus.h>
31 #include <dbus/dbus-glib-lowlevel.h>
32 #include <sys/statvfs.h>
33 #include <sys/stat.h>
34 #ifdef _SET_VIP_PROCESS
35 #include <sys/prctl.h>
36 #endif
37 #include <system_info.h>
38 #include <dd-display.h>
39
40 #ifndef _USE_DEVICED_DBUS
41 #include <usb-device.h>
42 #endif
43
44 #include "media-util.h"
45 #include "media-server-ipc.h"
46 #include "media-common-dbg.h"
47 #include "media-common-system.h"
48 #include "media-common-utils.h"
49
50 #define MS_DRM_CONTENT_TYPE_LENGTH 100
51
52 /* it's for 32bit file offset */
53 struct statvfs_32 {
54         unsigned long int f_bsize;
55         unsigned long int f_frsize;
56         unsigned long int f_blocks;
57         unsigned long int f_bfree;
58         unsigned long int f_bavail;
59         unsigned long int f_files;
60         unsigned long int f_ffree;
61         unsigned long int f_favail;
62         unsigned long int f_fsid;
63 #ifdef _STATVFSBUF_F_UNUSED
64         int __f_unused;
65 #endif
66         unsigned long int f_flag;
67         unsigned long int f_namemax;
68         int __f_spare[6];
69 };
70
71 bool ms_is_mmc_inserted(void)
72 {
73         bool ret = FALSE;
74         ms_stg_type_e stg_type = MS_STG_TYPE_MMC;
75         GArray *dev_list = NULL;
76
77         ret = ms_sys_get_device_list(stg_type, &dev_list);
78         if (ret == MS_MEDIA_ERR_NONE) {
79                 if (dev_list != NULL) {
80                         MS_DBG_WARN("MMC FOUND[%d]", dev_list->len);
81                         ms_sys_release_device_list(&dev_list);
82                         ret = TRUE;
83                 } else {
84                         MS_DBG_ERR("MMC NOT FOUND");
85                 }
86         } else {
87                 MS_DBG_ERR("ms_sys_get_device_list failed");
88         }
89
90         return ret;
91 }
92
93 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
94 {
95         int len = 0;
96         int real_size = size - 1;
97
98         if (!res || !pattern || !str1 || !str2)
99                 return MS_MEDIA_ERR_INVALID_PARAMETER;
100
101         if (real_size < (int)(strlen(str1) + strlen(str2)))
102                 return MS_MEDIA_ERR_INVALID_PARAMETER;
103
104         len = snprintf(res, real_size, pattern, str1, str2);
105         if (len < 0) {
106                 return MS_MEDIA_ERR_INVALID_PARAMETER;
107         }
108
109         res[len] = '\0';
110
111         return MS_MEDIA_ERR_NONE;
112 }
113
114 int ms_strcopy(char *res, const int size, const char *pattern, const char *str1)
115 {
116         int len = 0;
117         int real_size = size;
118
119         if (!res || !pattern || !str1) {
120                 MS_DBG_ERR("parameta is invalid");
121                 return MS_MEDIA_ERR_INVALID_PARAMETER;
122         }
123
124         if (real_size < (int)(strlen(str1))) {
125                 MS_DBG_ERR("size is wrong");
126                 return MS_MEDIA_ERR_INVALID_PARAMETER;
127         }
128
129         len = snprintf(res, real_size, pattern, str1);
130         if (len < 0) {
131                 MS_DBG_ERR("snprintf failed");
132                 return MS_MEDIA_ERR_INVALID_PARAMETER;
133         }
134
135         res[len] = '\0';
136
137         return MS_MEDIA_ERR_NONE;
138 }
139
140 bool ms_config_get_int(const char *key, int *value)
141 {
142         int err;
143
144         if (!key || !value) {
145                 MS_DBG_ERR("Arguments key or value is NULL");
146                 return false;
147         }
148
149         err = vconf_get_int(key, value);
150         if (err == 0)
151                 return true;
152         else if (err == -1)
153                 return false;
154         else
155                 MS_DBG_ERR("Unexpected error code: %d", err);
156
157         return false;
158 }
159
160 bool ms_config_set_int(const char *key, int value)
161 {
162         int err;
163
164         if (!key) {
165                 MS_DBG_ERR("Arguments key is NULL");
166                 return false;
167         }
168
169         err = vconf_set_int(key, value);
170         if (err == 0)
171                 return true;
172         else if (err == -1)
173                 return false;
174         else
175                 MS_DBG_ERR("Unexpected error code: %d", err);
176
177         return false;
178 }
179
180 bool ms_config_get_str(const char *key, char **value)
181 {
182         char *res = NULL;
183
184         if (key == NULL || value == NULL) {
185                 MS_DBG_ERR("Arguments key or value is NULL");
186                 return false;
187         }
188
189         res = vconf_get_str(key);
190         if (MS_STRING_VALID(res)) {
191                 *value = strdup(res);
192                 MS_SAFE_FREE(res);
193                 return true;
194         }
195
196         return false;
197 }
198
199 bool ms_config_set_str(const char *key, const char *value)
200 {
201         int err;
202
203         if (!key || !value) {
204                 MS_DBG_ERR("Arguments key or value is NULL");
205                 return false;
206         }
207
208         err = vconf_set_str(key, value);
209         if (err == 0)
210                 return true;
211         else
212                 MS_DBG_ERR("fail to vconf_set_str %d", err);
213
214         return false;
215 }
216
217 bool ms_config_get_bool(const char *key, int *value)
218 {
219         int err;
220
221         if (!key || !value) {
222                 MS_DBG_ERR("Arguments key or value is NULL");
223                 return false;
224         }
225
226         err = vconf_get_bool(key, value);
227         if (err == 0)
228                 return true;
229         else if (err == -1)
230                 return false;
231         else
232                 MS_DBG_ERR("Unexpected error code: %d", err);
233
234         return false;
235 }
236
237 static int get_memory_size(const char *path, struct statvfs_32 *buf)
238 {
239         struct statvfs s;
240         int ret;
241
242         ret = statvfs(path, &s);
243         if (ret) {
244                 MS_DBG_ERR("statvfs failed[%d]", ret);
245                 MS_DBG_STRERROR();
246                 return MS_MEDIA_ERR_INTERNAL;
247         }
248
249         buf->f_bsize = s.f_bsize;
250         buf->f_frsize = s.f_frsize;
251         buf->f_blocks = (unsigned long)s.f_blocks;
252         buf->f_bfree = (unsigned long)s.f_bfree;
253         buf->f_bavail = (unsigned long)s.f_bavail;
254         buf->f_files = (unsigned long)s.f_files;
255         buf->f_ffree = (unsigned long)s.f_ffree;
256         buf->f_favail = (unsigned long)s.f_favail;
257         buf->f_fsid = s.f_fsid;
258         buf->f_flag = s.f_flag;
259         buf->f_namemax = s.f_namemax;
260
261         return MS_MEDIA_ERR_NONE;
262 }
263
264 int ms_get_remain_space(double *free_space)
265 {
266         int ret = MS_MEDIA_ERR_NONE;
267         struct statvfs_32 temp;
268
269         ret = get_memory_size("/opt", &temp);
270         if (ret != MS_MEDIA_ERR_NONE) {
271                 MS_DBG_ERR("fail to get memory size");
272                 return ret;
273         }
274
275 //      MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
276
277         *free_space = (double)temp.f_bsize*temp.f_bavail;
278
279         return ret;
280 }
281
282 #ifdef _USE_RECORDED_CONTENT
283 bool ms_is_support_pvr(void)
284 {
285
286         int nSupportPVR = 0;
287         if (system_info_get_value_int(SYSTEM_INFO_KEY_PVR_SUPPORTED, &nSupportPVR) != SYSTEM_INFO_ERROR_NONE) {
288                 MS_DBG_ERR("Get PVR Support failed");
289                 return false;
290         }
291
292         MS_DBG("PVR Support : [%d]", nSupportPVR);
293
294         return (nSupportPVR != 0);
295 }
296 #endif
297
298 #ifdef _USE_SENIOR_MODE
299 bool ms_is_support_senior_mode()
300 {
301         bool bSupportSeniorMode = false;
302
303         if (system_info_get_value_bool(SYSTEM_INFO_KEY_GET_SENIOR_MODE_SUPPORTED, &bSupportSeniorMode) != SYSTEM_INFO_ERROR_NONE) {
304                 MS_DBG_ERR("Get senior mode support failed");
305                 return false;
306         }
307
308         MS_DBG("Senior mode support : [%d]", bSupportSeniorMode);
309
310         return bSupportSeniorMode;
311 }
312 #endif
313
314 int ms_check_file_path(const char *file_path, uid_t uid)
315 {
316         int exist;
317         struct stat file_st;
318         ms_user_storage_type_t storage_type = -1;
319         int ret = MS_MEDIA_ERR_NONE;
320
321         if (!MS_STRING_VALID(file_path)) {
322                 MS_DBG_ERR("Invalid path");
323                 return MS_MEDIA_ERR_INVALID_PARAMETER;
324         }
325
326         /* check location of file */
327         /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
328         ret = ms_user_get_storage_type(uid, file_path, &storage_type);
329         MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
330
331         /* check the file exits actually */
332         exist = open(file_path, O_RDONLY);
333         if (exist < 0) {
334                 MS_DBG_SERR("open file fail [%s]", file_path);
335                 return MS_MEDIA_ERR_INVALID_PATH;
336         }
337         close(exist);
338
339         /* check type of the path */
340         /* It must be a regular file */
341         memset(&file_st, 0, sizeof(struct stat));
342         if (stat(file_path, &file_st) == 0) {
343                 if (!S_ISREG(file_st.st_mode)) {
344                         /* In this case, it is not a regula file */
345                         MS_DBG_ERR("this path is not a file");
346                         return MS_MEDIA_ERR_INVALID_PATH;
347                 }
348         } else {
349                 MS_DBG_STRERROR("stat failed");
350                 return MS_MEDIA_ERR_INVALID_PATH;
351         }
352
353         return MS_MEDIA_ERR_NONE;
354 }
355
356 int ms_check_ignore_dir(const char *full_path, uid_t uid)
357 {
358         int ret = MS_MEDIA_ERR_NONE;
359         char *dir_path = NULL;
360         char *leaf_path = NULL;
361         char *usr_path = NULL;
362
363         ret = ms_check_file_path(full_path, uid);
364         if (ret != MS_MEDIA_ERR_NONE) {
365                 MS_DBG_ERR("invalid path : %s", full_path);
366                 return MS_MEDIA_ERR_INVALID_PATH;
367         }
368
369         dir_path = g_path_get_dirname(full_path);
370         if (dir_path == NULL || strcmp(dir_path, ".") == 0) {
371                 MS_DBG_ERR("getting directory path is failed : %s", full_path);
372                 MS_SAFE_FREE(dir_path);
373                 return MS_MEDIA_ERR_INVALID_PATH;
374         }
375
376         ret = ms_user_get_internal_root_path(uid, &usr_path);
377         if (ret != MS_MEDIA_ERR_NONE) {
378                 MS_DBG_ERR("ms_user_get_internal_root_path() fail");
379                 MS_SAFE_FREE(dir_path);
380                 return MS_MEDIA_ERR_INTERNAL;
381         }
382
383         while (1) {
384                 if (ms_check_scan_ignore(dir_path) != MS_MEDIA_ERR_NONE) {
385                         ret = MS_MEDIA_ERR_INVALID_PATH;
386                         break;
387                 }
388
389 #ifdef _USE_SENIOR_MODE
390                 if (ms_is_support_senior_mode()) {
391                         if (strcmp(dir_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0)
392                                 break;
393                 }
394 #endif
395                 if (strcmp(dir_path, usr_path) == 0)
396                         break;
397                 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(dir_path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
398                         break;
399                 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(dir_path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
400                         break;
401                 else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(dir_path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0))
402                         break;
403
404                 leaf_path = strrchr(dir_path, '/');
405                 if (leaf_path != NULL) {
406                                 int seek_len = leaf_path -dir_path;
407                                 dir_path[seek_len] = '\0';
408                 } else {
409                         MS_DBG_ERR("Fail to find leaf path");
410                         ret = MS_MEDIA_ERR_INVALID_PATH;
411                         break;
412                 }
413         }
414
415         MS_SAFE_FREE(dir_path);
416         MS_SAFE_FREE(usr_path);
417
418         return ret;
419 }
420
421 int ms_check_scan_ignore(char * path)
422 {
423         int fd = -1;
424         int exist = -1;
425         const char *ignore_path = "/.scan_ignore";
426         char *check_ignore_file = NULL;
427         int ret = MS_MEDIA_ERR_NONE;
428
429         if (strstr(path, "/.")) {
430                 MS_DBG_ERR("hidden path");
431                 ret = MS_MEDIA_ERR_INVALID_PATH;
432                 goto ERROR;
433         }
434
435         fd = open(path, O_RDONLY | O_DIRECTORY);
436         if (fd == -1) {
437                 MS_DBG_ERR("%s folder opendir fails", path);
438                 ret = MS_MEDIA_ERR_INVALID_PATH;
439
440                 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
441                         MS_DBG_ERR("Fail to get USB path");
442                         goto ERROR;
443                 }
444
445                 if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
446                         if (errno == ENOENT) {
447                                 /*if the directory does not exist, check the device is unmounted*/
448                                 if (!ms_storage_mount_status(path)) {
449                                         MS_DBG_ERR("Device is unmounted[%s]", path);
450                                         ret = MS_MEDIA_ERR_USB_UNMOUNTED;
451                                         goto ERROR;
452                                 }
453                         }
454                 }
455
456                 struct stat folder_st;
457                 if (stat(path, &folder_st) == 0) {
458                         MS_DBG_WARN("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
459                                 (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
460                 } else {
461                         MS_DBG_ERR("%s folder stat fails", path);
462                 }
463
464                 goto ERROR;
465         } else {
466                 /* check the file exits actually */
467                 int path_len = 0;
468
469                 path_len = strlen(path) + strlen(ignore_path) + 1;
470                 check_ignore_file = malloc(path_len);
471                 if (check_ignore_file != NULL) {
472                         memset(check_ignore_file, 0x0, path_len);
473                         snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
474
475                         exist = open(check_ignore_file, O_RDONLY);
476                         if (exist >= 0) {
477                                 MS_DBG_WARN("scan_ignore exists [%s]", check_ignore_file);
478                                 ret = MS_MEDIA_ERR_INVALID_PATH;
479                         }
480
481                         MS_SAFE_FREE(check_ignore_file);
482                 } else {
483                         MS_DBG_ERR("malloc failed");
484                         ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
485                 }
486         }
487
488 ERROR:
489
490         if (fd != -1) {
491                 close(fd);
492                 fd = -1;
493         }
494
495         if (exist >= 0) close(exist);
496
497         return ret;
498 }
499
500 bool ms_storage_mount_status(const char* start_path)
501 {
502         bool ret = false;
503 #ifndef _USE_DEVICED_DBUS
504         int count = 0;
505         int err = 0;
506         usb_device_list_h list;
507         usb_device_h device;
508         char *mount_path = NULL;
509
510         char *storage_path = NULL;
511         char *remain_path = NULL;
512         int remain_len = 0;
513
514         remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
515         if (remain_path != NULL)
516                 remain_len = strlen(remain_path);
517
518         storage_path = strndup(start_path, strlen(start_path) - remain_len);
519
520         MS_DBG_WARN("storage_path [%s]", storage_path);
521
522         err = usb_device_get_device_list(USB_MASS_STORAGE, &list);
523         if (err == 0) {
524                 count = usb_device_list_get_count(list);
525                 if (count > 0) {
526                         err = usb_device_list_get_first(list, &device);
527                         if (err != USB_ERROR_LIST_FAILED_TO_GET && device != NULL) {
528                                 mount_path = usb_device_get_mountpath(device);
529                                 if (mount_path != NULL) {
530                                         MS_DBG_WARN("mount_path [%s]", mount_path);
531                                         if (strlen(mount_path) == strlen(storage_path)) {
532                                                 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
533                                                         MS_DBG_WARN("start path is mounted [%s]", start_path);
534                                                         ret = true;
535                                                 }
536                                         }
537                                 }
538                         }
539
540                         if (ret != true) {
541                                 while (usb_device_list_get_next(list, &device) == 0) {
542                                         if (device != NULL) {
543                                                 mount_path = usb_device_get_mountpath(device);
544                                                 if (mount_path != NULL) {
545                                                         MS_DBG_WARN("mount_path [%s]", mount_path);
546                                                         if (strlen(mount_path) == strlen(storage_path)) {
547                                                                 if (strncmp(mount_path, storage_path, strlen(mount_path)) == 0) {
548                                                                         MS_DBG_WARN("start path is mounted [%s]", start_path);
549                                                                         ret = true;
550                                                                         break;
551                                                                 }
552                                                         }
553                                                 }
554                                         }
555                                 }
556                         }
557                 }
558
559                 usb_device_free_device_list(list);
560         } else {
561                 MS_DBG_ERR("usb_device_get_device_list falied [%d]", err);
562         }
563
564         MS_SAFE_FREE(storage_path);
565 #endif
566         return ret;
567 }
568
569 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
570 {
571         int res = MS_MEDIA_ERR_NONE;
572         int err = 0;
573
574         if (status == MS_DB_UPDATING) {
575                 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
576                         res = MS_MEDIA_ERR_VCONF_SET_FAIL;
577                         MS_DBG_ERR("ms_config_set_int failed");
578                 }
579
580                 if (storage_type == MS_STORAGE_EXTERNAL) {
581                         if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
582                                 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
583                                 MS_DBG_ERR("ms_config_set_int failed");
584                         }
585                 }
586         } else {
587                 if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
588                         res = MS_MEDIA_ERR_VCONF_SET_FAIL;
589                         MS_DBG_ERR("ms_config_set_int failed");
590                 }
591
592                 if (storage_type == MS_STORAGE_EXTERNAL) {
593                         if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
594                                 res = MS_MEDIA_ERR_VCONF_SET_FAIL;
595                                 MS_DBG_ERR("ms_config_set_int failed");
596                         }
597                 }
598         }
599
600         err = ms_set_power_mode(status);
601         if (err != MS_MEDIA_ERR_NONE) {
602                 MS_DBG_ERR("ms_set_power_mode fail");
603                 res = err;
604         }
605
606         return res;
607 }
608
609 int ms_set_power_mode(ms_db_status_type_t status)
610 {
611         int res = MS_MEDIA_ERR_NONE;
612         int err;
613
614         switch (status) {
615         case MS_DB_UPDATING:
616                 err = display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
617                 if (err != 0)
618                         res = MS_MEDIA_ERR_INTERNAL;
619                 break;
620         case MS_DB_UPDATED:
621                 err = display_unlock_state(LCD_OFF, PM_RESET_TIMER);
622                 if (err != 0)
623                         res = MS_MEDIA_ERR_INTERNAL;
624                 break;
625         default:
626                 MS_DBG_ERR("Unacceptable type : %d", status);
627                 break;
628         }
629
630         return res;
631 }
632
633 void ms_trim_dir_path(char *dir_path)
634 {
635         /* need implementation */
636         /* if dir_path is not NULL terminated, this function will occure crash */
637         int len = strlen(dir_path);
638
639         if (dir_path[len -1] == '/')
640                 dir_path[len -1] = '\0';
641 }
642
643 bool ms_check_folder_path(const char *folder_path)
644 {
645         DIR *dp = NULL;
646
647         dp = opendir(folder_path);
648         if (dp == NULL) {
649                 MS_DBG_ERR("Deleted folder path");
650                 return false;
651         }
652         closedir(dp);
653
654         return true;
655 }
656
657 int ms_check_size_mediadb(uid_t uid, double *db_size)
658 {
659         int ret = MS_MEDIA_ERR_NONE;
660         char *db_path = NULL;
661         struct stat buf;
662
663         ret = ms_user_get_media_db_path(uid, &db_path);
664
665         if (stat(db_path, &buf) == 0) {
666                 *db_size = buf.st_size;
667         } else {
668                 MS_DBG_STRERROR("stat failed");
669                 ret = MS_MEDIA_ERR_INTERNAL;
670         }
671
672         MS_SAFE_FREE(db_path);
673
674         return ret;
675 }
676
677 #ifdef _SET_VIP_PROCESS
678 #define PROC_OOM_SCORE_ADJ_PATH         "/proc/%d/oom_score_adj"
679 #define VIP_OOM_SCORE_ADJ                       (-1000)
680 #define PROC_NAME_MAX 1024
681 #define PROC_BUF_MAX 64
682
683 static int ms_get_cmdline_from_proc(pid_t pid, char *cmdline)
684 {
685         char buf[PROC_BUF_MAX];
686         char cmdline_buf[PROC_NAME_MAX];
687         char *filename;
688         FILE *fp;
689
690         snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
691         fp = fopen(buf, "r");
692         if (fp == NULL)
693                 return MS_MEDIA_ERR_INTERNAL;
694
695         if (fgets(cmdline_buf, PROC_NAME_MAX-1, fp) == NULL) {
696                 fclose(fp);
697                 return MS_MEDIA_ERR_INTERNAL;
698         }
699         fclose(fp);
700
701         filename = strrchr(cmdline_buf, '/');
702         if (filename == NULL)
703                 filename = cmdline_buf;
704         else
705                 filename = filename + 1;
706
707         SAFE_STRLCPY(cmdline, filename, PROC_NAME_MAX);
708
709         return MS_MEDIA_ERR_NONE;
710 }
711
712 int ms_set_vip_process(void)
713 {
714         char buf[100] = {0};
715         int id = 0;
716         static pid_t pid = 0;
717         static char process_name[PROC_NAME_MAX] = {0};
718         static char *appid = NULL;
719
720         /* Get Pid */
721         pid = getpid();
722         if (ms_get_cmdline_from_proc(pid, process_name)) {
723                 MS_DBG_ERR("%s: Read process name failed pid[%d]\n", __func__, pid);
724                 return MS_MEDIA_ERR_INTERNAL;
725         }
726         appid = process_name;
727
728         MS_DBG("Process name[%s]:Pid[%d]", appid, pid);
729
730         if (prctl(PR_GET_DUMPABLE) == 0)
731                 prctl(PR_SET_DUMPABLE, 1);
732
733         snprintf(buf, sizeof(buf), PROC_OOM_SCORE_ADJ_PATH, pid);
734         id = open(buf, O_WRONLY, 0777);
735         if (id < 0) {
736                 MS_DBG_ERR("fopen %s failed errno:%d", buf, errno);
737                 return MS_MEDIA_ERR_INTERNAL;
738         }
739         snprintf(buf, sizeof(buf), "%d", VIP_OOM_SCORE_ADJ);
740         if (write(id, buf, strlen(buf)) < 0) {
741                 MS_DBG_ERR("write() failed errno=%d", errno);
742                 close(id);
743                 return MS_MEDIA_ERR_INTERNAL;
744         }
745         close(id);
746         return MS_MEDIA_ERR_NONE;
747 }
748 #endif