svn commit: r250416 - in stable/9/sys: kern sys

Mikolaj Golub trociny at FreeBSD.org
Thu May 9 18:38:50 UTC 2013


Author: trociny
Date: Thu May  9 18:38:49 2013
New Revision: 250416
URL: http://svnweb.freebsd.org/changeset/base/250416

Log:
  MFC r249488:
  
  Similarly to proc_getargv() and proc_getenvv(), export proc_getauxv()
  to be able to reuse the code.

Modified:
  stable/9/sys/kern/kern_proc.c
  stable/9/sys/sys/proc.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/sys/   (props changed)

Modified: stable/9/sys/kern/kern_proc.c
==============================================================================
--- stable/9/sys/kern/kern_proc.c	Thu May  9 17:25:29 2013	(r250415)
+++ stable/9/sys/kern/kern_proc.c	Thu May  9 18:38:49 2013	(r250416)
@@ -1760,6 +1760,27 @@ proc_getenvv(struct thread *td, struct p
 	return (get_ps_strings(curthread, p, sb, PROC_ENV));
 }
 
+int
+proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
+{
+	size_t vsize, size;
+	char **auxv;
+	int error;
+
+	error = get_proc_vector(td, p, &auxv, &vsize, PROC_AUX);
+	if (error == 0) {
+#ifdef COMPAT_FREEBSD32
+		if (SV_PROC_FLAG(p, SV_ILP32) != 0)
+			size = vsize * sizeof(Elf32_Auxinfo);
+		else
+#endif
+			size = vsize * sizeof(Elf_Auxinfo);
+		error = sbuf_bcat(sb, auxv, size);
+		free(auxv, M_TEMP);
+	}
+	return (error);
+}
+
 /*
  * This sysctl allows a process to retrieve the argument list or process
  * title for another process without groping around in the address space
@@ -1865,9 +1886,8 @@ sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARG
 	int *name = (int *)arg1;
 	u_int namelen = arg2;
 	struct proc *p;
-	size_t vsize, size;
-	char **auxv;
-	int error;
+	struct sbuf sb;
+	int error, error2;
 
 	if (namelen != 1)
 		return (EINVAL);
@@ -1879,21 +1899,12 @@ sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARG
 		PRELE(p);
 		return (0);
 	}
-	error = get_proc_vector(curthread, p, &auxv, &vsize, PROC_AUX);
-	if (error == 0) {
-#ifdef COMPAT_FREEBSD32
-		if (SV_PROC_FLAG(p, SV_ILP32) != 0)
-			size = vsize * sizeof(Elf32_Auxinfo);
-		else
-#endif
-		size = vsize * sizeof(Elf_Auxinfo);
-		PRELE(p);
-		error = SYSCTL_OUT(req, auxv, size);
-		free(auxv, M_TEMP);
-	} else {
-		PRELE(p);
-	}
-	return (error);
+	sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
+	error = proc_getauxv(curthread, p, &sb);
+	error2 = sbuf_finish(&sb);
+	PRELE(p);
+	sbuf_delete(&sb);
+	return (error != 0 ? error : error2);
 }
 
 /*

Modified: stable/9/sys/sys/proc.h
==============================================================================
--- stable/9/sys/sys/proc.h	Thu May  9 17:25:29 2013	(r250415)
+++ stable/9/sys/sys/proc.h	Thu May  9 18:38:49 2013	(r250416)
@@ -884,6 +884,7 @@ struct	pargs *pargs_alloc(int len);
 void	pargs_drop(struct pargs *pa);
 void	pargs_hold(struct pargs *pa);
 int	proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb);
+int	proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb);
 int	proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb);
 void	procinit(void);
 void	proc_linkup0(struct proc *p, struct thread *td);


More information about the svn-src-stable-9 mailing list