Back to index

tor  0.2.3.18-rc
Typedefs | Functions
procmon.h File Reference

Headers for procmon.c. More...

#include "compat.h"
#include "compat_libevent.h"
#include "torlog.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct tor_process_monitor_t
typedef void(* tor_procmon_callback_t )(void *)

Functions

int tor_validate_process_specifier (const char *process_spec, const char **msg)
 Verify that the process specifier given in process_spec is syntactically valid.
tor_process_monitor_ttor_process_monitor_new (struct event_base *base, const char *process_spec, log_domain_mask_t log_domain, tor_procmon_callback_t cb, void *cb_arg, const char **msg)
 Create a process-termination monitor for the process specifier given in process_spec.
void tor_process_monitor_free (tor_process_monitor_t *procmon)
 Free the process-termination monitor procmon.

Detailed Description

Headers for procmon.c.

Definition in file procmon.h.


Typedef Documentation

typedef struct tor_process_monitor_t

Definition at line 17 of file procmon.h.

typedef void(* tor_procmon_callback_t)(void *)

Definition at line 20 of file procmon.h.


Function Documentation

Free the process-termination monitor procmon.

Definition at line 326 of file procmon.c.

{
  if (procmon == NULL)
    return;

#ifdef _WIN32
  if (procmon->hproc != NULL)
    CloseHandle(procmon->hproc);
#endif

  if (procmon->e != NULL)
    tor_event_free(procmon->e);

  tor_free(procmon);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tor_process_monitor_t* tor_process_monitor_new ( struct event_base *  base,
const char *  process_spec,
log_domain_mask_t  log_domain,
tor_procmon_callback_t  cb,
void *  cb_arg,
const char **  msg 
)

Create a process-termination monitor for the process specifier given in process_spec.

Return a newly allocated tor_process_monitor_t on success; return NULL and store an error message into *msg on failure. The caller must not free the returned error message.

When the monitored process terminates, call cb(cb_arg).

Definition at line 176 of file procmon.c.

{
  tor_process_monitor_t *procmon = tor_malloc(sizeof(tor_process_monitor_t));
  struct parsed_process_specifier_t ppspec;

  tor_assert(msg != NULL);
  *msg = NULL;

  if (procmon == NULL) {
    *msg = "out of memory";
    goto err;
  }

  procmon->log_domain = log_domain;

  if (parse_process_specifier(process_spec, &ppspec, msg))
    goto err;

  procmon->pid = ppspec.pid;

#ifdef _WIN32
  procmon->hproc = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
                               FALSE,
                               procmon->pid);

  if (procmon->hproc != NULL) {
    procmon->poll_hproc = 1;
    log_info(procmon->log_domain, "Successfully opened handle to process %d; "
             "monitoring it.",
             (int)(procmon->pid));
  } else {
    /* If we couldn't get a handle to the process, we'll try again the
     * first time we poll. */
    log_info(procmon->log_domain, "Failed to open handle to process %d; will "
             "try again later.",
             (int)(procmon->pid));
  }
#endif

  procmon->cb = cb;
  procmon->cb_arg = cb_arg;

#ifdef PROCMON_POLLS
  procmon->e = tor_event_new(base, -1 /* no FD */, PERIODIC_TIMER_FLAGS,
                             tor_process_monitor_poll_cb, procmon);
  /* Note: If you port this file to plain Libevent 2, check that
   * procmon->e is non-NULL.  We don't need to here because
   * tor_evtimer_new never returns NULL. */

  evtimer_add(procmon->e, &poll_interval_tv);
#else
#error OOPS?
#endif

  return procmon;
 err:
  tor_process_monitor_free(procmon);
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tor_validate_process_specifier ( const char *  process_spec,
const char **  msg 
)

Verify that the process specifier given in process_spec is syntactically valid.

Return 0 on success; return -1 and store an error message into *msg on failure. The caller must not free the returned error message.

Definition at line 142 of file procmon.c.

{
  struct parsed_process_specifier_t ppspec;

  tor_assert(msg != NULL);
  *msg = NULL;

  return parse_process_specifier(process_spec, &ppspec, msg);
}

Here is the call graph for this function: