DragonFly BSD
DragonFly submit List (threaded) for 2004-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: strtonum(3)


From: Chris Pressey <cpressey@xxxxxxxxxxxxxxx>
Date: Tue, 27 Jul 2004 15:02:22 -0700

On Mon, 26 Jul 2004 08:25:23 +0200
Jeroen Ruigrok/asmodai <asmodai@xxxxxx> wrote:

> -On [20040726 08:12], Chris Pressey (cpressey@xxxxxxxxxxxxxxx) wrote:
> >I like it, but I don't know what our official policy (if any) on
> >stdlib API extensions is... assuming we're open to them, I'll be
> >happy to handle this.
> 
> Do I need to mention strlcat(), strlcpy() and such extensions?
> 
> Just add it, this kind of stuff sets a precedent and we can then lobby
> the C committee and the SUS/POSIX guys for extending the base
> specifications since we are actively using it.

In that case, I propose adding an extension to obtain the pid of the
process on the other end of a popen()'ed stream; see attached patch.
This information is currently impossible to get at without rolling your
own custom popen/pclose functions (which I had to do in the installer.)

-Chris

Index: include/stdio.h
===================================================================
RCS file: /home/dcvs/src/include/stdio.h,v
retrieving revision 1.5
diff -u -r1.5 stdio.h
--- include/stdio.h	15 Nov 2003 19:28:42 -0000	1.5
+++ include/stdio.h	26 Jul 2004 19:19:44 -0000
@@ -49,6 +49,11 @@
 #include <machine/stdarg.h>
 #endif
 
+#ifndef _PID_T_DECLARED
+#define _PID_T_DECLARED
+typedef	__pid_t		pid_t;		/* process id */
+#endif
+
 #ifndef _SIZE_T_DECLARED
 #define _SIZE_T_DECLARED
 typedef __size_t	size_t;
@@ -313,6 +318,7 @@
 __off_t ftello (FILE *);
 int	 getw (FILE *);
 int	 pclose (FILE *);
+pid_t	 pgetpid (FILE *);
 FILE	*popen (const char *, const char *);
 int	 putw (int, FILE *);
 void	 setbuffer (FILE *, char *, int);
Index: sys/sys/types.h
===================================================================
RCS file: /home/dcvs/src/sys/sys/types.h,v
retrieving revision 1.6
diff -u -r1.6 types.h
--- sys/sys/types.h	15 Nov 2003 19:28:42 -0000	1.6
+++ sys/sys/types.h	26 Jul 2004 19:19:28 -0000
@@ -82,7 +82,6 @@
 typedef	__uint16_t	mode_t;		/* permissions */
 typedef	__uint16_t	nlink_t;	/* link count */
 typedef	__off_t		off_t;		/* file offset */
-typedef	__pid_t		pid_t;		/* process id */
 typedef	quad_t		rlim_t;		/* resource limit */
 typedef	__int32_t	segsz_t;	/* segment size */
 typedef	__int32_t	swblk_t;	/* swap offset */
@@ -131,6 +130,11 @@
 typedef __clockid_t	clockid_t;
 #endif
 
+#ifndef _PID_T_DECLARED
+#define _PID_T_DECLARED
+typedef	__pid_t		pid_t;		/* process id */
+#endif
+
 #ifndef _SIZE_T_DECLARED
 #define _SIZE_T_DECLARED
 typedef __size_t	size_t;
Index: lib/libc/gen/popen.3
===================================================================
RCS file: /home/dcvs/src/lib/libc/gen/popen.3,v
retrieving revision 1.2
diff -u -r1.2 popen.3
--- lib/libc/gen/popen.3	17 Jun 2003 04:26:42 -0000	1.2
+++ lib/libc/gen/popen.3	27 Jul 2004 21:50:40 -0000
@@ -33,12 +33,13 @@
 .\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.10.2.4 2003/03/15 15:11:05 trhodes Exp $
 .\" $DragonFly: src/lib/libc/gen/popen.3,v 1.2 2003/06/17 04:26:42 dillon Exp $
 .\"
-.Dd May 3, 1995
+.Dd Jul 27, 2004
 .Dt POPEN 3
 .Os
 .Sh NAME
 .Nm popen ,
-.Nm pclose
+.Nm pclose ,
+.Nm pgetpid
 .Nd process
 .Tn I/O
 .Sh LIBRARY
@@ -49,6 +50,8 @@
 .Fn popen "const char *command" "const char *type"
 .Ft int
 .Fn pclose "FILE *stream"
+.Ft pid_t
+.Fn pgetpid "FILE *stream"
 .Sh DESCRIPTION
 The
 .Fn popen
@@ -124,6 +127,12 @@
 and returns the exit status of the command
 as returned by
 .Fn wait4 .
+.Pp
+The
+.Fn pgetpid
+function returns the pid of the process on the other end of a stream that
+was opened with
+.Fn popen .
 .Sh RETURN VALUES
 The
 .Fn popen
@@ -145,11 +154,20 @@
 .Dq popened
 command, if
 .Fa stream
-already
+has already been
 .Dq pclosed ,
 or if
 .Xr wait4
 returns an error.
+.Pp
+The
+.Fn pgetpid
+function returns (pid_t)\-1 if
+.Fa stream
+is not associated with a
+.Dq popened
+command or if it has already been
+.Dq pclosed .
 .Sh ERRORS
 The
 .Fn popen
@@ -200,3 +218,7 @@
 .Pp
 Bidirectional functionality was added in
 .Fx 2.2.6 .
+The
+.Fn pgetpid
+function appeared in
+.Dx 1.1 .
Index: lib/libc/gen/popen.c
===================================================================
RCS file: /home/dcvs/src/lib/libc/gen/popen.c,v
retrieving revision 1.3
diff -u -r1.3 popen.c
--- lib/libc/gen/popen.c	6 Jun 2004 15:05:55 -0000	1.3
+++ lib/libc/gen/popen.c	26 Jul 2004 19:03:19 -0000
@@ -188,3 +188,14 @@
 
 	return (pid == -1 ? -1 : pstat);
 }
+
+pid_t
+pgetpid(FILE *iop)
+{
+	struct pid *cur;
+
+	for (cur = pidlist; cur != NULL; cur = cur->next)
+		if (cur->fp == iop)
+			return (cur->pid);
+	return (-1);
+}


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]