From 3c590c051a74b9b7ed779378e8ab510eb3dc525b Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 29 Sep 2000 17:54:39 +0000 Subject: [PATCH] quick hack to add interactive mode so you get a prompt and can enter multiple commands. We still need a manpage on this. If nobody else wants to do it, I'll do one over the weekend. --- source/utils/smbcontrol.c | 111 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 29 deletions(-) diff --git a/source/utils/smbcontrol.c b/source/utils/smbcontrol.c index b31b53473c4..cedb13620d5 100644 --- a/source/utils/smbcontrol.c +++ b/source/utils/smbcontrol.c @@ -33,15 +33,20 @@ static struct { {NULL, -1} }; -static void usage(void) +static void usage(BOOL doexit) { int i; - printf("Usage: smbcontrol \n\n"); + if (doexit) { + printf("Usage: smbcontrol -i\n"); + printf(" smbcontrol \n\n"); + } else { + printf(" \n\n"); + } printf("\t is one of \"nmbd\", \"smbd\" or a process ID\n"); printf("\t is one of: "); for (i=0; msg_types[i].name; i++) printf("%s, ", msg_types[i].name); printf("\n"); - exit(1); + if (doexit) exit(1); } static int pong_count; @@ -94,54 +99,45 @@ static int parse_type(char *mtype) } - int main(int argc, char *argv[]) +/**************************************************************************** +do command +****************************************************************************/ +static BOOL do_command(char *dest, char *msg_name, char *params) { - char *dest; int i, n, v; - pstring servicesf = CONFIGFILE; int mtype; - TimeInit(); - setup_logging(argv[0],True); - - charset_initialise(); - lp_load(servicesf,False,False,False); - - message_init(); - - if (argc < 3) usage(); - - dest = argv[1]; - mtype = parse_type(argv[2]); + mtype = parse_type(msg_name); if (mtype == -1) { - fprintf(stderr,"Couldn't resolve message type: %s\n", argv[2]); - exit(1); + fprintf(stderr,"Couldn't resolve message type: %s\n", msg_name); + return(False); } - argc -= 2; - argv += 2; - switch (mtype) { case MSG_DEBUG: - if (argc < 2) { + if (!params) { fprintf(stderr,"MSG_DEBUG needs a parameter\n"); - exit(1); + return(False); } - v = atoi(argv[1]); + v = atoi(params); send_message(dest, MSG_DEBUG, &v, sizeof(int)); break; case MSG_FORCE_ELECTION: if (!strequal(dest, "nmbd")) { fprintf(stderr,"force-election can only be sent to nmbd\n"); - exit(1); + return(False); } send_message(dest, MSG_FORCE_ELECTION, NULL, 0); break; case MSG_PING: message_register(MSG_PONG, pong_function); - n = atoi(argv[1]); + if (!params) { + fprintf(stderr,"MSG_PING needs a parameter\n"); + return(False); + } + n = atoi(params); for (i=0;i 2 ? argv[2] : 0)); + } + + while (True) { + char *myargv[3]; + int myargc; + + printf("smbcontrol> "); + if (!gets(temp)) break; + myargc = 0; + while ((myargc < 3) && + (myargv[myargc] = strtok(myargc?NULL:temp," \t"))) { + myargc++; + } + if (!myargc) break; + if (myargc < 2) + usage(False); + else if (!do_command(myargv[0],myargv[1],myargc > 2 ? myargv[2] : 0)) + usage(False); + } + return(0); } -- 2.11.4.GIT