Subject: | Low-level code in Proc::ProcessTable does not use warn |
I've attached a simple example fix for the fact that the os/*.c code
in Proc::ProcessTable does not use warn().
It turns out that (in an unrelated problem) Proc::ProcessTable is hit
by the same problem that procps was on Linux systems (get more info
on this at http://www.ussg.iu.edu/hypermail/linux/kernel/0202.2/0446.html)
This leads to spurious warning on some of our systems which cannot be
shut off using $SIG{__WARN__}.
Fixing the larger problem of /proc/stat interaction would be good (though
it's not tuely Proc::ProcessTable's problem), but making it not issue
warnings to stderr without calling warn() is useful regardless since there
are many instances (e.g. CGI, monitoring systems, etc) where
calling warn() is useful for reporting to a human being, but simple
stderr is likely to be thrown away.
diff --new-file -ur Proc-ProcessTable-0.38/ProcessTable.xs /home/ajs/.cpan/build/Proc-ProcessTable-0.38/ProcessTable.xs
--- Proc-ProcessTable-0.38/ProcessTable.xs Thu Nov 7 21:38:27 2002
+++ /home/ajs/.cpan/build/Proc-ProcessTable-0.38/ProcessTable.xs Wed May 14 12:34:11 2003
@@ -31,6 +31,8 @@
#include <string.h>
#include <stdarg.h>
+#include "ppt.h"
+
/* prototypes to make the compiler shut up */
void store_ttydev( HV*, unsigned long );
void bless_into_proc(char* , char**, ...);
@@ -47,6 +49,18 @@
/* This holds a pointer to the list of process objects we will build */
AV* Proclist;
+/* Our local varargs warn which can be called as extern by code
+ * that doesn't know Perl internals (and thus doesn't have a
+ * warn() defined).
+ */
+void ppt_warn(const char *pat, ...) {
+ dTHX;
+ va_list args;
+ va_start(args, pat);
+ vwarn(pat, &args);
+ va_end(args);
+}
+
/* Look up the tty device, given the ttynum and store it */
void store_ttydev( HV* myhash, unsigned long ttynum ){
SV** ttydev;
diff --new-file -ur Proc-ProcessTable-0.38/os/Linux.c /home/ajs/.cpan/build/Proc-ProcessTable-0.38/os/Linux.c
--- Proc-ProcessTable-0.38/os/Linux.c Thu Nov 7 20:03:12 2002
+++ /home/ajs/.cpan/build/Proc-ProcessTable-0.38/os/Linux.c Wed May 14 12:27:52 2003
@@ -1,5 +1,6 @@
#include "os/Linux.h"
+#include "ppt.h"
unsigned long Hertz;
@@ -401,7 +402,7 @@
#define FILE_TO_BUF(filename, fd) do{ \
static int n; \
if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \
- fprintf(stderr, BAD_OPEN_MESSAGE); \
+ ppt_warn(BAD_OPEN_MESSAGE); \
close(fd); \
return 0; \
} \
@@ -476,7 +477,7 @@
case 1015 ... 1035 : Hertz = 1024; break; /* Alpha */
default:
Hertz = (sizeof(long)==sizeof(int)) ? 100UL : 1024UL;
- fprintf(stderr, "Unknown HZ value! (%ld) Assume %ld.\n", h, Hertz);
+ ppt_warn("Unknown HZ value! (%ld) Assume %ld.\n", h, Hertz);
}
#endif /* HZ */
return 0; /* useless, but FILE_TO_BUF has a return in it */
diff --new-file -ur Proc-ProcessTable-0.38/ppt.h /home/ajs/.cpan/build/Proc-ProcessTable-0.38/ppt.h
--- Proc-ProcessTable-0.38/ppt.h Wed Dec 31 19:00:00 1969
+++ /home/ajs/.cpan/build/Proc-ProcessTable-0.38/ppt.h Wed May 14 12:28:37 2003
@@ -0,0 +1 @@
+extern void ppt_warn(const char *pat, ...);