Try to open proc files several times due to problems with permissions accepted/tizen/unified/20180821.091206 submit/tizen/20180820.170401
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Fri, 10 Aug 2018 20:18:30 +0000 (23:18 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Mon, 20 Aug 2018 17:01:22 +0000 (20:01 +0300)
profctl.c

index 288cb6d1cc2af93bf5e7182f437315cbaa9e29a9..1c2e850d44d79b26f4998b7e1b3b4511761c5d4e 100644 (file)
--- a/profctl.c
+++ b/profctl.c
@@ -159,15 +159,36 @@ static void *outstat(void *arg)
                exit(1);
        }
 
-       pmstat = fopen(statmname, "r");
-       if (pmstat == NULL) {
-               perror("open /proc/$pid/statm");
-               exit(1);
+       // Sometimes we can't successfully open /proc/$pid files due to strange
+       // permission problems, so we retry to open it several times.
+
+       int retry = 0;
+       const int max_retry = 10;
+
+       for (; retry < max_retry; ++retry)
+       {
+               pmstat = fopen(statmname, "r");
+               if (pmstat == NULL) {
+                       perror("open /proc/$pid/statm");
+                       usleep(100000);
+                       continue;
+               }
+               break;
+       }
+
+       for (; retry < max_retry; ++retry)
+       {
+               pstat = fopen(statname, "r");
+               if (pstat == NULL) {
+                       perror("open /proc/$pid/stat");
+                       usleep(100000);
+                       continue;
+               }
+               break;
        }
 
-       pstat = fopen(statname, "r");
-       if (pstat == NULL) {
-               perror("open /proc/$pid/stat");
+       if (statmname == NULL || statname == NULL)
+       {
                exit(1);
        }