2 Unix SMB/Netbios implementation.
4 program to send control messages to Samba processes
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 {"force-election", MSG_FORCE_ELECTION},
36 static void usage(void)
39 printf("Usage: smbcontrol <destination> <message-type> <parameters>\n\n");
40 printf("\t<destination> is one of \"nmbd\", \"smbd\" or a process ID\n");
41 printf("\t<message-type> is one of: ");
42 for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name);
47 static int pong_count;
49 /****************************************************************************
50 a useful function for testing the message system
51 ****************************************************************************/
52 void pong_function(int msg_type, pid_t src, void *buf, size_t len)
57 /****************************************************************************
58 send a message to a named destination
59 ****************************************************************************/
60 static BOOL send_message(char *dest, int msg_type, void *buf, int len)
64 /* "smbd" is the only broadcast operation */
65 if (strequal(dest,"smbd")) {
66 return message_send_all(msg_type, buf, len);
67 } else if (strequal(dest,"nmbd")) {
68 pid = pidfile_pid(dest);
70 fprintf(stderr,"Can't find pid for nmbd\n");
76 fprintf(stderr,"Not a valid pid\n");
81 return message_send_pid(pid, msg_type, buf, len);
84 /****************************************************************************
85 evaluate a message type string
86 ****************************************************************************/
87 static int parse_type(char *mtype)
90 for (i=0;msg_types[i].name;i++) {
91 if (strequal(mtype, msg_types[i].name)) return msg_types[i].value;
97 int main(int argc, char *argv[])
101 pstring servicesf = CONFIGFILE;
105 setup_logging(argv[0],True);
107 charset_initialise();
108 lp_load(servicesf,False,False,False);
112 if (argc < 3) usage();
115 mtype = parse_type(argv[2]);
117 fprintf(stderr,"Couldn't resolve message type: %s\n", argv[2]);
127 fprintf(stderr,"MSG_DEBUG needs a parameter\n");
131 send_message(dest, MSG_DEBUG, &v, sizeof(int));
134 case MSG_FORCE_ELECTION:
135 if (!strequal(dest, "nmbd")) {
136 fprintf(stderr,"force-election can only be sent to nmbd\n");
139 send_message(dest, MSG_FORCE_ELECTION, NULL, 0);
143 message_register(MSG_PONG, pong_function);
146 send_message(dest, MSG_PING, NULL, 0);
148 while (pong_count < n) message_dispatch();