dpm-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: dpm-mgmt_main.c 358766 2010-01-20 16:37:38Z jamesk $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 /* The Application and This Daemon's Documentation: */
00022 
00382 #include <sync/common.h>
00383 #include <jnx/pmon.h>
00384 #include "dpm-mgmt_main.h"
00385 #include "dpm-mgmt_config.h"
00386 #include "dpm-mgmt_conn.h"
00387 #include "dpm-mgmt_kcom.h"
00388 #include "dpm-mgmt_logging.h"
00389 
00390 #include DPM_SEQUENCE_H
00391 
00392 /*** Constants ***/
00393 
00397 #define DNAME_DPM_MGMT    "dpm-mgmt"
00398 
00399 
00403 #define PMON_HB_INTERVAL   30
00404 
00405 
00406 /*** Data Structures ***/
00407 
00412 extern const parse_menu_t master_menu[];
00413 
00417 extern const char * dpm_config[];
00418 
00419 static junos_pmon_context_t pmon; 
00420 
00421 /*** STATIC/INTERNAL Functions ***/
00422 
00423 
00430 static void
00431 dpm_sigterm(int signal_ign __unused)
00432 {
00433     dpm_shutdown(TRUE);
00434 }
00435 
00445 static int
00446 dpm_init (evContext ctx)
00447 {
00448     struct timespec interval;
00449     
00450     pmon = NULL;
00451     
00452     junos_sig_register(SIGTERM, dpm_sigterm);
00453 
00454     init_config();
00455     
00456     if(kcom_init(ctx) != KCOM_OK) {
00457         goto init_fail;
00458     }
00459     
00460     if((pmon = junos_pmon_create_context()) == PMON_CONTEXT_INVALID) {
00461         LOG(LOG_ERR, "%s: health monitoring: initialization failed", __func__);
00462         goto init_fail;
00463     }
00464 
00465     if(junos_pmon_set_event_context(pmon, ctx)) {
00466         LOG(LOG_ERR, "%s: health monitoring: setup failed", __func__);
00467         goto init_fail;
00468     }
00469     
00470     if(junos_pmon_select_backend(pmon, PMON_BACKEND_LOCAL, NULL)) {
00471         LOG(LOG_ERR, "%s: health monitoring: select backend failed", __func__);
00472         goto init_fail;
00473     }
00474     
00475     interval.tv_sec = PMON_HB_INTERVAL;
00476     interval.tv_nsec = 0;
00477     
00478     if(junos_pmon_heartbeat(pmon, &interval, 0)) {
00479         LOG(LOG_ERR, "health monitoring: setup heartbeat failed");
00480         goto init_fail;
00481     }
00482     
00483     if(init_conn_server(ctx)) {
00484         goto init_fail;
00485     }
00486     
00487     return SUCCESS;
00488     
00489 init_fail:
00490 
00491     LOG(LOG_CRIT, "initialization failed");
00492     kcom_shutdown();
00493     clear_config();
00494     shutdown_conn_server();
00495     if(pmon) {
00496         junos_pmon_destroy_context(&pmon);
00497     }
00498     
00499     return EFAIL;
00500 }
00501 
00502 
00503 /*** GLOBAL/EXTERNAL Functions ***/
00504 
00511 void
00512 dpm_shutdown(boolean do_exit)
00513 {
00514     kcom_shutdown();
00515     clear_config();
00516     shutdown_conn_server();
00517     junos_pmon_destroy_context(&pmon);
00518     
00519     if(do_exit) {
00520         LOG(TRACE_LOG_INFO, "dpm-mgmt shutting down");
00521         exit(0);
00522     }
00523 }
00524 
00525 
00538 int
00539 main (int argc, char **argv)
00540 {
00541     int ret = 0;
00542     junos_sdk_app_ctx_t ctx;
00543     
00544     // create an application context
00545     ctx = junos_create_app_ctx(argc, argv, DNAME_DPM_MGMT,
00546                  master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00547     if (ctx == NULL) {
00548         return -1;
00549     }
00550 
00551     // set config read call back
00552     ret = junos_set_app_cb_config_read(ctx, dpm_config_read);
00553     if (ret < 0) {
00554         junos_destroy_app_ctx(ctx); 
00555         return ret;
00556     }
00557 
00558     // set init call back
00559     ret = junos_set_app_cb_init(ctx, dpm_init);
00560     if (ret < 0) {
00561         junos_destroy_app_ctx(ctx); 
00562         return ret;
00563     }
00564     
00565     // set trace options DDL path
00566     ret = junos_set_app_cfg_trace_path(ctx, dpm_config);
00567     if (ret < 0) {
00568         junos_destroy_app_ctx(ctx);
00569         return ret;
00570     }
00571 
00572     // now just call the great junos_app_init
00573     ret = junos_app_init(ctx);
00574 
00575     // should not come here unless daemon exiting or init failed,
00576     // destroy context
00577     junos_destroy_app_ctx(ctx);
00578     return ret;
00579 }

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:55 2010 for SDK Your Net Corporation Dynamic Policy Manager Example: dpm-mgmt 1.0 by Doxygen 1.5.1