os::is_headless_jre()

-

//Linux版(jdk7/hotspot/src/os/linux/vm/os_linux.cpp)
// is_headless_jre()
//
// Test for the existence of libmawt in motif21 or xawt directories
// in order to report if we are running in a headless jre
//
bool os::is_headless_jre() {
    struct stat statbuf;
    char buf[MAXPATHLEN];
    char libmawtpath[MAXPATHLEN];
    const char *xawtstr  = "/xawt/libmawt.so";
    const char *motifstr = "/motif21/libmawt.so";
    char *p;

    // Get path to libjvm.so
    os::jvm_path(buf, sizeof(buf));

    // Get rid of libjvm.so
    p = strrchr(buf, '/');
    if (p == NULL) return false;
    else *p = '\0';

    // Get rid of client or server
    p = strrchr(buf, '/');
    if (p == NULL) return false;
    else *p = '\0';

    // check xawt/libmawt.so
    strcpy(libmawtpath, buf);
    strcat(libmawtpath, xawtstr);
    if (::stat(libmawtpath, &statbuf) == 0) return false;

    // check motif21/libmawt.so
    strcpy(libmawtpath, buf);
    strcat(libmawtpath, motifstr);
    if (::stat(libmawtpath, &statbuf) == 0) return false;

    return true;
}