Author: markj
Date: Sat Jan 31 03:22:00 2015
New Revision: 277961
URL: https://svnweb.freebsd.org/changeset/base/277961

Log:
  Stop iterating and return if the caller-supplied callback function returns
  a non-zero value.
  
  MFC after:    1 week

Modified:
  head/lib/libproc/proc_sym.c

Modified: head/lib/libproc/proc_sym.c
==============================================================================
--- head/lib/libproc/proc_sym.c Sat Jan 31 02:15:16 2015        (r277960)
+++ head/lib/libproc/proc_sym.c Sat Jan 31 03:22:00 2015        (r277961)
@@ -153,9 +153,12 @@ proc_iter_objs(struct proc_handle *p, pr
        prmap_t map;
        char path[MAXPATHLEN];
        char last[MAXPATHLEN];
+       int error;
 
        if (p->nobjs == 0)
                return (-1);
+
+       error = 0;
        memset(last, 0, sizeof(last));
        for (i = 0; i < p->nobjs; i++) {
                rdl = &p->rdobjs[i];
@@ -169,11 +172,11 @@ proc_iter_objs(struct proc_handle *p, pr
                 */
                if (strcmp(path, last) == 0)
                        continue;
-               (*func)(cd, &map, path);
+               if ((error = (*func)(cd, &map, path)) != 0)
+                       break;
                strlcpy(last, path, sizeof(last));
        }
-
-       return (0);
+       return (error);
 }
 
 prmap_t *
@@ -599,7 +602,8 @@ proc_iter_symbyaddr(struct proc_handle *
                s = elf_strptr(e, stridx, sym.st_name);
                if (ehdr.e_type != ET_EXEC)
                        sym.st_value += map->pr_vaddr;
-               (*func)(cd, &sym, s);
+               if ((error = (*func)(cd, &sym, s)) != 0)
+                       goto err2;
        }
        error = 0;
 err2:
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to