Modify the problem that the original assembly is deleted (#80)
[platform/core/dotnet/launcher.git] / NativeLauncher / tool / ni_common.cc
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <pkgmgr-info.h>
18 #include <pkgmgr_installer_info.h>
19 #include <aul.h>
20
21 #include "log.h"
22 #include "utils.h"
23 #include "pkgmgr_parser_plugin_interface.h"
24
25 #include <wait.h>
26 #include <dirent.h>
27 #include <sys/stat.h>
28
29 #include <algorithm>
30 #include <string>
31 #include <fstream>
32
33 #include <pwd.h>
34 #include <grp.h>
35 #include <unistd.h>
36 #include <string.h>
37
38 #include "ni_common.h"
39 #include "tac_common.h"
40 #include "path_manager.h"
41 #include "plugin_manager.h"
42
43 #ifdef  LOG_TAG
44 #undef  LOG_TAG
45 #endif
46 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
47
48 #ifndef CROSSGEN_PATH
49 #error "CROSSGEN_PATH is missed"
50 #endif
51
52 #define __XSTR(x) #x
53 #define __STR(x) __XSTR(x)
54 static const char* __CROSSGEN_PATH = __STR(CROSSGEN_PATH);
55
56 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
57 static const char* __SYSTEM_BASE_FILE = __STR(SYSTEM_BASE_FILE);
58 #endif
59
60 #undef __STR
61 #undef __XSTR
62
63 static int __interval = 0;
64 static std::string __tpa;
65
66 static void waitInterval()
67 {
68         // by the recommand, ignore small value for performance.
69         if (__interval > 10000) {
70                 fprintf(stderr, "sleep %d usec\n", __interval);
71                 usleep(__interval);
72         }
73 }
74
75 static std::string getNiFilePath(const std::string& dllPath)
76 {
77         size_t index = dllPath.find_last_of(".");
78         if (index == std::string::npos) {
79                 fprintf(stderr, "File doesnot contain extension. fail to get NI file name\n");
80                 return "";
81         }
82         std::string fName = dllPath.substr(0, index);
83         std::string fExt = dllPath.substr(index, dllPath.length());
84
85         // crossgen generate file with lower case extension only
86         std::transform(fExt.begin(), fExt.end(), fExt.begin(), ::tolower);
87         std::string niPath = fName + ".ni" + fExt;
88
89         return niPath;
90 }
91
92 static std::string getAppNIPath(const std::string& niPath)
93 {
94         std::string fileName;
95         std::string niDirPath;
96         std::string prevPath;
97
98         size_t index = niPath.find_last_of("/");
99         if (index != std::string::npos) {
100                 prevPath = niPath.substr(0, index);
101                 fileName = niPath.substr(index + 1, niPath.length());
102         } else {
103                 prevPath = ".";
104                 fileName = niPath;
105         }
106
107         niDirPath = concatPath(prevPath, APP_NI_SUB_DIR);
108
109         if (!isFileExist(niDirPath)) {
110                 if (mkdir(niDirPath.c_str(), 0755) == 0) {
111                         updateAssemblyInfo(prevPath, niDirPath);
112                 } else {
113                         fprintf(stderr, "Fail to create app ni directory (%s)\n", niDirPath.c_str());
114                 }
115         }
116
117         return concatPath(niDirPath, fileName);
118 }
119
120 static bool niExist(const std::string& path)
121 {
122         std::string f = getNiFilePath(path);
123         if (f.empty()) {
124                 return false;
125         }
126
127         if (isFileExist(f)) {
128                 return true;
129         }
130
131         // native image of System.Private.CoreLib.dll should have to overwrite
132         // original file to support new coreclr
133         if (path.find("System.Private.CoreLib.dll") != std::string::npos) {
134                 std::string coreLibBackup = path + ".Backup";
135                 if (isFileExist(coreLibBackup)) {
136                         return true;
137                 }
138         }
139
140         return false;
141 }
142
143 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
144 // Get next base address to be used for system ni image from file
145 // __SYSTEM_BASE_FILE should be checked for existance before calling this function
146 static uintptr_t getNextBaseAddrFromFile()
147 {
148         FILE *pFile = fopen(__SYSTEM_BASE_FILE, "r");
149         if (pFile == NULL) {
150                 fprintf(stderr, "Failed to open %s\n", __SYSTEM_BASE_FILE);
151                 return 0;
152         }
153
154         uintptr_t addr = 0;
155         uintptr_t size = 0;
156
157         while (fscanf(pFile, "%u %u", &addr, &size) != EOF) {
158         }
159
160         fclose(pFile);
161
162         return addr + size;
163 }
164
165 // Get next base address to be used for system ni image
166 static uintptr_t getNextBaseAddr()
167 {
168         uintptr_t baseAddr = 0;
169
170         if (!isFileExist(__SYSTEM_BASE_FILE)) {
171                 // This is the starting address for all default base addresses
172                 baseAddr = DEFAULT_BASE_ADDR_START;
173         } else {
174                 baseAddr = getNextBaseAddrFromFile();
175
176                 // Round to a multple of 64K (see ZapImage::CalculateZapBaseAddress in CoreCLR)
177                 uintptr_t BASE_ADDRESS_ALIGNMENT = 0xffff;
178                 baseAddr = (baseAddr + BASE_ADDRESS_ALIGNMENT) & ~BASE_ADDRESS_ALIGNMENT;
179         }
180
181         return baseAddr;
182 }
183
184 // Save base address of system ni image to file
185 static void updateBaseAddrFile(const std::string &dllPath, uintptr_t baseAddr)
186 {
187         std::string absNiPath = getNiFilePath(dllPath);
188         if (absNiPath.empty()) {
189                 fprintf(stderr, "Failed to get ni file path for %s\n", dllPath.c_str());
190                 return;
191         }
192
193         uintptr_t niSize = getFileSize(absNiPath);
194         if (niSize == 0) {
195                 fprintf(stderr, "File %s doesn't exist\n", absNiPath.c_str());
196                 return;
197         }
198
199         // Write new entry to the file
200         FILE *pFile = fopen(__SYSTEM_BASE_FILE, "a");
201         if (pFile == NULL) {
202                 fprintf(stderr, "Failed to open %s\n", __SYSTEM_BASE_FILE);
203                 return;
204         }
205
206         fprintf(pFile, "%u %u\n", baseAddr, niSize);
207         fclose(pFile);
208 }
209
210 // check if dll is listed in TPA
211 static bool isTPADll(const std::string &dllPath)
212 {
213         std::string absDllPath = absolutePath(dllPath);
214
215         if (__tpa.find(absDllPath) != std::string::npos) {
216                 return true;
217         }
218
219         return false;
220 }
221 #endif
222
223 // baseAddr should be checked in file before getting here
224 static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, uintptr_t baseAddr = 0, bool isAppNI = false)
225 {
226         if (!isFileExist(dllPath)) {
227                 fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str());
228                 return NI_ERROR_NO_SUCH_FILE;
229         }
230
231         if (!isManagedAssembly(dllPath)) {
232                 fprintf(stderr, "Input file is not a dll file : %s\n", dllPath.c_str());
233                 return NI_ERROR_INVALID_PARAMETER;
234         }
235
236         if (niExist(dllPath)) {
237                 fprintf(stderr, "Already ni file is exist for %s\n", dllPath.c_str());
238                 return NI_ERROR_ALREADY_EXIST;
239         }
240
241         std::string absDllPath = absolutePath(dllPath);
242         std::string absNiPath = getNiFilePath(dllPath);
243         if (absNiPath.empty()) {
244                 fprintf(stderr, "Fail to get ni file name\n");
245                 return NI_ERROR_UNKNOWN;
246         }
247
248         if (isAppNI) {
249                 absNiPath = getAppNIPath(absNiPath);
250         }
251
252         pid_t pid = fork();
253         if (pid == -1)
254                 return NI_ERROR_UNKNOWN;
255
256         if (pid > 0) {
257                 int status;
258                 waitpid(pid, &status, 0);
259                 if (WIFEXITED(status)) {
260                         // Do not use niExist() function to check whether ni file created or not.
261                         // niEixst() return false for System.Private.Corelib.dll
262                         if (isFileExist(absNiPath)) {
263                                 updateAssemblyInfo(absDllPath, absNiPath);
264                                 return NI_ERROR_NONE;
265                         } else {
266                                 fprintf(stderr, "Fail to create native image for %s\n", dllPath.c_str());
267                                 return NI_ERROR_NO_SUCH_FILE;
268                         }
269                 }
270         } else {
271                 std::string jitPath = getRuntimeDir() + "/libclrjit.so";
272                 std::vector<const char*> argv = {
273                         __CROSSGEN_PATH,
274                         "/nologo",
275                         "/Trusted_Platform_Assemblies", __tpa.c_str(),
276                         "/JITPath", jitPath.c_str()
277                 };
278
279                 if (!enableR2R) {
280                         argv.push_back("/FragileNonVersionable");
281                 }
282
283 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
284                 if (baseAddr != 0) {
285                         argv.push_back("/BaseAddress");
286                         argv.push_back(std::to_string(baseAddr).c_str());
287                 }
288 #endif
289
290                 argv.push_back("/App_Paths");
291                 std::string absAppPath;
292                 if (!appPath.empty()) {
293                         absAppPath = appPath;
294                 } else {
295                         absAppPath = baseName(absDllPath);
296                 }
297                 argv.push_back(absAppPath.c_str());
298
299                 argv.push_back("/out");
300                 argv.push_back(absNiPath.c_str());
301
302                 argv.push_back(absDllPath.c_str());
303                 argv.push_back(nullptr);
304
305                 fprintf(stderr, "+ %s (%s)\n", absDllPath.c_str(), enableR2R ? "R2R" : "FNV");
306
307                 execv(__CROSSGEN_PATH, const_cast<char* const*>(argv.data()));
308                 exit(0);
309         }
310
311         return NI_ERROR_NONE;
312 }
313
314 // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
315 static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
316 {
317         char *pkgId = NULL;
318         int ret = 0;
319         bool* enableR2R = (bool*)userData;
320
321         ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
322         if (ret != PMINFO_R_OK) {
323                 fprintf(stderr, "Failed to get pkgid\n");
324                 return -1;
325         }
326
327         if (removeNiUnderPkgRoot(pkgId) != NI_ERROR_NONE) {
328                 fprintf(stderr, "Failed to remove previous dlls from [%s]\n", pkgId);
329                 return -1;
330         }
331
332         if (resetTACPackage(pkgId) != TAC_ERROR_NONE) {
333                 fprintf(stderr, "Failed to remove symlink for given package [%s]\n", pkgId);
334                 return -1;
335         }
336
337         // Regenerate ni files with R2R mode forcibiliy. (there is no way to now which option is used)
338         if (createNiUnderPkgRoot(pkgId, *enableR2R) != NI_ERROR_NONE) {
339                 fprintf(stderr, "Failed to generate NI file [%s]\n", pkgId);
340                 return -1;
341         } else {
342                 fprintf(stderr, "Complete make application to native image\n");
343         }
344
345         if (createTACPackage(pkgId) != TAC_ERROR_NONE) {
346                 fprintf(stderr, "Failed to generate symbolic link file [%s]\n", pkgId);
347                 return -1;
348         }else {
349                 fprintf(stderr, "Complete make symbolic link file to tac\n");
350         }
351
352         return 0;
353 }
354
355 static void createCoreLibNI(bool enableR2R, bool doGenUniqueBaseSystem)
356 {
357         std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll");
358         std::string niCoreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.ni.dll");
359         std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup");
360
361         if (!isFileExist(coreLibBackup)) {
362                 uintptr_t baseAddr = 0;
363
364 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
365                 if (doGenUniqueBaseSystem) {
366                         baseAddr = getNextBaseAddr();
367                 }
368 #endif
369
370                 if (!crossgen(coreLib, std::string(), enableR2R, baseAddr)) {
371 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
372                         if (doGenUniqueBaseSystem && baseAddr != 0) {
373                                 updateBaseAddrFile(coreLib, baseAddr);
374                         }
375 #endif
376
377                         if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
378                                 fprintf(stderr, "Failed to rename System.Private.CoreLib.dll\n");
379                         }
380                         if (rename(niCoreLib.c_str(), coreLib.c_str())) {
381                                 fprintf(stderr, "Failed to rename System.Private.CoreLib.ni.dll\n");
382                         }
383                 } else {
384                         fprintf(stderr, "Failed to create native image for %s\n", coreLib.c_str());
385                 }
386         }
387 }
388
389 ni_error_e initNICommon(NiCommonOption* option)
390 {
391 #if defined(__arm__)
392         // get interval value
393         const char* intervalFile = "/usr/share/dotnet.tizen/lib/crossgen_interval.txt";
394         std::ifstream inFile(intervalFile);
395         if (inFile) {
396                 fprintf(stderr, "crossgen_interval.txt is found\n");
397                 inFile >> __interval;
398         }
399
400         if (initializePluginManager("normal")) {
401                 fprintf(stderr, "Fail to initialize plugin manager\n");
402                 return NI_ERROR_UNKNOWN;
403         }
404         if (initializePathManager(option->runtimeDir, option->tizenFXDir, option->extraDirs)) {
405                 fprintf(stderr, "Fail to initialize path manager\n");
406                 return NI_ERROR_UNKNOWN;
407         }
408
409         __tpa = getTPA();
410
411         return NI_ERROR_NONE;
412 #else
413         fprintf(stderr, "crossgen supports arm architecture only. skip ni file generation\n");
414         return NI_ERROR_NOT_SUPPORTED;
415 #endif
416 }
417
418 void finalizeNICommon()
419 {
420         __interval = 0;
421
422         finalizePluginManager();
423         finalizePathManager();
424
425         __tpa.clear();
426 }
427
428
429 void createNiPlatform(bool enableR2R, bool doGenUniqueBaseSystem)
430 {
431         const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()};
432         createNiUnderDirs(platformDirs, 2, enableR2R, doGenUniqueBaseSystem);
433 }
434
435 ni_error_e createNiDll(const std::string& dllPath, bool enableR2R, bool doGenUniqueBaseSystem)
436 {
437         createCoreLibNI(enableR2R, doGenUniqueBaseSystem);
438         // System.Private.CoreLib.dll is generated in the createCoreLibNI function.
439         // Skip if input dll is System.Private.CoreLib.dll
440         if (dllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
441                 return NI_ERROR_NONE;
442         }
443
444         uintptr_t baseAddr = 0;
445
446 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
447         if (doGenUniqueBaseSystem && isTPADll(dllPath)) {
448                 baseAddr = getNextBaseAddr();
449         }
450 #endif
451
452         ni_error_e status = crossgen(dllPath, std::string(), enableR2R, baseAddr);
453
454 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
455         if (doGenUniqueBaseSystem && baseAddr != 0) {
456                 updateBaseAddrFile(dllPath, baseAddr);
457         }
458 #endif
459
460         return status;
461 }
462
463 void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool doGenUniqueBaseSystem, bool isAppNI)
464 {
465         createCoreLibNI(enableR2R, doGenUniqueBaseSystem);
466
467         std::string appPaths;
468         for (int i = 0; i < count; i++) {
469                 appPaths += rootPaths[i];
470                 appPaths += ':';
471         }
472
473         if (appPaths.back() == ':')
474                 appPaths.pop_back();
475
476         auto convert = [&appPaths, enableR2R, doGenUniqueBaseSystem, isAppNI](const std::string& path, const char* name) {
477                 uintptr_t baseAddr = 0;
478
479 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
480                 if (doGenUniqueBaseSystem && !isAppNI && isTPADll(path)) {
481                         baseAddr = getNextBaseAddr();
482                 }
483 #endif
484
485                 if (!crossgen(path, appPaths.c_str(), enableR2R, baseAddr, isAppNI)) {
486 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
487                         if (doGenUniqueBaseSystem && !isAppNI && baseAddr != 0) {
488                                 updateBaseAddrFile(path, baseAddr);
489                         }
490 #endif
491
492                         waitInterval();
493                 }
494         };
495
496         for (int i = 0; i < count; i++) {
497                 scanFilesInDir(rootPaths[i], convert, 1);
498         }
499 }
500
501 ni_error_e createNiUnderPkgRoot(const std::string& pkgId, bool enableR2R)
502 {
503         std::string pkgRoot;
504         if (getRootPath(pkgId, pkgRoot) < 0) {
505                 return NI_ERROR_INVALID_PACKAGE;
506         }
507
508         std::string binDir = concatPath(pkgRoot, "bin");
509         std::string libDir = concatPath(pkgRoot, "lib");
510         std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
511         std::string paths[] = {binDir, libDir, tacDir};
512
513         createNiUnderDirs(paths, 3, enableR2R, false, true);
514
515         return NI_ERROR_NONE;
516 }
517
518 ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string& dllPath, bool enableR2R)
519 {
520         std::string pkgRoot;
521         if (getRootPath(pkgId, pkgRoot) < 0) {
522                 return NI_ERROR_INVALID_PACKAGE;
523         }
524
525         std::string binDir = concatPath(pkgRoot, "bin");
526         std::string libDir = concatPath(pkgRoot, "lib");
527         std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
528         std::string paths = binDir + ":" + libDir + ":" + tacDir;
529
530         if (bf::is_symlink(dllPath)) {
531                 if (bf::exists(tacDir)) {
532                         if (!isNativeImage(dllPath)) {
533                                 std::string originPath = bf::read_symlink(dllPath).string();
534                                 std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
535                                 if (!bf::exists(originNiPath)) {
536                                         if(createNiDll(originPath, false, false) != NI_ERROR_NONE) {
537                                                 fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
538                                                 return NI_ERROR_UNKNOWN;
539                                         }
540                                 }
541                                 std::string setNiPath = dllPath.substr(0, dllPath.rfind(".dll")) + ".ni.dll";
542                                 if (!bf::exists(setNiPath)) {
543                                         bf::create_symlink(originNiPath, setNiPath);
544                                         fprintf(stderr, "%s symbolic link file generated successfully.\n", setNiPath.c_str());
545                                         updateAssemblyInfo(tacDir.c_str(), setNiPath.c_str(), true);
546                                 }
547                         }
548                 }
549                 return NI_ERROR_NONE;
550         } else {
551                 return crossgen(dllPath, paths, enableR2R, 0, true);
552         }
553 }
554
555 void removeNiPlatform()
556 {
557         std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll");
558         std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup");
559
560         if (!isFileExist(coreLibBackup)) {
561                 return;
562         }
563
564 #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
565         if (isFileExist(__SYSTEM_BASE_FILE)) {
566                 if (remove(__SYSTEM_BASE_FILE)) {
567                         fprintf(stderr, "Failed to remove %s\n", __SYSTEM_BASE_FILE);
568                 }
569         }
570 #endif
571
572         if (remove(coreLib.c_str())) {
573                 fprintf(stderr, "Failed to remove System.Private.CoreLib native image file\n");
574         }
575
576         if (rename(coreLibBackup.c_str(), coreLib.c_str())) {
577                 fprintf(stderr, "Failed to rename System.Private.CoreLib.Backup to origin\n");
578         }
579
580         const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()};
581
582         removeNiUnderDirs(platformDirs, 2);
583 }
584
585 void removeNiUnderDirs(const std::string rootPaths[], int count)
586 {
587         auto convert = [](const std::string& path, std::string name) {
588                 if (isNativeImage(path)) {
589                         if (remove(path.c_str())) {
590                                 fprintf(stderr, "Failed to remove %s\n", path.c_str());
591                         }
592                 }
593         };
594
595         for (int i = 0; i < count; i++)
596                 scanFilesInDir(rootPaths[i], convert, -1);
597 }
598
599 ni_error_e removeNiUnderPkgRoot(const std::string& pkgId)
600 {
601         std::string pkgRoot;
602         if (getRootPath(pkgId, pkgRoot) < 0) {
603                 return NI_ERROR_INVALID_PACKAGE;
604         }
605
606         std::string binDir = concatPath(pkgRoot, "bin");
607         std::string libDir = concatPath(pkgRoot, "lib");
608         std::string paths[] = {binDir, libDir};
609
610         removeNiUnderDirs(paths, 2);
611
612         std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
613         if (isFileExist(binNIDir)) {
614                 if (rmdir(binNIDir.c_str()) != 0) {
615                         fprintf(stderr, "Failed to remove app ni dir [%s]\n", binNIDir.c_str());
616                 }
617         }
618
619         std::string libNIDir = concatPath(libDir, APP_NI_SUB_DIR);
620         if (isFileExist(libNIDir)) {
621                 if (rmdir(libNIDir.c_str()) != 0) {
622                         fprintf(stderr, "Failed to remove app ni dir [%s]\n", libNIDir.c_str());
623                 }
624         }
625
626         return NI_ERROR_NONE;
627 }
628
629 ni_error_e regenerateAppNI(bool enableR2R)
630 {
631         int ret = 0;
632         pkgmgrinfo_appinfo_metadata_filter_h handle;
633
634         ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
635         if (ret != PMINFO_R_OK)
636                 return NI_ERROR_UNKNOWN;
637
638         ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE);
639         if (ret != PMINFO_R_OK) {
640                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
641                 return NI_ERROR_UNKNOWN;
642         }
643
644         ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, appAotCb, &enableR2R);
645         if (ret != PMINFO_R_OK) {
646                 fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
647                 pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
648                 return NI_ERROR_UNKNOWN;
649         }
650
651         fprintf(stderr, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n");
652
653         pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
654         return NI_ERROR_NONE;
655 }