Ejemplo n.º 1
0
/* Pops the top of the prompt stack, and frees the memory allocated for it. */
void
pop_prompt (void)
{
  /* If we are not during a 'synchronous' execution command, in which
     case, the top prompt would be empty. */
  if (strcmp (PROMPT (0), ""))
    /* This is for the case in which the prompt is set while the
       annotation level is 2. The top prompt will be changed, but when
       we return to annotation level < 2, we want that new prompt to be
       in effect, until the user does another 'set prompt'. */
    if (strcmp (PROMPT (0), PROMPT (-1)))
      {
	xfree (PROMPT (-1));
	PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
      }

  xfree (PREFIX (0));
  xfree (PROMPT (0));
  xfree (SUFFIX (0));
  the_prompts.top--;
}
Ejemplo n.º 2
0
static int fit_file(T *thiz, hdr_block_t *hdr)
{
    int r = 0;
    struct stat st;
    char *hdr_buf = NULL, *tail_buf = NULL;

    fstat(thiz->wfd, &st);
    if (hdr->fend_off == st.st_size) goto _out;
    if (hdr->fend_off > st.st_size) {
        ERROR("offset=%"PRIu32" bigger than fsize=%zu", hdr->fend_off, st.st_size);
        r = -1;
        goto _out;
    }

    PROMPT("repair tailer block");
    r = ftruncate(thiz->wfd, hdr->fend_off);
    if (r != 0) {
        ERROR("ftruncate errno=%d", errno);
        r = -1;
        goto _out;
    }

    hdr_buf = MY_Memalign(BTR_HEADER_BLK_SIZE);
    tail_buf = MY_Memalign(BTR_HEADER_BLK_SIZE);

    io_pread(thiz->wfd, hdr_buf, BTR_HEADER_BLK_SIZE, 0);
    io_pread(thiz->wfd, tail_buf, BTR_HEADER_BLK_SIZE, hdr->fend_off - BTR_HEADER_BLK_SIZE);

    r = memcmp(hdr_buf, tail_buf, BTR_HEADER_BLK_SIZE);
    if (r != 0) {
        ERROR("header still not euqal tailer");
        r = -1;
    }

    MY_AlignFree(hdr_buf);
    MY_AlignFree(tail_buf);

_out:
    fsync(thiz->wfd);
    return r;

}
Ejemplo n.º 3
0
/* Used when the user requests a different annotation level, with
   'set annotate'. It pushes a new prompt (with prefix and suffix) on top
   of the prompt stack, if the annotation level desired is 2, otherwise
   it pops the top of the prompt stack when we want the annotation level
   to be the normal ones (1 or 0). */
static void
change_annotation_level (void)
{
  char *prefix, *suffix;

  if (!PREFIX (0) || !PROMPT (0) || !SUFFIX (0))
    {
      /* The prompt stack has not been initialized to "", we are
         using gdb w/o the --async switch */
      warning (_("Command has same effect as set annotate"));
      return;
    }

  if (annotation_level > 1)
    {
      if (!strcmp (PREFIX (0), "") && !strcmp (SUFFIX (0), ""))
	{
	  /* Push a new prompt if the previous annotation_level was not >1. */
	  prefix = (char *) alloca (strlen (async_annotation_suffix) + 10);
	  strcpy (prefix, "\n\032\032pre-");
	  strcat (prefix, async_annotation_suffix);
	  strcat (prefix, "\n");

	  suffix = (char *) alloca (strlen (async_annotation_suffix) + 6);
	  strcpy (suffix, "\n\032\032");
	  strcat (suffix, async_annotation_suffix);
	  strcat (suffix, "\n");

	  push_prompt (prefix, (char *) 0, suffix);
	}
    }
  else
    {
      if (strcmp (PREFIX (0), "") && strcmp (SUFFIX (0), ""))
	{
	  /* Pop the top of the stack, we are going back to annotation < 1. */
	  pop_prompt ();
	}
    }
}
Ejemplo n.º 4
0
static void 
BkgdProcEndCallbk(struct Process *pa_)
{
	PROMPT(Usual,"bkgd process end.\n");
	sta_ifBkgdSubProcess = 0;
}
Ejemplo n.º 5
0
static void
welcome_(void)
{
	PROMPT("version " WELCOMEVERSION " is ready.");
}
Ejemplo n.º 6
0
/* Called by do_setshow_command.  */
void
set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
{
  PROMPT (0) = xstrdup (new_async_prompt);
}
Ejemplo n.º 7
0
/* Called by do_setshow_command.  */
void
set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
{
  PROMPT (0) = savestring (new_async_prompt, strlen (new_async_prompt));
}
Ejemplo n.º 8
0
static int diagnosis(T *thiz)
{
    int r = 0, r1, r2, blktype = 0;
    struct stat st;
    char *hdr_buf = NULL, *tail_buf = NULL;

    hdr_buf = MY_Memalign(BTR_HEADER_BLK_SIZE);
    tail_buf = MY_Memalign(BTR_HEADER_BLK_SIZE);

    if (hdr_buf == NULL || tail_buf == NULL) {
        r = -1;
        goto _out;
    }

    r1 = io_pread(thiz->wfd, hdr_buf, BTR_HEADER_BLK_SIZE, 0);
    if (r1 == -1 || r1 != BTR_HEADER_BLK_SIZE) {
        ERROR("pread errno=%d, r=%d", errno, BTR_HEADER_BLK_SIZE);
        r = -1;
        goto _out;
    }

    /* read tailer block */
    fstat(thiz->wfd, &st);
    r2 = io_pread(thiz->wfd, tail_buf, BTR_HEADER_BLK_SIZE, st.st_size - BTR_HEADER_BLK_SIZE);
    if (r2 == -1 || r2 != BTR_HEADER_BLK_SIZE) {
        ERROR("pread errno=%d, r=%d", errno, r2);
        r = -1;
        goto _out;
    }

    r1 = r2 = 0;

    blktype = *(hdr_buf + 4);
    if (blktype != BTR_HEADER_BLK) {
        ERROR("header not a real BTR_HEADER_BLK, blktype=%d", blktype);
        r1 = -1;
    }

    blktype = *(tail_buf + 4);
    if (blktype != BTR_HEADER_BLK) {
        ERROR("tailer not a real BTR_HEADER_BLK, blktype=%d", blktype);
        r2 = -1;
    }

    if (r1 == -1 && r2 == -1) {
        r = -1;
        goto _out;
    }

    if (r1 == 0) {
        r1 = blk_crc32_check(hdr_buf, BTR_HEADER_BLK_SIZE);
        /* return if header block is correct, regardless of tailer block */
        if (r1 == 0) goto _out;
        else {
            ERROR("header block crc error");
        }
    }

    r2 = blk_crc32_check(tail_buf, BTR_HEADER_BLK_SIZE);
    if (r2 != 0) {
        ERROR("tailer block crc error");
        r = -1;
        goto _out;
    }

    PROMPT("repair header block");
    r2 = io_pwrite(thiz->wfd, tail_buf, BTR_HEADER_BLK_SIZE, 0);
    if (r2 == -1 || r2 != BTR_HEADER_BLK_SIZE) {
        ERROR("repair header block error");
        r = -1;
        goto _out;
    }

_out:
    if (hdr_buf) MY_AlignFree(hdr_buf);
    if (tail_buf) MY_AlignFree(tail_buf);

    return r;
}
Ejemplo n.º 9
0
int main_loop() {
#define STDIN 0

    int ret = 0;
    struct timeval to;
    char *newline;
    int bytes, buf_idx = 0;
    fd_set input_fds;
    char *buf = (char *)malloc(MAX_MSGDATA);
    msg_t msg;

    memset(buf, 0, MAX_MSGDATA);
    printf("\n");
    PROMPT();

    while(TRUE) {

        /* If we've not seen the server in KA_TIMEOUT seconds, send
         * a keepalive message. */
        if ((ret = check_keepalive()) != 0) {
            fprintf(stderr, "Problem sending keepalive packet.\n");
            return ret;
        }


        /****************************************
         * Check stdin for input...
         *
         * TODO: try other values for timeout?
         */
        FD_ZERO(&input_fds);
        FD_SET(STDIN, &input_fds);
        to.tv_sec = 0;
        to.tv_usec = 0;

        select(STDIN+1, &input_fds, NULL, NULL, &to);

        if (FD_ISSET(STDIN, &input_fds)) {
            debug_sub_print(DBG_ACTIVE, "%s: stdin has input\n", __func__);
            /************************************
             * Can read from stdin, collect input in buf until
             * we've got a whole line. STDIN may be
             * line-buffered, in which case this is not
             * necessry. TODO: check/set buffering strategy
             * of stdin
             */
            bytes = read(STDIN, buf + buf_idx, MAX_MSGDATA - buf_idx);

            if (bytes <= 0) {
                fprintf(stderr, "%s: reading from stdin: %s\n",
                    __func__, strerror(errno));
                shutdown_clean(1);
            } else {
                newline = (char *) (memchr(buf + buf_idx, '\n', bytes));

                if (newline) {
                    /* User pressed enter, check if control message or
                     * chat message. The functions which we pass the input
                     * on to expect null-termination.
                     */
                    *newline = '\0';

                    if (buf[0] == '!') {
                        ret = handle_command_input(&buf[1]);
                    } else {
                        ret = handle_chatmsg_input(buf);
                    }

                    if (ret) {
                        fprintf(stderr, "Error communicating with server\n");
                        return ret;
                    }
                    
                    PROMPT();
                    /* done with the buffer contents, reset */
                    memset(buf, 0, MAX_MSGDATA);
                    buf_idx = 0;
                } else {
                    /* keep track of how much buffer we've used, continue
                     * waiting for a newline...
                     */
                    buf_idx += bytes;
                }
            }
        } else {
            /************************************
             * Try to read a message from the queue...
             */
            bytes = msgrcv(ctrl2rcvr_qid, &msg, sizeof(struct body_s),
                CTRL_TYPE, IPC_NOWAIT);

            if (bytes <= 0) {
                /* EAGAIN and ENOMSG are expected if there was nothing
                 * waiting for us, don't know what to do with other
                 * types of error */
                if ((errno == EAGAIN) || (errno == ENOMSG)) {
                    /* that's cool */
                    /*debug_sub_print(DBG_ACTIVE, "%s: msgrcv: %s\n",
                        __func__, strerror(errno));
                    */
                } else {
                    fprintf(stderr, "%s: msgrcv: unexpected error: %s\n",
                        __func__, strerror(errno));
                    shutdown_clean(1);
                }
            } else if (bytes > 0) {
                /* Update our timestamp if it is an activity notification from
                 * the receiver process, otherwise we're not sure what to do
                 */
                if ((msg.body.status) == SERVER_ACTIVE) {
                    seen_server();
                } else {
                    debug_sub_print(DBG_ACTIVE, "%s: Unexpected message"
                        "type from receiver (%d)\n", __func__, msg.body.status);
                }
            }
        }
    }

    debug_print("%s: Hm, shouldn't be here.\n", __func__);
    return -1;
}