crash-stack: Eliminate now-deprecated readdir_r 31/125231/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 14 Apr 2017 07:36:14 +0000 (09:36 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 14 Apr 2017 07:43:18 +0000 (09:43 +0200)
This commit fixes build break with new toolchain.

Glibc 2.24 deprecated readdir_r() - readdir() now recommended even
for multithreaded programs.  This commit fixes following error:

/home/abuild/rpmbuild/BUILD/crash-worker-1.0.0/src/crash-stack/crash-stack.c: In function 'find_crash_tid':
/home/abuild/rpmbuild/BUILD/crash-worker-1.0.0/src/crash-stack/crash-stack.c:891:4: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations]
while (readdir_r(dir, &entry, &dentry) == 0 && dentry) {
^~~~~

Change-Id: I99f22a0de87f2539988e1669ae2149dcac74a4df

src/crash-stack/crash-stack.c

index edda6cd..587e932 100644 (file)
@@ -870,8 +870,7 @@ static int find_crash_tid(int pid)
        int threadnum = 1;
        int crash_tid = -1;
        DIR *dir;
-       struct dirent entry;
-       struct dirent *dentry = NULL;
+       struct dirent *entry;
        char task_path[PATH_MAX];
        struct stat sb;
 
@@ -888,12 +887,12 @@ static int find_crash_tid(int pid)
                        fprintf(errfile, "[crash-stack] cannot open %s\n", task_path);
                        return -1;
                } else {
-                       while (readdir_r(dir, &entry, &dentry) == 0 && dentry) {
-                               if (strcmp(dentry->d_name, ".") == 0 ||
-                                   strcmp(dentry->d_name, "..") == 0)
+                       while ((entry = readdir(dir)) != NULL) {
+                               if (strcmp(entry->d_name, ".") == 0 ||
+                                   strcmp(entry->d_name, "..") == 0)
                                        continue;
                                crash_tid = check_thread_wchan(pid,
-                                               atoi(dentry->d_name));
+                                                              atoi(entry->d_name));
                                if (crash_tid > 0)
                                        break;
                        }