/*
 * Clear last per-thread error message
 */
static void
clearLastError() {
    char* msg = (char *)sysTlsGet(tlsIndex);
    if (msg != NULL) {
        (*callback->free)(msg);
        sysTlsPut(tlsIndex, NULL);
    }
}
jint
shmemBase_getlasterror(char *msg, jint size) {
    char *errstr = (char *)sysTlsGet(tlsIndex);
    if (errstr != NULL) {
        strcpy(msg, errstr);
        return SYS_OK;
    } else {
        return SYS_ERR;
    }
}
/*
 * Set the per-thread error message (if not already set)
 */
static void
setLastErrorMsg(char *newmsg) {
    char *msg;

    msg = (char *)sysTlsGet(tlsIndex);
    if (msg == NULL) {
        msg = (*callback->alloc)(strlen(newmsg)+1);
        if (msg != NULL) {
           strcpy(msg, newmsg);
        }
        sysTlsPut(tlsIndex, (void *)msg);
    }
}
Esempio n. 4
0
/*
 * Return the error message for this thread.
 */
static jdwpTransportError  JNICALL
shmemGetLastError(jdwpTransportEnv* env, char **msgP)
{
    char *msg = (char *)sysTlsGet(tlsIndex);
    if (msg == NULL) {
        return JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE;
    }
    *msgP = (*callbacks->alloc)((int)strlen(msg)+1);
    if (*msgP == NULL) {
        return JDWPTRANSPORT_ERROR_OUT_OF_MEMORY;
    }
    strcpy(*msgP, msg);
    return JDWPTRANSPORT_ERROR_NONE;
}
Esempio n. 5
0
/*
 * Set the error message for this thread. If the error is an I/O
 * error then augment the supplied error message with the textual
 * representation of the I/O error.
 */
static void
setLastError(int err, char *newmsg) {
    char buf[255];
    char *msg;

    /* get any I/O first in case any system calls override errno */
    if (err == JDWPTRANSPORT_ERROR_IO_ERROR) {
        if (shmemBase_getlasterror(buf, sizeof(buf)) != SYS_OK) {
            buf[0] = '\0';
        }
    }

    /* free any current error */
    msg = (char *)sysTlsGet(tlsIndex);
    if (msg != NULL) {
        (*callbacks->free)(msg);
    }

    /*
     * For I/O errors append the I/O error message with to the
     * supplied message. For all other errors just use the supplied
     * message.
     */
    if (err == JDWPTRANSPORT_ERROR_IO_ERROR) {
        char *join_str = ": ";
        int msg_len = (int)strlen(newmsg) + (int)strlen(join_str) +
                      (int)strlen(buf) + 3;
        msg = (*callbacks->alloc)(msg_len);
        if (msg != NULL) {
            strcpy(msg, newmsg);
            strcat(msg, join_str);
            strcat(msg, buf);
        }
    } else {
        msg = (*callbacks->alloc)((int)strlen(newmsg)+1);
        if (msg != NULL) {
            strcpy(msg, newmsg);
        }
    }

    /* Put a pointer to the message in TLS */
    sysTlsPut(tlsIndex, msg);
}