]> andersk Git - moira.git/blob - clients/moira/main.c
030a0c99d5a4a24b5d924a4d980205dede80e1cd
[moira.git] / clients / moira / main.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif lint
4
5 /*      This is the file main.c for the SMS Client, which allows a nieve
6  *      user to quickly and easily maintain most parts of the SMS database.
7  *      It Contains: The main driver for the SMS Client.
8  *      
9  *      Created:        4/12/88
10  *      By:             Chris D. Peterson
11  *
12  *      $Source$
13  *      $Author$
14  *      $Header$
15  *      
16  *      Copyright 1988 by the Massachusetts Institute of Technology.
17  *
18  *      For further information on copyright and distribution 
19  *      see the file mit-copyright.h
20  */
21
22 #include <pwd.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <strings.h>
26 #include <sys/types.h>
27 #include <sms.h>
28 #include <menu.h>
29
30 #include "mit-copyright.h"
31 #include "defs.h"
32 #include "f_defs.h"
33 #include "globals.h"
34
35 char * whoami;                  /* used by menu.c ugh!!! */
36
37 extern Menu sms_top_menu, list_menu, user_menu, dcm_menu;
38
39 #ifndef DEBUG
40 static void SignalHandler();
41 #endif DEBUG
42
43 static void ErrorExit(), Usage();
44 char *getlogin();
45 uid_t getuid();
46 struct passwd *getpwuid();
47
48 Bool use_menu = TRUE;           /* whether or not we are using a menu. */
49
50 /*      Function Name: main
51  *      Description: The main driver for the SMS Client.
52  *      Arguments: argc, argv - standard command line args.
53  *      Returns: doesn't return.
54  */
55
56 void
57 main(argc, argv)
58     int argc;
59     char ** argv;
60 {
61     int status;
62     Menu *menu;
63     char *motd;
64
65     if ((user = getlogin()) == NULL) 
66         user = getpwuid((int) getuid())->pw_name;
67     user = (user && strlen(user)) ? Strsave(user) : "";
68
69     if ((program_name = rindex(argv[0], '/')) == NULL)
70       program_name = argv[0];
71     else
72       program_name++;
73     program_name = Strsave(program_name);
74     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
75
76     verbose = TRUE;
77
78     switch (argc) {
79     case 2:
80       if (strcmp(argv[1], "-nomenu") == 0)
81         use_menu = FALSE;
82       else 
83         Usage();
84       break;
85     case 1:
86       break;
87     default:
88       Usage();
89       break;
90     }
91
92     if ( status = sms_connect(SMS_SERVER) ) 
93         ErrorExit("\nConnection to SMS server failed", status);
94
95     if ( status = sms_motd(&motd) )
96         ErrorExit("\nUnable to check server status", status);
97     if (motd) {
98         fprintf(stderr, "The SMS server is currently unavailable:\n%s\n", motd);
99         sms_disconnect();
100         exit(1);
101     }
102
103     if ( status = sms_auth(program_name) ) 
104         ErrorExit("\nAuthorization failed -- please run kinit", status);
105
106 /*
107  * These signals should not be set until just before we fire up the menu
108  * system. 
109  */
110
111 #ifndef DEBUG
112     (void) signal(SIGHUP, SignalHandler);
113     (void) signal(SIGINT, SignalHandler); 
114     (void) signal(SIGQUIT, SignalHandler);
115 #endif DEBUG
116
117     if (!strcmp(program_name, "listmaint"))
118       menu = &list_menu;
119     else if (!strcmp(program_name, "usermaint"))
120       menu = &user_menu;
121     else if (!strcmp(program_name, "dcmmaint"))
122       menu = &dcm_menu;
123     else
124       menu = &sms_top_menu;
125
126     if (use_menu) {             /* Start menus that execute program */
127         Start_paging();
128         Start_menu(menu);
129         Stop_paging();
130     }
131     else                        /* Start program without menus. */
132         Start_no_menu(menu);
133
134     sms_disconnect();
135     exit(0);
136 }
137
138 /*      Function Name: ErrorExit
139  *      Description: This function does the error handling and exits.
140  *      Arguments: buf - the error message to print.
141  *                 status - the error code.
142  *      Returns: doesn't return.
143  */
144
145 static void
146 ErrorExit(buf,status)
147 int status;
148 char * buf;    
149 {
150     com_err(program_name, status, buf);
151     sms_disconnect();
152     exit(1);
153 }
154
155 /*      Function Name: usage
156  *      Description: Prints usage info and then exits.
157  *      Arguments: none
158  *      Returns: doesn't return.
159  */
160
161 static void
162 Usage()
163 {
164     fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
165     exit(1);
166 }
167
168 #ifndef DEBUG
169 /*      Function Name: SignalHandler
170  *      Description: This function cleans up from a signal interrupt.
171  *      Arguments: none.
172  *      Returns: doesn't
173  */
174
175 static void
176 SignalHandler()
177 {
178     Put_message("Signal caught - exiting");
179     if (use_menu)
180       Cleanup_menu();
181     sms_disconnect();
182     exit(1);
183 }
184 #endif DEBUG
This page took 0.047171 seconds and 3 git commands to generate.