summaryrefslogtreecommitdiffstats
path: root/src/plugins/sc_plugins.c
diff options
context:
space:
mode:
authorjackiechen1985 <xiaobo.chen@tieto.com>2019-07-03 17:07:56 +0800
committerjackiechen1985 <xiaobo.chen@tieto.com>2019-07-03 17:13:44 +0800
commitadc56bc5ddcdf947864d982cda809588b7ccd8bc (patch)
tree484cb25388b4b5ea2bc6ac66a17026774cb91529 /src/plugins/sc_plugins.c
parentf086b6eec410b18daba34e6a0dd64f46c076bbe7 (diff)
Enable mutil-thread VPP API calling support.
- Lock/Unlock before and after invoke VPP API; - Introduce sc_vpp_main_t for warpping VPP API context, mode and pid; Change-Id: If1b1c040cb4723ecc4e88c5060c0380de7c715c0 Signed-off-by: jackiechen1985 <xiaobo.chen@tieto.com>
Diffstat (limited to 'src/plugins/sc_plugins.c')
-rw-r--r--src/plugins/sc_plugins.c78
1 files changed, 13 insertions, 65 deletions
diff --git a/src/plugins/sc_plugins.c b/src/plugins/sc_plugins.c
index 7fc5975..8ed2c12 100644
--- a/src/plugins/sc_plugins.c
+++ b/src/plugins/sc_plugins.c
@@ -20,67 +20,23 @@
#include <vpp-api/client/stat_client.h>
sc_plugin_main_t sc_plugin_main;
-static int vpp_pid_start;
sc_plugin_main_t *sc_get_plugin_main()
{
return &sc_plugin_main;
}
-/* get vpp pid in system */
-int get_vpp_pid()
-{
- DIR *dir;
- struct dirent *ptr;
- FILE *fp;
- char filepath[50];
- char filetext[20];
-
- dir = opendir("/proc");
- int vpp_pid = 0;
- /* read vpp pid file in proc, return pid of vpp */
- if (NULL != dir)
- {
- while (NULL != (ptr =readdir(dir)))
- {
- if ((0 == strcmp(ptr->d_name, ".")) || (0 == strcmp(ptr->d_name, "..")))
- continue;
-
- if (DT_DIR != ptr->d_type)
- continue;
-
- sprintf(filepath, "/proc/%s/cmdline",ptr->d_name);
- fp = fopen(filepath, "r");
-
- if (NULL != fp)
- {
- fread(filetext, 1, 13, fp);
- filetext[12] = '\0';
-
- if (filetext == strstr(filetext, "/usr/bin/vpp"))
- vpp_pid = atoi(ptr->d_name);
-
- fclose(fp);
- }
- }
- closedir(dir);
- }
- return vpp_pid;
-}
-
-
int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx)
{
- int rc;
+ int rc = SR_ERR_OK;;
sc_plugin_main.session = session;
/* Connect to VAPI */
- rc = sc_connect_vpp();
- if (0 != rc) {
- SRP_LOG_ERR("vpp vapi connect error , with return %d.", rc);
- return SR_ERR_INTERNAL;
- }
+ if (!(sc_plugin_main.vpp_main = sc_connect_vpp())) {
+ SRP_LOG_ERR("VPP connect error: %d", rc);
+ return SR_ERR_INTERNAL;
+ }
/* Connect to STAT API */
rc = stat_segment_connect(STAT_SEGMENT_SOCKET_FILE);
@@ -97,9 +53,8 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx)
/* set subscription as our private context */
*private_ctx = sc_plugin_main.subscription;
- /* get the vpp pid sweetcomb connected, we assumed that only one vpp is run in system */
- vpp_pid_start = get_vpp_pid();
- return SR_ERR_OK;
+
+ return rc;
}
void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx)
@@ -119,18 +74,11 @@ void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx)
SRP_LOG_DBG_MSG("plugin disconnect vpp ok.");
}
-int sr_plugin_health_check_cb(sr_session_ctx_t *session, void *private_ctx)
+int sr_plugin_health_check_cb( __attribute__ ((unused)) sr_session_ctx_t *session,
+ __attribute__ ((unused)) void *private_ctx)
{
- /* health check, will use shell to detect vpp when plugin is loaded */
- /* health_check will run every 10 seconds in loop*/
- int vpp_pid_now = get_vpp_pid();
-
- if(vpp_pid_now == vpp_pid_start)
- {
- return SR_ERR_OK;
- }
- else
- {
- return -1;
- }
+ /* health check, will use shell to detect vpp when plugin is loaded */
+ /* health_check will run every 10 seconds in loop*/
+ pid_t pid = sc_get_vpp_pid();
+ return sc_plugin_main.vpp_main->pid == pid && pid != 0 ? SR_ERR_OK : SR_ERR_INTERNAL;
}