From: Aleksei Vereshchagin Date: Fri, 10 Aug 2018 20:18:30 +0000 (+0300) Subject: Try to open proc files several times due to problems with permissions X-Git-Tag: submit/tizen/20180820.170401^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94faa04e242cc6a1f17daea615504e07d4284387;p=sdk%2Ftools%2Fprofctl.git Try to open proc files several times due to problems with permissions --- diff --git a/profctl.c b/profctl.c index 288cb6d..1c2e850 100644 --- 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); }