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, QUERY_VERSION, 0)
113 if ((status = mr_auth(program_name)))
115 if (status == MR_USER_AUTH)
118 com_err(program_name, status, "\nPress [RETURN] to continue");
119 fgets(buf, BUFSIZ, stdin);
123 if (status >= ERROR_TABLE_BASE_krb &&
124 status <= ERROR_TABLE_BASE_krb + 256)
125 ErrorExit("\nAuthorization failed -- please run kinit", status);
127 ErrorExit("\nAuthorization failed.", status);
132 * These signals should not be set until just before we fire up the menu
137 if (!strcmp(program_name, "listmaint"))
139 else if (!strcmp(program_name, "usermaint"))
141 else if (!strcmp(program_name, "dcmmaint"))
144 menu = &moira_top_menu;
147 if (use_menu) /* Start menus that execute program */
153 else /* Start program without menus. */
161 /* Function Name: ErrorExit
162 * Description: This function does the error handling and exits.
163 * Arguments: buf - the error message to print.
164 * status - the error code.
165 * Returns: doesn't return.
168 static void ErrorExit(char *buf, int status)
170 com_err(program_name, status, buf);
175 /* Function Name: usage
176 * Description: Prints usage info and then exits.
178 * Returns: doesn't return.
181 static void Usage(void)
183 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
188 /* Function Name: Signal_Handler
189 * Description: This function cleans up from a signal interrupt.
194 static void Signal_Handler(int sig)
196 Put_message("Signal caught - exiting");
206 static void CatchInterrupt(int sig)
208 Put_message("Interrupt! Press RETURN to continue");
212 #ifdef HAVE_POSIX_SIGNALS
213 static void SetHandlers(void)
215 struct sigaction act;
217 sigemptyset(&act.sa_mask);
219 act.sa_handler = Signal_Handler;
220 sigaction(SIGHUP, &act, NULL);
221 sigaction(SIGQUIT, &act, NULL);
224 sigaction(SIGINT, &act, NULL);
228 act.sa_handler = CatchInterrupt;
229 sigaction(SIGINT, &act, NULL);
233 static void SetHandlers(void)
235 signal(SIGTERM, Signal_Handler);
238 signal(SIGINT, Signal_Handler);
241 signal(SIGINT, CatchInterrupt);