Example #1
0
   /**
    * \brief Run the service
    *
    * Creates, configures and runs a service instance. Make sure you call this from
    * run() at some point when overriding it.
    */
   void run_service()
   {
      ProcessServiceType service(create_service_instance());

      child_init_func child_init(service, m_logging, m_logging_enabled, m_program_name, options());

      service.set_child_init_func(boost::ref(child_init));

      if (options().count("noerr"))
      {
         service.set_default_stderr_state(false);
      }

      if (!m_pidfile.empty())
      {
         service.set_pidfile(m_pidfile);
      }

      if (m_shell_port)
      {
         service.set_shell_port(m_shell_port);
      }

      service.run(running_as_daemon());
   }
Example #2
0
int sub_init(void)
{
  int i;

  /* Clear table of subprocesses */
  for (i = 0; i < SUB_N; i++) {
    sub_item_zero(&(sub_tab[i]));
    sub_tab[i].num = i;
  }

  /* Create control pipe */
  if ( pipe(sub_ctrl) == -1 )
    return -1;

  /* Control pipe read endpoint is non-blocking */
  fcntl(sub_ctrl[0], F_SETFL, O_NONBLOCK);

  /* Control pipe is not accessible from exec() subprocesses */
  fcntl(sub_ctrl[0], F_SETFD, FD_CLOEXEC);
  fcntl(sub_ctrl[1], F_SETFD, FD_CLOEXEC);

  /* Setup child process management */
  child_init();

  /* Register link class */
  link_class_register(&sub_lclass);

  return 0;
}
Example #3
0
/* each child get a new connection to the database */
static int mod_child_init(int r)
{
	if ( child_init()!=0 )
		return -1;

	LM_DBG("#%d: database connection opened successfully\n",r);

	return 0;
}
Example #4
0
int child_start(Widget top, char *cmd, void (*cb)(int) )
{
    int hc = child_init(cmd, 0);
    struct child_stat *child = mls(CLIST, hc);
    child->cb = cb;
    child_exec(hc);
    child->id = XtAppAddInput(XtWidgetToApplicationContext(top),
                              child_read_fd(hc),
                              (XtPointer)  (XtInputReadMask),
                              child_input_cb,(XtPointer) hc );
    return hc;
}
void
jsk_pcl_ros::Filter::onInit ()
{
  // Call the super onInit ()
  PCLNodelet::onInit ();

  // Call the child's local init
  bool has_service = false;
  if (!child_init (*pnh_, has_service))
  {
    NODELET_ERROR ("[%s::onInit] Initialization failed.", getName ().c_str ());
    return;
  }

  pub_output_ = pnh_->advertise<PointCloud2> ("output", max_queue_size_);

  // Enable the dynamic reconfigure service
  if (!has_service)
  {
    srv_ = boost::make_shared <dynamic_reconfigure::Server<pcl_ros::FilterConfig> > (*pnh_);
    dynamic_reconfigure::Server<pcl_ros::FilterConfig>::CallbackType f =  boost::bind (&Filter::config_callback, this, _1, _2);
    srv_->setCallback (f);
  }

  // If we're supposed to look for PointIndices (indices)
  if (use_indices_)
  {
    // Subscribe to the input using a filter
    sub_input_filter_.subscribe (*pnh_, "input", max_queue_size_);
    sub_indices_filter_.subscribe (*pnh_, "indices", max_queue_size_);

    if (approximate_sync_)
    {
      sync_input_indices_a_ = boost::make_shared <message_filters::Synchronizer<sync_policies::ApproximateTime<PointCloud2, pcl::PointIndices> > >(max_queue_size_);
      sync_input_indices_a_->connectInput (sub_input_filter_, sub_indices_filter_);
      sync_input_indices_a_->registerCallback (bind (&Filter::input_indices_callback, this, _1, _2));
    }
    else
    {
      sync_input_indices_e_ = boost::make_shared <message_filters::Synchronizer<sync_policies::ExactTime<PointCloud2, pcl::PointIndices> > >(max_queue_size_);
      sync_input_indices_e_->connectInput (sub_input_filter_, sub_indices_filter_);
      sync_input_indices_e_->registerCallback (bind (&Filter::input_indices_callback, this, _1, _2));
    }
  }
  else
    // Subscribe in an old fashion to input only (no filters)
    sub_input_ = pnh_->subscribe<sensor_msgs::PointCloud2> ("input", max_queue_size_,  bind (&Filter::input_indices_callback, this, _1, pcl::PointIndicesConstPtr ()));

  NODELET_DEBUG ("[%s::onInit] Nodelet successfully created.", getName ().c_str ());
}
Example #6
0
int child_startv(Widget top, int cmd_m, void (*cb)(int) )
{
    int l = m_len(cmd_m);
    int i;
    int hc = child_init(STR(cmd_m,0), 0);
    struct child_stat *child = mls(CLIST, hc);
    child->cb = cb;
    for(i=1;i<l;i++) v_kset(child->args, STR(cmd_m, i), -1 );
    child_exec(hc);
    child->id = XtAppAddInput(XtWidgetToApplicationContext(top),
                              child_read_fd(hc),
                              (XtPointer)  (XtInputReadMask),
                              child_input_cb,(XtPointer) hc );
    return hc;
}
/**
 * Create the per-client translator
 */
void* CALLBACK on_connect_handler(const WebSocketServer *server) {
    request_rec *r = server->request(server);

    if (!trans) { // first connection

        // connect to opensrf
        if (child_init(server) != APR_SUCCESS)
            return NULL;

        // build pools, thread data, and the translator
        if (build_startup_data(server) != APR_SUCCESS)
            return NULL;
    }

    const char* client_ip = get_client_ip(r);
    osrfLogInfo(OSRF_LOG_MARK, "WS connect from %s", client_ip);

    last_activity_time = time(NULL);
    trans->client_connected = 1;
    return trans;
}
Example #8
0
pid_t trace_fork_with_child_init(
        int (*child_init)(void),
        int (*cleanup_on_failure)(pid_t child_pid)
        )
{
    /* In order to guarantee that either success or failure is returned consistently in both the parent and the child we follow this procedure:
     * - The parent creates a pipe
     * - The parent forks
     * - The child calls the supplied child_init function.
     * - The child sends either 0 (if successful) or otherwise the errno value via the pipe. In case of failure it exits.
     * - If the child failed to send a completion status via the pipe or reported an error, the parent waits for it to exit.
     * */

    int pipefd[2];
    if (pipe(pipefd) < 0) {
        return -1;
    }

    int status = 0;
    const pid_t pid = fork();

    if (pid < 0) {
        status = errno;
    }
    else if (0 == pid) {    /* Child */
        if (child_init() < 0) {
            status = errno;
            TRACE_ASSERT(0 != status);
        }

        switch (write(pipefd[1], &status, sizeof(status))) {
        case sizeof(status):
            break;

        default:
            errno = EIO;
            /* no break - fall through to the regular error case */

        case -1:
            if (0 == status) {
                status = errno;
            }
            TRACE_ASSERT(0 != status);
            break;
        }

        if (0 != status) {
            cleanup_on_failure(getpid());
            _exit(MIN(status, 0xFF));
        }
    }
    else {  /* Parent */
        TRACE_ASSERT(pid > 0);
        const ssize_t n_bytes_read = read(pipefd[0], &status, sizeof(status));
        switch (n_bytes_read) {
        case sizeof(status):
            if (0 != status) {
                wait_until_process_exited(pid, NULL);
            }
            break;

        case 0: { /* The child process exited without writing a status to the pipe. */
            siginfo_t si;
            wait_until_process_exited(pid, &si);
            if (CLD_EXITED == si.si_code) {
                status = (0 != si.si_status) ? si.si_status : EIO;
            }
            else {
                cleanup_on_failure(pid);  /* The child most likely was killed by a signal, so clean after it. */
                status = EIO;
            }
            TRACE_ASSERT(0 != status);
            break;
        }

        default: /* Something went badly wrong with the pipe */
            status = (n_bytes_read < 0) ? errno : EIO;
            if (0 == kill(pid, SIGKILL)) {
                wait_until_process_exited(pid, NULL);
                cleanup_on_failure(pid);
            }
            break;
        }
    }

    close(pipefd[0]);
    close(pipefd[1]);

    if (0 != status) {
        errno = status;
        return -1;
    }

    return pid;
}
Example #9
0
void grandson_init(struct grandson *grandson)
{
	memset(grandson, sizeof(*grandson), 0);
	child_init(&grandson->child);
	CLASS_OPS_INIT_SUPER_WITH_FIRST_STATIC(grandson->child.parent.ops, parent_ops, static_pub_data3);
}
Example #10
-1
/*
 * Parse the JSON protocol header to determine protocol version and features.
 * In case the buffer does not contain a valid header (invalid JSON, or no
 * version field found), the 'correct' field of the returned header is set to
 * false. The amount of bytes consumed by parsing the header is returned in
 * *consumed (if non-NULL).
 *
 */
void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed) {
    static yajl_callbacks version_callbacks = {
        .yajl_boolean = header_boolean,
        .yajl_integer = header_integer,
        .yajl_map_key = &header_map_key,
    };

    child_init(child);

    current_key = NO_KEY;

    yajl_handle handle = yajl_alloc(&version_callbacks, NULL, child);
    /* Allow trailing garbage. yajl 1 always behaves that way anyways, but for
     * yajl 2, we need to be explicit. */
    yajl_config(handle, yajl_allow_trailing_garbage, 1);

    yajl_status state = yajl_parse(handle, buffer, length);
    if (state != yajl_status_ok) {
        child_init(child);
        if (consumed != NULL)
            *consumed = 0;
    } else {
        if (consumed != NULL)
            *consumed = yajl_get_bytes_consumed(handle);
    }

    yajl_free(handle);
}