comparison freeDiameterd/main.c @ 1412:4768e3bf1c9b

freeDiameter: use standard exit codes Exit with EXIT_FAILURE (1) on any error, and EXIT_SUCCESS (0) if ok
author Luke Mewburn <luke@mewburn.net>
date Tue, 18 Feb 2020 17:21:20 +1100
parents a4fce08e49e4
children 32f158d0d859
comparison
equal deleted inserted replaced
1411:a4fce08e49e4 1412:4768e3bf1c9b
152 ASSERT(ret == 0); 152 ASSERT(ret == 0);
153 153
154 /* Parse the command-line */ 154 /* Parse the command-line */
155 ret = main_cmdline(argc, argv); 155 ret = main_cmdline(argc, argv);
156 if (ret != 0) { 156 if (ret != 0) {
157 return ret; 157 return EXIT_FAILURE;
158 } 158 }
159 159
160 if (daemon_mode) { 160 if (daemon_mode) {
161 TRACE_DEBUG(INFO, "entering background mode"); 161 TRACE_DEBUG(INFO, "entering background mode");
162 CHECK_SYS( daemon(1, 0) ); 162 CHECK_SYS_DO( daemon(1, 0), return EXIT_FAILURE );
163 } 163 }
164 164
165 CHECK_FCT( pidfile_create() ); 165 CHECK_FCT_DO( pidfile_create(), return EXIT_FAILURE );
166 166
167 /* Initialize the core library */ 167 /* Initialize the core library */
168 ret = fd_core_initialize(); 168 ret = fd_core_initialize();
169 if (ret != 0) { 169 if (ret != 0) {
170 fprintf(stderr, "An error occurred during freeDiameter core library initialization.\n"); 170 fprintf(stderr, "An error occurred during freeDiameter core library initialization.\n");
171 return ret; 171 return EXIT_FAILURE;
172 } 172 }
173 173
174 /* Set gnutls debug level ? */ 174 /* Set gnutls debug level ? */
175 if (gnutls_debug) { 175 if (gnutls_debug) {
176 gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug); 176 gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
188 CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error ); 188 CHECK_POSIX_DO( pthread_create(&signals_thr, NULL, catch_signals, NULL), goto error );
189 189
190 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized."); 190 TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
191 191
192 /* Now, just wait for termination */ 192 /* Now, just wait for termination */
193 CHECK_FCT( fd_core_wait_shutdown_complete() ); 193 CHECK_FCT_DO( fd_core_wait_shutdown_complete(), return EXIT_FAILURE );
194 194
195 /* Just in case it was not the result of a signal, we cancel signals_thr */ 195 /* Just in case it was not the result of a signal, we cancel signals_thr */
196 fd_thr_term(&signals_thr); 196 fd_thr_term(&signals_thr);
197 197
198 return 0; 198 return EXIT_SUCCESS;
199 error: 199 error:
200 CHECK_FCT_DO( fd_core_shutdown(), ); 200 CHECK_FCT_DO( fd_core_shutdown(), );
201 CHECK_FCT( fd_core_wait_shutdown_complete() ); 201 CHECK_FCT_DO( fd_core_wait_shutdown_complete(), return EXIT_FAILURE );
202 fd_thr_term(&signals_thr); 202 fd_thr_term(&signals_thr);
203 return -1; 203 return EXIT_FAILURE;
204 } 204 }
205 205
206 206
207 /* Display package version */ 207 /* Display package version */
208 static void main_version_core(void) 208 static void main_version_core(void)
274 break; /* Exit from the loop. */ 274 break; /* Exit from the loop. */
275 275
276 switch (c) { 276 switch (c) {
277 case 'h': /* Print help and exit. */ 277 case 'h': /* Print help and exit. */
278 main_help(); 278 main_help();
279 exit(0); 279 exit(EXIT_SUCCESS);
280 280
281 case 'V': /* Print version and exit. */ 281 case 'V': /* Print version and exit. */
282 main_version(); 282 main_version();
283 exit(0); 283 exit(EXIT_SUCCESS);
284 284
285 case 'c': /* Read configuration from this file instead of the default location.. */ 285 case 'c': /* Read configuration from this file instead of the default location.. */
286 if (optarg == NULL ) { 286 if (optarg == NULL ) {
287 fprintf(stderr, "Missing argument with --config directive\n"); 287 fprintf(stderr, "Missing argument with --config directive\n");
288 return EINVAL; 288 return EINVAL;
"Welcome to our mercurial repository"