patch for samba-2.2.1a/source/web/statuspage.c
Joachim Ott
ott at ardala.han.de
Sat Sep 29 15:02:03 GMT 2001
Hi,
included is a patch for samba-2.2.1a/source/web/statuspage.c, in the table
"Open Files" the Client-name is shown rather than the PID.
-------------- next part --------------
--- samba-2.2.1a/source/web/statuspage.c.org Sat Sep 29 17:05:32 2001
+++ samba-2.2.1a/source/web/statuspage.c Sat Sep 29 17:28:15 2001
@@ -21,8 +21,79 @@
#include "includes.h"
+#define PIDMAP struct PidMap
+
+PIDMAP {
+ PIDMAP *next;
+ pid_t pid;
+ char *machine;
+};
+
+static PIDMAP *pidmap, *pidmap_current;
+
static pid_t smbd_pid;
+/* from 2nd call on, remove old list */
+static void initPid2Machine (void)
+{
+ PIDMAP *p, *q;
+
+ for (p = pidmap; p != NULL; ) {
+ q = p->next;
+
+ if (p->machine)
+ free (p->machine);
+
+ free (p);
+ p = q;
+ }
+
+ pidmap = pidmap_current = NULL;
+}
+
+/* add new PID <-> Machine name mapping */
+static void addPid2Machine (pid_t pid, char *machine)
+{
+ PIDMAP *newmap;
+
+ if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) {
+ /* need error message? */
+ return;
+ }
+
+ newmap->next = NULL;
+ newmap->pid = pid;
+ newmap->machine = strdup (machine);
+
+ if (pidmap == NULL) {
+ pidmap = pidmap_current = newmap;
+ }
+ else {
+ pidmap_current->next = newmap;
+ pidmap_current = newmap;
+ }
+}
+
+/* lookup PID <-> Machine name mapping */
+static char *mapPid2Machine (pid_t pid)
+{
+ static char pidbuf [64];
+ PIDMAP *map;
+
+ for (map = pidmap; map != NULL; map = map->next) {
+ if (pid == map->pid) {
+ if (map->machine == NULL) /* no machine name */
+ break; /* show PID */
+
+ return map->machine;
+ }
+ }
+
+ /* PID not in list or machine name NULL? return pid as string */
+ snprintf (pidbuf, sizeof (pidbuf) - 1, "%d", pid);
+ return pidbuf;
+}
+
static char *tstring(time_t t)
{
static pstring buf;
@@ -33,7 +104,7 @@
static void print_share_mode(share_mode_entry *e, char *fname)
{
- printf("<tr><td>%d</td>",(int)e->pid);
+ printf("<tr><td>%s</td>", mapPid2Machine (e->pid));
printf("<td>");
switch ((e->share_mode>>4)&0xF) {
case DENY_NONE: printf("DENY_NONE"); break;
@@ -105,6 +176,8 @@
if (crec.cnum != -1 || !process_exists(crec.pid) || (crec.pid == smbd_pid))
return 0;
+ addPid2Machine (crec.pid, crec.machine);
+
printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
(int)crec.pid,
crec.machine,crec.addr,
@@ -190,6 +263,8 @@
tdb = tdb_open_log(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0);
if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
+ initPid2Machine ();
+
printf("<H2>Server Status</H2>\n");
printf("<FORM method=post>\n");
@@ -268,7 +343,7 @@
printf("<h3>Open Files</h3>\n");
printf("<table border=1>\n");
- printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
+ printf("<tr><th>Client</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
locking_init(1);
share_mode_forall(print_share_mode);
More information about the samba
mailing list