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