Exemplo n.º 1
0
int wrap_rrd_graph(char *argstr, FILE *fd)
{
	char
		**prdata = NULL,	//	must be passed to the rrd_graph function but does not need to be initialised
		**argv = NULL;

	int
		i, argc,
		xsize = 0,	//	must be passed to the rrd_graph function but does not need to be initialised
		ysize = 0;	//	must be passed to the rrd_graph function but does not need to be initialised
	double
		ymin,	//	must be passed to the rrd_graph function but does not need to be initialised
		ymax;	//	must be passed to the rrd_graph function but does not need to be initialised

	if((argv = string_to_argv(argstr, &argc)) != NULL)
	{
		optind=0; /* reset gnu getopt */
		opterr=0; /* no error messages */

		i = rrd_graph(argc, argv, &prdata, &xsize, &ysize, fd, &ymin, &ymax);

		//	free up the memory
		Free_argv(argv);

		return i;
	}
	else
	{
		//	error
		return (-1);
	}
}
Exemplo n.º 2
0
int wrap_rrd_dump(char *argstr)
{
	char
		**argv;

	int
		i, argc;

	if((argv = string_to_argv(argstr, &argc)) != NULL)
	{
		optind=0; /* reset gnu getopt */
		opterr=0; /* no error messages */

		i = rrd_dump(argc, argv);

		//	free up the memory
		Free_argv(argv);

		return i;
	}
	else
	{
		//	error
		return (-1);
	}
}
Exemplo n.º 3
0
/**
 * @brief sends/receives socket messages
 * @param self pointer to dispatcher socket struct
 * @param context void context pointer required for event loop callback (currently unused)
 */
int dispatcher_cb(void *self, void *context) {
  co_socket_t *sock = self;
  char buffer[1024];
  char *cmdargv[MAX_ARGS];
  int cmdargc;
  memset((void *)buffer, '\0', sizeof(buffer));

  /* Incoming message on socket */
  int received = sock->receive(sock, buffer, sizeof(buffer));
  DEBUG("Received %d bytes.", received);
  if(received == 0) {
    INFO("Received connection.");
    return 1;
  }
  if (received < 0) {
    INFO("Connection recvd() -1");
    sock->hangup(sock, context);
    return 1;
  }
  /* If it's a commotion message type, parse the header, target and payload */
  co_msg_t *msgrcv = co_msg_unpack(buffer);
  if(msgrcv->header.size <= (sizeof(co_msg_header_t) + strlen(msgrcv->target))) {
    DEBUG("Received message with target %s and empty payload.", msgrcv->target);
    cmdargc = 0;
    cmdargv[0] = NULL;
  } else {
    DEBUG("Received target %s and payload %s", msgrcv->target, msgrcv->payload);
    string_to_argv(msgrcv->payload, cmdargv, &cmdargc, MAX_ARGS);
  }
  /*  */
  char *ret = co_cmd_exec(msgrcv->target, cmdargv, cmdargc, 0);
  if(ret) {
    sock->send(sock, ret, strlen(ret));
    free(ret);
  } else {
    sock->send(sock, "No such command.\n", 17);
  }

 // for(int i = 0; i < cmdargc; i++) {
 //   if(cmdargv[i]) free(cmdargv[i]);
 // }
  return 1;
}