monitube-data_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube-data_main.c 346460 2009-11-14 05:06:47Z ssiano $
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 
00903 #include "monitube-data_main.h"
00904 #include "monitube-data_config.h"
00905 #include "monitube-data_conn.h"
00906 #include "monitube-data_ha.h"
00907 #include "monitube-data_packet.h"
00908 #include <jnx/radix.h>
00909 #include <unistd.h>
00910 
00911 /*** Constants ***/
00912 
00916 #define DNAME_MONITUBE_DATA    "monitube-data"
00917 
00918 /*** Data Structures ***/
00919 
00920 static evContext mainctx; 
00921 static uint8_t init_conf; 
00922 
00923 /*** STATIC/INTERNAL Functions ***/
00924 
00925 
00929 static void
00930 monitube_quit(int signo __unused)
00931 {
00932     if(init_conf) {
00933         close_connections();
00934     
00935         stop_replication();
00936     
00937         stop_packet_loops(mainctx);
00938     
00939         clear_config();
00940     
00941         destroy_packet_loops_oc();
00942     }
00943     
00944     msp_exit();
00945 
00946     LOG(LOG_INFO, "Shutting down finished");
00947 
00948     exit(0);
00949 }
00950 
00951 
00960 static int
00961 monitube_init(evContext ctx)
00962 {
00963     int cpu;
00964 
00965     msp_init();
00966 
00967     // Handle some signals that we may receive:
00968     signal(SIGTERM, monitube_quit); // call quit fnc
00969     signal(SIGHUP, SIG_IGN); // ignore
00970     signal(SIGPIPE, SIG_IGN); // ignore
00971 
00972     logging_set_level(LOG_INFO);
00973     logging_set_mode(LOGGING_SYSLOG);
00974 
00975     // call init function for modules:
00976 
00977     mainctx = ctx;
00978     init_conf = 0;
00979 
00980     // find another user cpu number to use for this main thread
00981     cpu = msp_env_get_next_user_cpu(MSP_NEXT_NONE);
00982 
00983     // if at least one valid user cpu available...
00984     if(cpu != MSP_NEXT_END) {
00985 
00986         // else it will be on the same user core as the monitoring thread
00987 
00988         LOG(LOG_INFO, "%s: Binding main process to user cpu %d",
00989                 __func__, cpu);
00990 
00991         if(msp_process_bind(cpu) != SUCCESS) {
00992             LOG(LOG_ALERT, "%s: Failed to initialize. Cannot bind to user cpu. "
00993                     "See error log for details ", __func__);
00994             monitube_quit(0);
00995             return EFAIL;
00996         }
00997 
00998     } else {
00999         LOG(LOG_EMERG, "%s: Main process will not be bound to a user cpu as "
01000             "expected. System cannot run without a user core.", __func__);
01001     }
01002 
01003     init_forwarding_database(ctx);
01004 
01005     return SUCCESS;
01006 }
01007 
01008 
01009 /*** GLOBAL/EXTERNAL Functions ***/
01010 
01011 
01018 void
01019 init_application(void)
01020 {
01021     int rc;
01022 
01023     rc = init_config(mainctx);
01024     if(rc != SUCCESS) {
01025         goto failed;
01026     }
01027 
01028     rc = init_connections(mainctx);
01029     if(rc != SUCCESS) {
01030         goto failed;
01031     }
01032 
01033     rc = init_packet_loops(mainctx);
01034     if(rc != SUCCESS) {
01035         goto failed;
01036     }
01037     
01038     init_conf = 1;
01039 
01040     return;
01041 
01042 failed:
01043 
01044     LOG(LOG_ALERT, "%s: Failed to initialize. "
01045             "See error log for details ", __func__);
01046     monitube_quit(0);
01047 }
01048 
01049 
01050 
01063 int
01064 main(int32_t argc , char **argv)
01065 {
01066     mp_sdk_app_ctx_t app_ctx;
01067     int rc;
01068 
01069     app_ctx = msp_create_app_ctx(argc, argv, DNAME_MONITUBE_DATA);
01070     msp_set_app_cb_init(app_ctx, monitube_init);
01071 
01072     rc = msp_app_init(app_ctx);
01073 
01074     /* Should never reach this point */
01075     msp_destroy_app_ctx(app_ctx);
01076     return rc;
01077 }
01078 

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:27:02 2010 for SDK Your Net Corporation Monitube IPTV Monitoring Example: monitube-data 1.0 by Doxygen 1.5.1