diff options
author | Gerald Carter <jerry@samba.org> | 2001-10-06 18:03:25 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2001-10-06 18:03:25 +0000 |
commit | 8ad2982968478d91c9f799808195baf818d4fdae (patch) | |
tree | 108cb9d0573c2880b170bd55b85040c157ea9262 /source3 | |
parent | 032f65d5ff7de0a895e8915ea669bdbe07b9ae52 (diff) | |
download | samba-8ad2982968478d91c9f799808195baf818d4fdae.tar.gz samba-8ad2982968478d91c9f799808195baf818d4fdae.tar.bz2 samba-8ad2982968478d91c9f799808195baf818d4fdae.zip |
merge from 2.2
(This used to be commit 831530d93d606d13a792be1d3d4ac561697504d8)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/web/statuspage.c | 86 |
1 files changed, 84 insertions, 2 deletions
diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index 61bbf67a13..b49fc7b656 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -22,8 +22,79 @@ #include "includes.h" #include "webintl.h" +#define PIDMAP struct PidMap + +PIDMAP { + PIDMAP *next, *prev; + pid_t pid; + char *machine; +}; + +static PIDMAP *pidmap; +static int PID_or_Machine; /* 0 = show PID, else show Machine name */ + static pid_t smbd_pid; +/* from 2nd call on, remove old list */ +static void initPid2Machine (void) +{ + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + PIDMAP *p, *q; + + for (p = pidmap; p != NULL; ) { + DLIST_REMOVE(pidmap, p); + SAFE_FREE(p->machine); + SAFE_FREE(p); + } + + pidmap = NULL; + } +} + +/* add new PID <-> Machine name mapping */ +static void addPid2Machine (pid_t pid, char *machine) +{ + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + PIDMAP *newmap; + + if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) { + /* XXX need error message for this? + if malloc fails, PID is always shown */ + return; + } + + newmap->pid = pid; + newmap->machine = strdup (machine); + + DLIST_ADD(pidmap, newmap); + } +} + +/* lookup PID <-> Machine name mapping */ +static char *mapPid2Machine (pid_t pid) +{ + static char pidbuf [64]; + PIDMAP *map; + + /* show machine name rather PID on table "Open Files"? */ + if (PID_or_Machine) { + 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; @@ -34,7 +105,7 @@ static char *tstring(time_t t) 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; @@ -106,9 +177,11 @@ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st 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, + crec.machine,crec.addr, tstring(crec.start)); if (geteuid() == 0) { printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n", @@ -188,8 +261,14 @@ void status_page(void) refresh_interval = atoi(v); } + if (cgi_variable("show_client_in_col_1")) { + PID_or_Machine = 1; + } + tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); + + initPid2Machine (); printf("<H2>%s</H2>\n", _("Server Status")); @@ -277,6 +356,9 @@ void status_page(void) if (tdb) tdb_close(tdb); + printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"Show Client in col 1\">\n"); + printf("<input type=submit name=\"show_pid_in_col_1\" value=\"Show PID in col 1\">\n"); + printf("</FORM>\n"); if (autorefresh) { |