static bool do_winbind_onlinestatus(struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { struct server_id myid; myid = pid_to_procid(sys_getpid()); if (argc != 1) { fprintf(stderr, "Usage: smbcontrol winbindd onlinestatus\n"); return False; } messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS, print_pid_string_cb); if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid))) return False; wait_replies(msg_ctx, procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ if (num_replies == 0) printf("No replies received\n"); messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL); return num_replies; }
static BOOL retrieve_all_messages(char **msgs_buf, size_t *total_len) { TDB_DATA kbuf; TDB_DATA dbuf; TDB_DATA null_dbuf; ZERO_STRUCT(null_dbuf); *msgs_buf = NULL; *total_len = 0; kbuf = message_key_pid(pid_to_procid(sys_getpid())); if (tdb_chainlock(tdb, kbuf) == -1) return False; dbuf = tdb_fetch(tdb, kbuf); /* * Replace with an empty record to keep the allocated * space in the tdb. */ tdb_store(tdb, kbuf, null_dbuf, TDB_REPLACE); tdb_chainunlock(tdb, kbuf); if (dbuf.dptr == NULL || dbuf.dsize == 0) { SAFE_FREE(dbuf.dptr); return False; } *msgs_buf = dbuf.dptr; *total_len = dbuf.dsize; return True; }
static bool do_winbind_validate_cache(struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { struct server_id myid = pid_to_procid(sys_getpid()); if (argc != 1) { fprintf(stderr, "Usage: smbcontrol winbindd validate-cache\n"); return False; } messaging_register(msg_ctx, NULL, MSG_WINBIND_VALIDATE_CACHE, winbind_validate_cache_cb); if (!send_message(msg_ctx, pid, MSG_WINBIND_VALIDATE_CACHE, &myid, sizeof(myid))) { return False; } wait_replies(msg_ctx, procid_to_pid(&pid) == 0); if (num_replies == 0) { printf("No replies received\n"); } messaging_deregister(msg_ctx, MSG_WINBIND_VALIDATE_CACHE, NULL); return num_replies; }
static void remove_child_pid(struct smbd_parent_context *parent, pid_t pid, bool unclean_shutdown) { struct smbd_child_pid *child; struct server_id child_id; int ret; child_id = pid_to_procid(pid); ret = messaging_cleanup(parent->msg_ctx, pid); if ((ret != 0) && (ret != ENOENT)) { DEBUG(10, ("%s: messaging_cleanup returned %s\n", __func__, strerror(ret))); } smbprofile_cleanup(pid); for (child = parent->children; child != NULL; child = child->next) { if (child->pid == pid) { struct smbd_child_pid *tmp = child; DLIST_REMOVE(parent->children, child); TALLOC_FREE(tmp); parent->num_children -= 1; break; } } if (child == NULL) { /* not all forked child processes are added to the children list */ DEBUG(2, ("Could not find child %d -- ignoring\n", (int)pid)); return; } if (unclean_shutdown) { /* a child terminated uncleanly so tickle all processes to see if they can grab any of the pending locks */ DEBUG(3,(__location__ " Unclean shutdown of pid %u\n", (unsigned int)pid)); if (parent->cleanup_te == NULL) { /* call the cleanup timer, but not too often */ int cleanup_time = lp_parm_int(-1, "smbd", "cleanuptime", 20); parent->cleanup_te = tevent_add_timer(parent->ev_ctx, parent, timeval_current_ofs(cleanup_time, 0), cleanup_timeout_fn, parent); DEBUG(1,("Scheduled cleanup of brl and lock database after unclean shutdown\n")); } } if (!serverid_deregister(child_id)) { DEBUG(1, ("Could not remove pid %d from serverid.tdb\n", (int)pid)); } }
static struct server_id parse_dest(const char *dest) { struct server_id result = {-1}; pid_t pid; /* Zero is a special return value for broadcast to all processes */ if (strequal(dest, "all")) { return interpret_pid(MSG_BROADCAST_PID_STR); } /* Try self - useful for testing */ if (strequal(dest, "self")) { return pid_to_procid(sys_getpid()); } /* Fix winbind typo. */ if (strequal(dest, "winbind")) { dest = "winbindd"; } if (!(strequal(dest, "winbindd") || strequal(dest, "nmbd"))) { /* Check for numeric pid number */ result = interpret_pid(dest); /* Zero isn't valid if not smbd. */ if (result.pid && procid_valid(&result)) { return result; } } /* Look up other destinations in pidfile directory */ if ((pid = pidfile_pid(dest)) != 0) { return pid_to_procid(pid); } fprintf(stderr,"Can't find pid for destination '%s'\n", dest); return result; }
static bool do_winbind_dump_domain_list(struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { const char *domain = NULL; int domain_len = 0; struct server_id myid; uint8_t *buf = NULL; int buf_len = 0; myid = pid_to_procid(sys_getpid()); if (argc < 1 || argc > 2) { fprintf(stderr, "Usage: smbcontrol <dest> dump_domain_list " "<domain>\n"); return false; } if (argc == 2) { domain = argv[1]; domain_len = strlen(argv[1]) + 1; } messaging_register(msg_ctx, NULL, MSG_WINBIND_DUMP_DOMAIN_LIST, print_pid_string_cb); buf_len = sizeof(myid)+domain_len; buf = SMB_MALLOC_ARRAY(uint8_t, buf_len); if (!buf) { return false; } memcpy(buf, &myid, sizeof(myid)); memcpy(&buf[sizeof(myid)], domain, domain_len); if (!send_message(msg_ctx, pid, MSG_WINBIND_DUMP_DOMAIN_LIST, buf, buf_len)) { SAFE_FREE(buf); return false; } wait_replies(msg_ctx, procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ SAFE_FREE(buf); if (num_replies == 0) { printf("No replies received\n"); } messaging_deregister(msg_ctx, MSG_WINBIND_DUMP_DOMAIN_LIST, NULL); return num_replies; }
static int shutdown_other_smbds(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *p) { struct sessionid *sessionid = (struct sessionid *)dbuf.dptr; const char *ip = (const char *)p; if (!process_exists(pid_to_procid(sessionid->pid))) { return 0; } if (sessionid->pid == sys_getpid()) { return 0; } if (strcmp(ip, sessionid->ip_addr) != 0) { return 0; } message_send_pid(pid_to_procid(sessionid->pid), MSG_SHUTDOWN, NULL, 0, True); return 0; }
NTSTATUS messaging_send_to_children(struct messaging_context *msg_ctx, uint32_t msg_type, DATA_BLOB* data) { NTSTATUS status; struct child_pid *child; for (child = children; child != NULL; child = child->next) { status = messaging_send(msg_ctx, pid_to_procid(child->pid), msg_type, data); if (!NT_STATUS_IS_OK(status)) { return status; } } return NT_STATUS_OK; }
static bool do_dump_event_list(struct messaging_context *msg_ctx, const struct server_id pid, const int argc, const char **argv) { struct server_id myid; myid = pid_to_procid(sys_getpid()); if (argc != 1) { fprintf(stderr, "Usage: smbcontrol <dest> dump-event-list\n"); return False; } return send_message(msg_ctx, pid, MSG_DUMP_EVENT_LIST, NULL, 0); }
void prefork_warn_active_children(struct messaging_context *msg_ctx, struct prefork_pool *pfp) { const DATA_BLOB ping = data_blob_null; int i; for (i = 0; i < pfp->pool_size; i++) { if (pfp->pool[i].status == PF_WORKER_NONE) { continue; } messaging_send(msg_ctx, pid_to_procid(pfp->pool[i].pid), MSG_PREFORK_PARENT_EVENT, &ping); } }
int prefork_retire_children(struct messaging_context *msg_ctx, struct prefork_pool *pfp, int num_children, time_t age_limit) { const DATA_BLOB ping = data_blob_null; time_t now = time(NULL); struct prefork_oldest *oldest; int i, j; oldest = talloc_array(pfp, struct prefork_oldest, pfp->pool_size); if (!oldest) { return -1; } for (i = 0; i < pfp->pool_size; i++) { oldest[i].num = i; if (pfp->pool[i].status == PF_WORKER_ALIVE || pfp->pool[i].status == PF_WORKER_ACCEPTING) { oldest[i].started = pfp->pool[i].started; } else { oldest[i].started = now; } } qsort(oldest, pfp->pool_size, sizeof(struct prefork_oldest), prefork_sort_oldest); for (i = 0, j = 0; i < pfp->pool_size && j < num_children; i++) { if (((pfp->pool[i].status == PF_WORKER_ALIVE) && (pfp->pool[i].num_clients < 1)) && (pfp->pool[i].started <= age_limit)) { /* tell the child it's time to give up */ DEBUG(5, ("Retiring pid %u!\n", (unsigned int)pfp->pool[i].pid)); pfp->pool[i].cmds = PF_SRV_MSG_EXIT; messaging_send(msg_ctx, pid_to_procid(pfp->pool[i].pid), MSG_PREFORK_PARENT_EVENT, &ping); j++; } } return j; }
static int traverse_processes(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct sessionid sessionid; struct process_id pid; if (dbuf.dsize != sizeof(sessionid)) return 0; memcpy(&sessionid, dbuf.dptr, sizeof(sessionid)); pid = pid_to_procid((pid_t)sessionid.pid); if (!process_exists(pid)) { return 0; } Ucrit_addPid( sessionid.pid ); d_printf("%5d %-12s %-12s", (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid)); do_collect_usrstat(pid); return 0; }
NTSTATUS messaging_send_to_children(struct messaging_context *msg_ctx, uint32_t msg_type, DATA_BLOB* data) { NTSTATUS status; struct smbd_parent_context *parent = am_parent; struct smbd_child_pid *child; if (parent == NULL) { return NT_STATUS_INTERNAL_ERROR; } for (child = parent->children; child != NULL; child = child->next) { status = messaging_send(parent->msg_ctx, pid_to_procid(child->pid), msg_type, data); if (!NT_STATUS_IS_OK(status)) { return status; } } return NT_STATUS_OK; }
bool cli_send_mailslot(struct messaging_context *msg_ctx, bool unique, const char *mailslot, uint16 priority, char *buf, int len, const char *srcname, int src_type, const char *dstname, int dest_type, const struct sockaddr_storage *dest_ss) { struct packet_struct p; struct dgram_packet *dgram = &p.packet.dgram; char *ptr, *p2; char tmp[4]; pid_t nmbd_pid; char addr[INET6_ADDRSTRLEN]; if ((nmbd_pid = pidfile_pid("nmbd")) == 0) { DEBUG(3, ("No nmbd found\n")); return False; } if (dest_ss->ss_family != AF_INET) { DEBUG(3, ("cli_send_mailslot: can't send to IPv6 address.\n")); return false; } memset((char *)&p, '\0', sizeof(p)); /* * Next, build the DGRAM ... */ /* DIRECT GROUP or UNIQUE datagram. */ dgram->header.msg_type = unique ? 0x10 : 0x11; dgram->header.flags.node_type = M_NODE; dgram->header.flags.first = True; dgram->header.flags.more = False; dgram->header.dgm_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100); /* source ip is filled by nmbd */ dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ dgram->header.packet_offset = 0; make_nmb_name(&dgram->source_name,srcname,src_type); make_nmb_name(&dgram->dest_name,dstname,dest_type); ptr = &dgram->data[0]; /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); if (smb_size + 17*2 + strlen(mailslot) + 1 + len > MAX_DGRAM_SIZE) { DEBUG(0, ("cli_send_mailslot: Cannot write beyond end of packet\n")); return False; } cli_set_message(ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); SSVAL(ptr,smb_vwv1,len); SSVAL(ptr,smb_vwv11,len); SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); SSVAL(ptr,smb_vwv13,3); SSVAL(ptr,smb_vwv14,1); SSVAL(ptr,smb_vwv15,priority); SSVAL(ptr,smb_vwv16,2); p2 = smb_buf(ptr); fstrcpy(p2,mailslot); p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2); if (!p2) { return False; } memcpy(p2,buf,len); p2 += len; dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ p.packet_type = DGRAM_PACKET; p.ip = ((const struct sockaddr_in *)dest_ss)->sin_addr; p.timestamp = time(NULL); DEBUG(4,("send_mailslot: Sending to mailslot %s from %s ", mailslot, nmb_namestr(&dgram->source_name))); print_sockaddr(addr, sizeof(addr), dest_ss); DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), addr)); return NT_STATUS_IS_OK(messaging_send_buf(msg_ctx, pid_to_procid(nmbd_pid), MSG_SEND_PACKET, (uint8 *)&p, sizeof(p))); }
static void process(void) { BOOL run_election; BOOL no_subnets; while( True ) { time_t t = time(NULL); /* Check for internal messages */ message_dispatch(); /* * Check all broadcast subnets to see if * we need to run an election on any of them. * (nmbd_elections.c) */ run_election = check_elections(); /* * Read incoming UDP packets. * (nmbd_packets.c) */ if(listen_for_packets(run_election)) return; /* * Handle termination inband. */ if (got_sig_term) { got_sig_term = 0; terminate(); } /* * Process all incoming packets * read above. This calls the success and * failure functions registered when response * packets arrrive, and also deals with request * packets from other sources. * (nmbd_packets.c) */ run_packet_queue(); /* * Run any elections - initiate becoming * a local master browser if we have won. * (nmbd_elections.c) */ run_elections(t); /* * Send out any broadcast announcements * of our server names. This also announces * the workgroup name if we are a local * master browser. * (nmbd_sendannounce.c) */ announce_my_server_names(t); /* * Send out any LanMan broadcast announcements * of our server names. * (nmbd_sendannounce.c) */ announce_my_lm_server_names(t); /* * If we are a local master browser, periodically * announce ourselves to the domain master browser. * This also deals with syncronising the domain master * browser server lists with ourselves as a local * master browser. * (nmbd_sendannounce.c) */ announce_myself_to_domain_master_browser(t); /* * Fullfill any remote announce requests. * (nmbd_sendannounce.c) */ announce_remote(t); /* * Fullfill any remote browse sync announce requests. * (nmbd_sendannounce.c) */ browse_sync_remote(t); /* * Scan the broadcast subnets, and WINS client * namelists and refresh any that need refreshing. * (nmbd_mynames.c) */ refresh_my_names(t); /* * Scan the subnet namelists and server lists and * expire thos that have timed out. * (nmbd.c) */ expire_names_and_servers(t); /* * Write out a snapshot of our current browse list into * the browse.dat file. This is used by smbd to service * incoming NetServerEnum calls - used to synchronise * browse lists over subnets. * (nmbd_serverlistdb.c) */ write_browse_list(t, False); /* * If we are a domain master browser, we have a list of * local master browsers we should synchronise browse * lists with (these are added by an incoming local * master browser announcement packet). Expire any of * these that are no longer current, and pull the server * lists from each of these known local master browsers. * (nmbd_browsesync.c) */ dmb_expire_and_sync_browser_lists(t); /* * Check that there is a local master browser for our * workgroup for all our broadcast subnets. If one * is not found, start an election (which we ourselves * may or may not participate in, depending on the * setting of the 'local master' parameter. * (nmbd_elections.c) */ check_master_browser_exists(t); /* * If we are configured as a logon server, attempt to * register the special NetBIOS names to become such * (WORKGROUP<1c> name) on all broadcast subnets and * with the WINS server (if used). If we are configured * to become a domain master browser, attempt to register * the special NetBIOS name (WORKGROUP<1b> name) to * become such. * (nmbd_become_dmb.c) */ add_domain_names(t); /* * If we are a WINS server, do any timer dependent * processing required. * (nmbd_winsserver.c) */ initiate_wins_processing(t); /* * If we are a domain master browser, attempt to contact the * WINS server to get a list of all known WORKGROUPS/DOMAINS. * This will only work to a Samba WINS server. * (nmbd_browsesync.c) */ if (lp_enhanced_browsing()) collect_all_workgroup_names_from_wins_server(t); /* * Go through the response record queue and time out or re-transmit * and expired entries. * (nmbd_packets.c) */ retransmit_or_expire_response_records(t); /* * check to see if any remote browse sync child processes have completed */ sync_check_completion(); /* * regularly sync with any other DMBs we know about */ if (lp_enhanced_browsing()) sync_all_dmbs(t); /* * clear the unexpected packet queue */ clear_unexpected(t); /* * Reload the services file if we got a sighup. */ if(reload_after_sighup) { DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, pid_to_procid(0), (void*) &no_subnets, 0, NULL); if(no_subnets) return; reload_after_sighup = 0; } /* check for new network interfaces */ if(reload_interfaces(t)) return; /* free up temp memory */ lp_TALLOC_FREE(); } }
/* show the current server status */ void status_page(void) { const char *v; int autorefresh=0; int refresh_interval=30; int nr_running=0; bool waitup = False; TALLOC_CTX *ctx = talloc_stackframe(); const char form_name[] = "status"; smbd_pid = pid_to_procid(pidfile_pid("smbd")); if (!verify_xsrf_token(form_name)) { goto output_page; } if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) { stop_smbd(); start_smbd(); waitup=True; } if (cgi_variable("smbd_start") || cgi_variable("all_start")) { start_smbd(); waitup=True; } if (cgi_variable("smbd_stop") || cgi_variable("all_stop")) { stop_smbd(); waitup=True; } if (cgi_variable("nmbd_restart") || cgi_variable("all_restart")) { stop_nmbd(); start_nmbd(); waitup=True; } if (cgi_variable("nmbd_start") || cgi_variable("all_start")) { start_nmbd(); waitup=True; } if (cgi_variable("nmbd_stop")|| cgi_variable("all_stop")) { stop_nmbd(); waitup=True; } #ifdef WITH_WINBIND if (cgi_variable("winbindd_restart") || cgi_variable("all_restart")) { stop_winbindd(); start_winbindd(); waitup=True; } if (cgi_variable("winbindd_start") || cgi_variable("all_start")) { start_winbindd(); waitup=True; } if (cgi_variable("winbindd_stop") || cgi_variable("all_stop")) { stop_winbindd(); waitup=True; } #endif /* wait for daemons to start/stop */ if (waitup) sleep(SLEEP_TIME); if (cgi_variable("autorefresh")) { autorefresh = 1; } else if (cgi_variable("norefresh")) { autorefresh = 0; } else if (cgi_variable("refresh")) { autorefresh = 1; } if ((v=cgi_variable("refresh_interval"))) { refresh_interval = atoi(v); } if (cgi_variable("show_client_in_col_1")) { PID_or_Machine = 1; } if (cgi_variable("show_pid_in_col_1")) { PID_or_Machine = 0; } connections_forall_read(traverse_fn1, NULL); initPid2Machine (); output_page: printf("<H2>%s</H2>\n", _("Server Status")); printf("<FORM method=post>\n"); print_xsrf_token(cgi_user_name(), cgi_user_pass(), form_name); if (!autorefresh) { printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh")); printf("<br>%s", _("Refresh Interval: ")); printf("<input type=text size=2 name=\"refresh_interval\" value=\"%d\">\n", refresh_interval); } else { printf("<input type=submit value=\"%s\" name=\"norefresh\">\n", _("Stop Refreshing")); printf("<br>%s%d\n", _("Refresh Interval: "), refresh_interval); printf("<input type=hidden name=\"refresh\" value=\"1\">\n"); } printf("<p>\n"); printf("<table>\n"); printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), samba_version_string()); fflush(stdout); printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (smbd_running()) { nr_running++; printf("<td><input type=submit name=\"smbd_stop\" value=\"%s\"></td>\n", _("Stop smbd")); } else { printf("<td><input type=submit name=\"smbd_start\" value=\"%s\"></td>\n", _("Start smbd")); } printf("<td><input type=submit name=\"smbd_restart\" value=\"%s\"></td>\n", _("Restart smbd")); } printf("</tr>\n"); fflush(stdout); printf("<tr><td>%s</td><td>%s</td>\n", _("nmbd:"), nmbd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (nmbd_running()) { nr_running++; printf("<td><input type=submit name=\"nmbd_stop\" value=\"%s\"></td>\n", _("Stop nmbd")); } else { printf("<td><input type=submit name=\"nmbd_start\" value=\"%s\"></td>\n", _("Start nmbd")); } printf("<td><input type=submit name=\"nmbd_restart\" value=\"%s\"></td>\n", _("Restart nmbd")); } printf("</tr>\n"); #ifdef WITH_WINBIND fflush(stdout); printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running")); if (geteuid() == 0) { if (winbindd_running()) { nr_running++; printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd")); } else { printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd")); } printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd")); } printf("</tr>\n"); #endif if (geteuid() == 0) { printf("<tr><td></td><td></td>\n"); if (nr_running >= 1) { /* stop, restart all */ printf("<td><input type=submit name=\"all_stop\" value=\"%s\"></td>\n", _("Stop All")); printf("<td><input type=submit name=\"all_restart\" value=\"%s\"></td>\n", _("Restart All")); } else if (nr_running == 0) { /* start all */ printf("<td><input type=submit name=\"all_start\" value=\"%s\"></td>\n", _("Start All")); } printf("</tr>\n"); } printf("</table>\n"); fflush(stdout); printf("<p><h3>%s</h3>\n", _("Active Connections")); printf("<table border=1>\n"); printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th>\n", _("PID"), _("Client"), _("IP address"), _("Date")); if (geteuid() == 0) { printf("<th>%s</th>\n", _("Kill")); } printf("</tr>\n"); connections_forall_read(traverse_fn2, NULL); printf("</table><p>\n"); printf("<p><h3>%s</h3>\n", _("Active Shares")); printf("<table border=1>\n"); printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n", _("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date")); connections_forall_read(traverse_fn3, NULL); printf("</table><p>\n"); printf("<h3>%s</h3>\n", _("Open Files")); printf("<table border=1>\n"); printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("Share"), _("File"), _("Date")); locking_init_readonly(); share_mode_forall(print_share_mode, NULL); locking_end(); printf("</table>\n"); printf("<br><input type=submit name=\"show_client_in_col_1\" value=\"%s\">\n", _("Show Client in col 1")); printf("<input type=submit name=\"show_pid_in_col_1\" value=\"%s\">\n", _("Show PID in col 1")); printf("</FORM>\n"); if (autorefresh) { /* this little JavaScript allows for automatic refresh of the page. There are other methods but this seems to be the best alternative */ printf("<script language=\"JavaScript\">\n"); printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n", cgi_baseurl(), refresh_interval, refresh_interval*1000); printf("//-->\n</script>\n"); } TALLOC_FREE(ctx); }
int main(int argc, char *argv[]) { struct tevent_context *evt_ctx; struct messaging_context *msg_ctx; pid_t pid; int i, n; char buf[12]; int ret; TALLOC_CTX *frame = talloc_stackframe(); load_case_tables(); setup_logging(argv[0], DEBUG_STDOUT); lp_load_global(get_dyn_CONFIGFILE()); if (!(evt_ctx = samba_tevent_context_init(NULL)) || !(msg_ctx = messaging_init(NULL, evt_ctx))) { fprintf(stderr, "could not init messaging context\n"); TALLOC_FREE(frame); exit(1); } if (argc != 3) { fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]); TALLOC_FREE(frame); exit(1); } pid = atoi(argv[1]); n = atoi(argv[2]); messaging_register(msg_ctx, NULL, MSG_PONG, pong_message); for (i=0;i<n;i++) { messaging_send(msg_ctx, pid_to_procid(pid), MSG_PING, &data_blob_null); } while (pong_count < i) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } /* Ensure all messages get through to ourselves. */ pong_count = 0; strlcpy(buf, "1234567890", sizeof(buf)); for (i=0;i<n;i++) { messaging_send(msg_ctx, messaging_server_id(msg_ctx), MSG_PING, &data_blob_null); messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx), MSG_PING,(uint8 *)buf, 11); } /* * We have to loop at least 2 times for * each message as local ping messages are * handled by an immediate callback, that * has to be dispatched, which sends a pong * message, which also has to be dispatched. * Above we sent 2*n messages, which means * we have to dispatch 4*n times. */ while (pong_count < n*2) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } if (pong_count != 2*n) { fprintf(stderr, "Message count failed (%d).\n", pong_count); } /* Speed testing */ pong_count = 0; { struct timeval tv = timeval_current(); size_t timelimit = n; size_t ping_count = 0; printf("Sending pings for %d seconds\n", (int)timelimit); while (timeval_elapsed(&tv) < timelimit) { if(NT_STATUS_IS_OK(messaging_send_buf( msg_ctx, pid_to_procid(pid), MSG_PING, (uint8 *)buf, 11))) ping_count++; if(NT_STATUS_IS_OK(messaging_send( msg_ctx, pid_to_procid(pid), MSG_PING, &data_blob_null))) ping_count++; while (ping_count > pong_count + 20) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } } printf("waiting for %d remaining replies (done %d)\n", (int)(ping_count - pong_count), pong_count); while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } if (ping_count != pong_count) { fprintf(stderr, "ping test failed! received %d, sent " "%d\n", pong_count, (int)ping_count); } printf("ping rate of %.0f messages/sec\n", (ping_count+pong_count)/timeval_elapsed(&tv)); } TALLOC_FREE(frame); return (0); }
int main(int argc, char *argv[]) { struct tevent_context *evt_ctx; struct messaging_context *msg_ctx; pid_t pid; int i, n; char buf[12]; int ret; load_case_tables(); setup_logging(argv[0], DEBUG_STDOUT); lp_load(get_dyn_CONFIGFILE(),False,False,False,True); if (!(evt_ctx = tevent_context_init(NULL)) || !(msg_ctx = messaging_init(NULL, procid_self(), evt_ctx))) { fprintf(stderr, "could not init messaging context\n"); exit(1); } if (argc != 3) { fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], argv[0]); exit(1); } pid = atoi(argv[1]); n = atoi(argv[2]); messaging_register(msg_ctx, NULL, MSG_PONG, pong_message); for (i=0;i<n;i++) { messaging_send(msg_ctx, pid_to_procid(pid), MSG_PING, &data_blob_null); } while (pong_count < i) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } /* Now test that the duplicate filtering code works. */ pong_count = 0; strlcpy(buf, "1234567890", sizeof(buf)); for (i=0;i<n;i++) { messaging_send(msg_ctx, messaging_server_id(msg_ctx), MSG_PING, &data_blob_null); messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx), MSG_PING,(uint8 *)buf, 11); } for (i=0;i<n;i++) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } if (pong_count != 2) { fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count); } /* Speed testing */ pong_count = 0; { struct timeval tv = timeval_current(); size_t timelimit = n; size_t ping_count = 0; printf("Sending pings for %d seconds\n", (int)timelimit); while (timeval_elapsed(&tv) < timelimit) { if(NT_STATUS_IS_OK(messaging_send_buf( msg_ctx, pid_to_procid(pid), MSG_PING, (uint8 *)buf, 11))) ping_count++; if(NT_STATUS_IS_OK(messaging_send( msg_ctx, pid_to_procid(pid), MSG_PING, &data_blob_null))) ping_count++; while (ping_count > pong_count + 20) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } } printf("waiting for %d remaining replies (done %d)\n", (int)(ping_count - pong_count), pong_count); while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) { ret = tevent_loop_once(evt_ctx); if (ret != 0) { break; } } if (ping_count != pong_count) { fprintf(stderr, "ping test failed! received %d, sent " "%d\n", pong_count, (int)ping_count); } printf("ping rate of %.0f messages/sec\n", (ping_count+pong_count)/timeval_elapsed(&tv)); } return (0); }
static void print_notify_send_messages_to_printer(struct messaging_context *msg_ctx, const char *printer, unsigned int timeout) { char *buf; struct notify_queue *pq, *pq_next; size_t msg_count = 0, offset = 0; size_t num_pids = 0; size_t i; pid_t *pid_list = NULL; struct timeval end_time = timeval_zero(); /* Count the space needed to send the messages. */ for (pq = notify_queue_head; pq; pq = pq->next) { if (strequal(printer, pq->msg->printer)) { if (!flatten_message(pq)) { DEBUG(0,("print_notify_send_messages: Out of memory\n")); talloc_free_children(send_ctx); num_messages = 0; return; } offset += (pq->buflen + 4); msg_count++; } } offset += 4; /* For count. */ buf = (char *)TALLOC(send_ctx, offset); if (!buf) { DEBUG(0,("print_notify_send_messages: Out of memory\n")); talloc_free_children(send_ctx); num_messages = 0; return; } offset = 0; SIVAL(buf,offset,msg_count); offset += 4; for (pq = notify_queue_head; pq; pq = pq_next) { pq_next = pq->next; if (strequal(printer, pq->msg->printer)) { SIVAL(buf,offset,pq->buflen); offset += 4; memcpy(buf + offset, pq->buf, pq->buflen); offset += pq->buflen; /* Remove from list. */ DLIST_REMOVE(notify_queue_head, pq); } } DEBUG(5, ("print_notify_send_messages_to_printer: sending %lu print notify message%s to printer %s\n", (unsigned long)msg_count, msg_count != 1 ? "s" : "", printer)); /* * Get the list of PID's to send to. */ if (!print_notify_pid_list(printer, send_ctx, &num_pids, &pid_list)) return; if (timeout != 0) { end_time = timeval_current_ofs(timeout, 0); } for (i = 0; i < num_pids; i++) { messaging_send_buf(msg_ctx, pid_to_procid(pid_list[i]), MSG_PRINTER_NOTIFY2 | MSG_FLAG_LOWPRIORITY, (uint8 *)buf, offset); if ((timeout != 0) && timeval_expired(&end_time)) { break; } } }