int main() {
  log_out = stdout;
  log_err = stderr;

  winfo("Starting hypervisor");

  /* Get boartype */
  board = get_boardtype();
  werr2(board == NULL, return 0, "Could not get boardtype");

  /* Build path of settings_<boardtype>.json */
  char settings_file[128];
  int snprintf_rc = snprintf(settings_file, 128, "%s%s.json", SETTINGS_PATH, board);
  wsyserr2(snprintf_rc < 0, return 0, "Could not build the settings configuration file");
  werr2(snprintf_rc >= 128, return 0, "File path of settings configuration file too long");

  /* Get the content from the settings_<boardtype> file in a json_object */
  json_t *settings_json = file_to_json(settings_file);
  werr2(settings_json == NULL, return 0, "Could not load JSON from %s", settings_file);

  /* Load content from settings_<boardtype> in variables */
  bool load_settings_rc = load_content_from_settings_file(settings_json, settings_file);
  werr2(!load_settings_rc, return 0, "Invalid settings in %s", settings_file);

  /* Set local logs */
  log_out = fopen(logout_path, "a");
  if (log_out == NULL) { log_out = stdout; }
  log_err = fopen(logerr_path, "a");
  if (log_err == NULL) { log_err = stderr; }

  /* Load content from wyliodrin.json. The path to this file is indicated by the config_file
   * entry from the settings configuration file. */
  if (strncmp(board, "edison", strlen("edison")) == 0) {
    system("ls /media/storage/wyliodrin.json || "
           "(mkdir -p /media/storage ; mount -o loop,ro,offset=8192 /dev/mmcblk0p9 /media/storage)");
  }
  json_t *config_json = file_to_json(config_file);
  if (strncmp(board, "edison", strlen("edison")) == 0) {
    system("ls /media/storage/wyliodrin.json && umount /media/storage");
  }
  werr2(config_json == NULL, return 0, "Could not load JSON from %s", config_file);

  bool load_config_rc = load_content_from_config_file(config_json, config_file);
  werr2(!load_config_rc, return 0, "Invalid configuration in %s", config_file);

  init_shells();
  init_redis();

  while (true) {
    sleep(pong_timeout);
    publish("pong", 4);
  }

  return 0;
}
Exemplo n.º 2
0
      PluginInterfaceable* tryLoad(QPluginLoader* pluginLoader){
        this->loader = pluginLoader;

        if (!this->loadBinary()){
          werr(q_ptr, QString("Can't load binary!").arg(pluginLoader->errorString()));
          return 0;
        } else {
          if (!pluginLoader->isLoaded()){
            werr(q_ptr, QString("Failed to load plugin binary. Error: %1").arg(pluginLoader->errorString()));
            return 0;
          }

          else
            winfo(q_ptr, QString("Plugin interface loaded for %1").arg(id.toString()));
        }

        return this->getPluginInterface();
      }
Exemplo n.º 3
0
void
waterWindowBaseType2sweepItem(AMI_STREAM<waterWindowBaseType> *baseStr, 
			      const dimension_type nrows, 
			      const dimension_type ncols,
			      const elevation_type nodata_value,
			      AMI_STREAM<sweepItem> *sweep_str) {
  flow_waterWindower winfo(sweep_str);
  waterWindowBaseType nodata((elevation_type)nodata_value, 
							 (direction_type)nodata_value, 
							 DEPTH_INITIAL);
  /* 
	 assert(baseStr->stream_len() > 0);
	 XXX - should check if it fits in memory technically don't need to
	 give the template args, but seems to help the compiler 
	 memoryScan(*baseStr, hdr, nodata,  winfo); 
  */
  memoryScan<waterWindowBaseType,flow_waterWindower>(*baseStr, nrows, ncols, nodata, winfo); 
  
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
  log_out = stdout;
  log_err = stderr;

  winfo("Starting wyliodrind");

  /* Get libwyliodrin version */
  FILE *fp = popen("/usr/bin/wylio -v", "r");

  if (fp != NULL) {
    char libwyliodrin_version[8];
    char *fgets_rc = fgets(libwyliodrin_version, sizeof(libwyliodrin_version)-1, fp);
    wsyserr2(fgets_rc == NULL, /* Do nothing */, "Cannot read from /usr/bin/wylio -v stream");
    pclose(fp);

    if (fgets_rc != NULL) {
      int sscanf_rc = sscanf(libwyliodrin_version, "v%d.%d", &libwyliodrin_version_major,
                                                             &libwyliodrin_version_minor);
      werr2(sscanf_rc != 2, goto _finish, "Invalid libwyliodrin_version format.");
    }
Exemplo n.º 5
0
/*
 * Wait system call.
 * Search for a terminated (zombie) child,
 * finally lay it to rest, and collect its status.
 * Look also for stopped children,
 * and pass back status from them.
 */
int
waitid(idtype_t idtype, id_t id, k_siginfo_t *ip, int options)
{
	int found;
	proc_t *cp, *pp;
	int proc_gone;
	int waitflag = !(options & WNOWAIT);

	/*
	 * Obsolete flag, defined here only for binary compatibility
	 * with old statically linked executables.  Delete this when
	 * we no longer care about these old and broken applications.
	 */
#define	_WNOCHLD	0400
	options &= ~_WNOCHLD;

	if (options == 0 || (options & ~WOPTMASK))
		return (EINVAL);

	switch (idtype) {
	case P_PID:
	case P_PGID:
		if (id < 0 || id >= maxpid)
			return (EINVAL);
		/* FALLTHROUGH */
	case P_ALL:
		break;
	default:
		return (EINVAL);
	}

	pp = ttoproc(curthread);

	/*
	 * lock parent mutex so that sibling chain can be searched.
	 */
	mutex_enter(&pidlock);

	/*
	 * if we are only looking for exited processes and child_ns list
	 * is empty no reason to look at all children.
	 */
	if (idtype == P_ALL &&
	    (options & ~WNOWAIT) == (WNOHANG | WEXITED) &&
	    pp->p_child_ns == NULL) {
		if (pp->p_child) {
			mutex_exit(&pidlock);
			bzero(ip, sizeof (k_siginfo_t));
			return (0);
		}
		mutex_exit(&pidlock);
		return (ECHILD);
	}

	while (pp->p_child != NULL) {

		proc_gone = 0;

		for (cp = pp->p_child_ns; cp != NULL; cp = cp->p_sibling_ns) {
			if (idtype != P_PID && (cp->p_pidflag & CLDWAITPID))
				continue;
			if (idtype == P_PID && id != cp->p_pid)
				continue;
			if (idtype == P_PGID && id != cp->p_pgrp)
				continue;

			switch (cp->p_wcode) {

			case CLD_TRAPPED:
			case CLD_STOPPED:
			case CLD_CONTINUED:
				cmn_err(CE_PANIC,
				    "waitid: wrong state %d on the p_newstate"
				    " list", cp->p_wcode);
				break;

			case CLD_EXITED:
			case CLD_DUMPED:
			case CLD_KILLED:
				if (!(options & WEXITED)) {
					/*
					 * Count how many are already gone
					 * for good.
					 */
					proc_gone++;
					break;
				}
				if (!waitflag) {
					winfo(cp, ip, 0);
				} else {
					winfo(cp, ip, 1);
					freeproc(cp);
				}
				mutex_exit(&pidlock);
				if (waitflag) {		/* accept SIGCLD */
					sigcld_delete(ip);
					sigcld_repost();
				}
				return (0);
			}

			if (idtype == P_PID)
				break;
		}

		/*
		 * Wow! None of the threads on the p_sibling_ns list were
		 * interesting threads. Check all the kids!
		 */
		found = 0;
		for (cp = pp->p_child; cp != NULL; cp = cp->p_sibling) {
			if (idtype == P_PID && id != cp->p_pid)
				continue;
			if (idtype == P_PGID && id != cp->p_pgrp)
				continue;

			switch (cp->p_wcode) {
			case CLD_TRAPPED:
				if (!(options & WTRAPPED))
					break;
				winfo(cp, ip, waitflag);
				mutex_exit(&pidlock);
				if (waitflag) {		/* accept SIGCLD */
					sigcld_delete(ip);
					sigcld_repost();
				}
				return (0);

			case CLD_STOPPED:
				if (!(options & WSTOPPED))
					break;
				/* Is it still stopped? */
				mutex_enter(&cp->p_lock);
				if (!jobstopped(cp)) {
					mutex_exit(&cp->p_lock);
					break;
				}
				mutex_exit(&cp->p_lock);
				winfo(cp, ip, waitflag);
				mutex_exit(&pidlock);
				if (waitflag) {		/* accept SIGCLD */
					sigcld_delete(ip);
					sigcld_repost();
				}
				return (0);

			case CLD_CONTINUED:
				if (!(options & WCONTINUED))
					break;
				winfo(cp, ip, waitflag);
				mutex_exit(&pidlock);
				if (waitflag) {		/* accept SIGCLD */
					sigcld_delete(ip);
					sigcld_repost();
				}
				return (0);

			case CLD_EXITED:
			case CLD_DUMPED:
			case CLD_KILLED:
				if (idtype != P_PID &&
				    (cp->p_pidflag & CLDWAITPID))
					continue;
				/*
				 * Don't complain if a process was found in
				 * the first loop but we broke out of the loop
				 * because of the arguments passed to us.
				 */
				if (proc_gone == 0) {
					cmn_err(CE_PANIC,
					    "waitid: wrong state on the"
					    " p_child list");
				} else {
					break;
				}
			}

			found++;

			if (idtype == P_PID)
				break;
		}

		/*
		 * If we found no interesting processes at all,
		 * break out and return ECHILD.
		 */
		if (found + proc_gone == 0)
			break;

		if (options & WNOHANG) {
			mutex_exit(&pidlock);
			bzero(ip, sizeof (k_siginfo_t));
			/*
			 * We should set ip->si_signo = SIGCLD,
			 * but there is an SVVS test that expects
			 * ip->si_signo to be zero in this case.
			 */
			return (0);
		}

		/*
		 * If we found no processes of interest that could
		 * change state while we wait, we don't wait at all.
		 * Get out with ECHILD according to SVID.
		 */
		if (found == proc_gone)
			break;

		if (!cv_wait_sig_swap(&pp->p_cv, &pidlock)) {
			mutex_exit(&pidlock);
			return (EINTR);
		}
	}
	mutex_exit(&pidlock);
	return (ECHILD);
}