From 4aa44f7475e03dcc596f6a13fffffda7268074a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 May 2007 13:44:36 +0000 Subject: r22761: This introduces lib/conn_tdb.c with two main functions: connections_traverse and connections_forall. This centralizes all the routines that did individual tdb_open("connections.tdb") and direct tdb_traverse. Volker (This used to be commit e43e94cda1ad8876b3cb5d1129080b57fa6ec214) --- source3/web/statuspage.c | 83 ++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 52 deletions(-) (limited to 'source3/web') diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index 7b5c528a7d..2071561e2e 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -167,20 +167,17 @@ static void print_share_mode(const struct share_mode_entry *e, /* kill off any connections chosen by the user */ -static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn1(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 && process_exists(crec.pid)) { + if (crec->cnum == -1 && process_exists(crec->pid)) { char buf[30]; - slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec.pid)); + slprintf(buf, sizeof(buf)-1,"kill_%s", + procid_str_static(&crec->pid)); if (cgi_variable(buf)) { - kill_pid(crec.pid); + kill_pid(crec->pid); sleep(SLEEP_TIME); } } @@ -188,28 +185,24 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st } /* traversal fn for showing machine connections */ -static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn2(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 || !process_exists(crec.pid) || - procid_equal(&crec.pid, &smbd_pid)) + if (crec->cnum == -1 || !process_exists(crec->pid) || + procid_equal(&crec->pid, &smbd_pid)) return 0; - addPid2Machine (crec.pid, crec.machine); + addPid2Machine (crec->pid, crec->machine); printf("%s%s%s%s\n", - procid_str_static(&crec.pid), - crec.machine,crec.addr, - tstring(crec.start)); + procid_str_static(&crec->pid), + crec->machine, crec->addr, + tstring(crec->start)); if (geteuid() == 0) { printf("\n", - procid_str_static(&crec.pid)); + procid_str_static(&crec->pid)); } printf("\n"); @@ -217,23 +210,19 @@ static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* st } /* traversal fn for showing share connections */ -static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state) +static int traverse_fn3(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *crec, + void* state) { - struct connections_data crec; - - if (dbuf.dsize != sizeof(crec)) - return 0; - - memcpy(&crec, dbuf.dptr, sizeof(crec)); - - if (crec.cnum == -1 || !process_exists(crec.pid)) + if (crec->cnum == -1 || !process_exists(crec->pid)) return 0; printf("%s%s%s%s%s%s\n", - crec.servicename,uidtoname(crec.uid), - gidtoname(crec.gid),procid_str_static(&crec.pid), - crec.machine, - tstring(crec.start)); + crec->servicename, uidtoname(crec->uid), + gidtoname(crec->gid),procid_str_static(&crec->pid), + crec->machine, + tstring(crec->start)); return 0; } @@ -244,7 +233,6 @@ void status_page(void) const char *v; int autorefresh=0; int refresh_interval=30; - TDB_CONTEXT *tdb; int nr_running=0; BOOL waitup = False; @@ -322,8 +310,7 @@ void status_page(void) PID_or_Machine = 0; } - tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); - if (tdb) tdb_traverse(tdb, traverse_fn1, NULL); + connections_forall(traverse_fn1, NULL); initPid2Machine (); @@ -344,12 +331,6 @@ void status_page(void) printf("

\n"); - if (!tdb) { - /* open failure either means no connections have been - made */ - } - - printf("\n"); printf("", _("version:"), SAMBA_VERSION_STRING); @@ -419,7 +400,7 @@ void status_page(void) } printf("\n"); - if (tdb) tdb_traverse(tdb, traverse_fn2, NULL); + connections_forall(traverse_fn2, NULL); printf("
%s%s

\n"); @@ -428,7 +409,7 @@ void status_page(void) printf("%s%s%s%s%s%s\n\n", _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date")); - if (tdb) tdb_traverse(tdb, traverse_fn3, NULL); + connections_forall(traverse_fn3, NULL); printf("

\n"); @@ -441,8 +422,6 @@ void status_page(void) locking_end(); printf("\n"); - if (tdb) tdb_close(tdb); - printf("
\n", _("Show Client in col 1")); printf("\n", _("Show PID in col 1")); -- cgit