RDK Documentation (Open Sourced RDK Components)
test_connectivity.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include "logging.h"
5 #include "connectivity.h"
6 
7 int main (int argc, char* argv[])
8 {
9  freopen ("/opt/logs/netsrvmgr.log", "a", stderr);
10  freopen ("/opt/logs/netsrvmgr.log", "a", stdout);
11 
12  long timeout_ms, max_tries;
13  if (argc < 2 || (timeout_ms = strtol(argv[1], NULL, 10)) <= 0)
14  timeout_ms = 2000; // default to 2s if unspecified / non-positive
15  if (argc < 3 || (max_tries = strtol(argv[2], NULL, 10)) <= 0)
16  max_tries = 1; // default to 1 if unspecified / non-positive
17 
18  rdk_logger_init(0 == access("/opt/debug.ini", R_OK) ? "/opt/debug.ini" : "/etc/debug.ini");
19 
20  int connectivity;
21  for (int i = 1; (connectivity = test_connectivity(timeout_ms)) <= 0 && i < max_tries; i++)
22  sleep(1); // sleep 1s after a connectivity test failure before trying again
23 
24  fclose (stdout);
25  fclose (stderr);
26 
27  return (connectivity > 0) ? 0 : 1; // connectivity test successful => exit status 0
28 }
rdk_logger_init
rdk_Error rdk_logger_init(const char *debugConfigFile)
Initialize the logger. Sets up the environment variable storage by parsing debug configuration file t...
Definition: rdk_logger_init.c:57