示例#1
0
static void dispatch(const char *dir,const char *def)
     /* Hand off control to one of the command files in the list directory. */
{
  if (!is_dir(dir))
    return;
  if (!stralloc_append(&basedir,"/")) die_nomem();
  if (!stralloc_cats(&basedir,dir)) die_nomem();
  /* FIXME: set up $EXT $EXT2 $EXT3 $EXT4 ?  Is it feasable? */
  if (def == 0 || *def == 0)
    execute("editor",0);
  else if (str_diff(def,"owner") == 0)
    execute("owner",0);
  else if (str_diff(def,"digest-owner") == 0)
    execute("owner",0);
  else {
    try_dispatch(def,"digest-return-",14,"digest/bouncer");
    try_dispatch(def,"return-",7,"bouncer");
    try_dispatch(def,"confirm-",8,"confirmer");
    try_dispatch(def,"discard-",8,"confirmer");
    try_dispatch(def,"accept-",7,"moderator");
    try_dispatch(def,"reject-",7,"moderator");
    /* If nothing else matches, call the manager. */
    execute("manager",def);
  }
}
static void process_erl()
{
    debug("process_erl\n");
    ssize_t amount_read =
        read(STDIN_FILENO,
            erl_buffer + erl_buffer_ix,
            sizeof(erl_buffer) - erl_buffer_ix);

    if (amount_read < 0) {
        /* EINTR is ok to get if we were interrupted by a signal. */
        if (errno == EINTR)
            return;

        err(EXIT_FAILURE, "read");
    } else if (amount_read == 0) {
        /* EOF. Our Erlang process was terminated. */
        exit(EXIT_SUCCESS);
    }

    erl_buffer_ix += amount_read;
    for (;;) {
        size_t bytes_processed = try_dispatch();
        if (bytes_processed == 0) {
            /* Only have part of the command to process. */
            break;
        } else if (erl_buffer_ix > bytes_processed) {
            /* Processed the command, but there's another one. */
            memmove(erl_buffer, &erl_buffer[bytes_processed], erl_buffer_ix - bytes_processed);
            erl_buffer_ix -= bytes_processed;
        } else {
            /* Processed the whole buffer. */
            erl_buffer_ix = 0;
            break;
        }
    }
}