3 * This is the file main.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: The main driver for the Moira Client.
8 * By: Chris D. Peterson
10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
27 #endif /* HAVE_UNISTD_H */
31 static void ErrorExit(char *buf, int status);
32 static void Usage(void);
33 static void Signal_Handler(int sig);
34 static void CatchInterrupt(int sig);
35 static void SetHandlers(void);
37 char *whoami; /* used by menu.c ugh!!! */
41 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
44 Bool use_menu = TRUE; /* whether or not we are using a menu. */
47 /* Function Name: main
48 * Description: The main driver for the Moira Client.
49 * Arguments: argc, argv - standard command line args.
50 * Returns: doesn't return.
53 int main(int argc, char **argv)
59 if (!(program_name = strrchr(argv[0], '/')))
60 program_name = argv[0];
63 program_name = strdup(program_name);
64 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
66 user = mrcl_krb_user();
74 while (++arg - argv < argc)
78 if (!strcmp(*arg, "-nomenu"))
86 else if (!strcmp(*arg, "-menu"))
91 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
95 else if (!strcmp(*arg, "-db"))
97 if (arg - argv < argc - 1)
109 if (mrcl_connect(moira_server, program_name, 2, 0) != MRCL_SUCCESS)
112 if ((status = mr_auth(program_name)))
114 if (status == MR_USER_AUTH)
117 com_err(program_name, status, "\nPress [RETURN] to continue");
118 fgets(buf, BUFSIZ, stdin);
122 if (status >= ERROR_TABLE_BASE_krb &&
123 status <= ERROR_TABLE_BASE_krb + 256)
124 ErrorExit("\nAuthorization failed -- please run kinit", status);
126 ErrorExit("\nAuthorization failed.", status);
131 * These signals should not be set until just before we fire up the menu
136 if (!strcmp(program_name, "listmaint"))
138 else if (!strcmp(program_name, "usermaint"))
140 else if (!strcmp(program_name, "dcmmaint"))
143 menu = &moira_top_menu;
146 if (use_menu) /* Start menus that execute program */
152 else /* Start program without menus. */
160 /* Function Name: ErrorExit
161 * Description: This function does the error handling and exits.
162 * Arguments: buf - the error message to print.
163 * status - the error code.
164 * Returns: doesn't return.
167 static void ErrorExit(char *buf, int status)
169 com_err(program_name, status, buf);
174 /* Function Name: usage
175 * Description: Prints usage info and then exits.
177 * Returns: doesn't return.
180 static void Usage(void)
182 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
187 /* Function Name: Signal_Handler
188 * Description: This function cleans up from a signal interrupt.
193 static void Signal_Handler(int sig)
195 Put_message("Signal caught - exiting");
205 static void CatchInterrupt(int sig)
207 Put_message("Interrupt! Press RETURN to continue");
211 #ifdef HAVE_POSIX_SIGNALS
212 static void SetHandlers(void)
214 struct sigaction act;
216 sigemptyset(&act.sa_mask);
218 act.sa_handler = Signal_Handler;
219 sigaction(SIGHUP, &act, NULL);
220 sigaction(SIGQUIT, &act, NULL);
223 sigaction(SIGINT, &act, NULL);
227 act.sa_handler = CatchInterrupt;
228 sigaction(SIGINT, &act, NULL);
232 static void SetHandlers(void)
234 signal(SIGTERM, Signal_Handler);
237 signal(SIGINT, Signal_Handler);
240 signal(SIGINT, CatchInterrupt);