Skip to content
Permalink
Browse files

os, bugfix: librt.so not found on ubuntu (#487)

  • Loading branch information...
ngot authored and xicilion committed Apr 6, 2019
1 parent 0a565f3 commit c7ca4c69e3c9ae9db04d60711c20808ea9fbebb0
Showing with 4 additions and 16 deletions.
  1. +4 −16 fibjs/src/os/os_linux.cpp
@@ -16,6 +16,7 @@
#include <sys/param.h>
#include <string.h>
#include "path.h"
#include <time.h>

#ifndef CLOCK_BOOTTIME
#define CLOCK_BOOTTIME 7
@@ -28,28 +29,15 @@ result_t os_base::uptime(double& retVal)
static volatile int32_t no_clock_boottime;
struct timespec now;
int32_t r;
int32_t (*fngettime)(clockid_t, struct timespec*);

void* handle = dlopen("librt.so", RTLD_LAZY);
if (!handle)
return CHECK_ERROR(LastError());

fngettime = (int32_t(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
if (!fngettime) {
dlclose(handle);
return CHECK_ERROR(LastError());
}

if (no_clock_boottime) {
retry:
r = fngettime(CLOCK_MONOTONIC, &now);
} else if ((r = fngettime(CLOCK_BOOTTIME, &now)) && errno == EINVAL) {
r = clock_gettime(CLOCK_MONOTONIC, &now);
} else if ((r = clock_gettime(CLOCK_BOOTTIME, &now)) && errno == EINVAL) {
no_clock_boottime = 1;
goto retry;
}

dlclose(handle);

if (r)
return CHECK_ERROR(LastError());

@@ -360,7 +348,7 @@ result_t os_base::memoryUsage(v8::Local<v8::Object>& retVal)
/* Start of stack */
if (fscanf(f, "%u ", &utmp) == 0)
goto error;
/* coverity[secure_coding] */
/* coverity[secure_coding] */

error:
fclose(f);

0 comments on commit c7ca4c6

Please sign in to comment.
You can’t perform that action at this time.