Esempio n. 1
0
/*
** Generate a hyperlink to a version.
*/
void hyperlink_to_uuid(const char *zUuid){
  char zShortUuid[UUID_SIZE+1];
  shorten_uuid(zShortUuid, zUuid);
  if( g.okHistory ){
    @ <a class="timelineHistLink" href="%s(g.zBaseURL)/info/%s(zShortUuid)">
    @ [%s(zShortUuid)]</a>
  }else{
    @ <span class="timelineHistDsp">[%s(zShortUuid)]</span>
Esempio n. 2
0
/*
** Generate a hyperlink that invokes javascript to highlight
** a version on mouseover.
*/
void hyperlink_to_uuid_with_mouseover(
  const char *zUuid,   /* The UUID to display */
  const char *zIn,     /* Javascript proc for mouseover */
  const char *zOut,    /* Javascript proc for mouseout */
  int id               /* Argument to javascript procs */
){
  char zShortUuid[UUID_SIZE+1];
  shorten_uuid(zShortUuid, zUuid);
  if( g.okHistory ){
    @ <a onmouseover='%s(zIn)("m%d(id)")' onmouseout='%s(zOut)("m%d(id)")'
    @    href="%s(g.zBaseURL)/vinfo/%s(zShortUuid)">[%s(zShortUuid)]</a>
  }else{
    @ <b onmouseover='%s(zIn)("m%d(id)")' onmouseout='%s(zOut)("m%d(id)")'>
Esempio n. 3
0
static int generate(char id[34]) {
        int fd, r;
        unsigned char *p;
        sd_id128_t buf;
        char *q;
        ssize_t k;
        const char *vm_id;

        assert(id);

        /* First, try reading the D-Bus machine id, unless it is a symlink */
        fd = open("/var/lib/dbus/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
        if (fd >= 0) {

                k = loop_read(fd, id, 32, false);
                close_nointr_nofail(fd);

                if (k >= 32) {
                        id[32] = '\n';
                        id[33] = 0;

                        log_info("Initializing machine ID from D-Bus machine ID.");
                        return 0;
                }
        }

        /* If that didn't work, see if we are running in qemu/kvm and a
         * machine ID was passed in via -uuid on the qemu/kvm command
         * line */

        r = detect_vm(&vm_id);
        if (r > 0 && streq(vm_id, "kvm")) {
                char uuid[37];

                fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
                if (fd >= 0) {
                        k = loop_read(fd, uuid, 36, false);
                        close_nointr_nofail(fd);

                        if (k >= 36) {
                                r = shorten_uuid(id, uuid);
                                if (r >= 0) {
                                        log_info("Initializing machine ID from KVM UUID.");
                                        return 0;
                                }
                        }
                }
        }

        /* If that didn't work either, see if we are running in a
         * container, and a machine ID was passed in via
         * $container_uuid the way libvirt/LXC does it */
        r = detect_container(NULL);
        if (r > 0) {
                char *e;

                r = getenv_for_pid(1, "container_uuid", &e);
                if (r > 0) {
                        if (strlen(e) >= 36) {
                                r = shorten_uuid(id, e);
                                if (r >= 0) {
                                        log_info("Initializing machine ID from container UUID.");
                                        free(e);
                                        return 0;
                                }
                        }

                        free(e);
                }
        }

        /* If that didn't work, generate a random machine id */
        r = sd_id128_randomize(&buf);
        if (r < 0) {
                log_error("Failed to open /dev/urandom: %s", strerror(-r));
                return r;
        }

        for (p = buf.bytes, q = id; p < buf.bytes + sizeof(buf); p++, q += 2) {
                q[0] = hexchar(*p >> 4);
                q[1] = hexchar(*p & 15);
        }

        id[32] = '\n';
        id[33] = 0;

        log_info("Initializing machine ID from random generator.");

        return 0;
}