about:startup - open the correct file, error check the fopen, use try/catch to check for failure in the js

This commit is contained in:
Daniel Brooks 2010-08-01 04:47:42 -05:00
Родитель da263b215f
Коммит 981448b1b0
2 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -4,7 +4,11 @@ var Ci = Components.interfaces;
let launched, startup, restored;
let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
try {
displayTimestamp("launched", launched = runtime.launchTimestamp);
} catch(x) { }
displayTimestamp("started", startup = runtime.startupTimestamp);
if (launched)
displayDuration("started", startup - launched);

Просмотреть файл

@ -810,6 +810,7 @@ NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
{
#ifdef XP_UNIX
FILE *uptime;
long tickspersecond = sysconf(_SC_CLK_TCK);
unsigned long long sec, ssec;
uptime = fopen("/proc/uptime", "r");
@ -819,9 +820,10 @@ NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
FILE *pidstat;
pid_t pid = getpid();
char *statpath = PR_smprintf("/proc/%d/uptime", pid);
char *statpath = PR_smprintf("/proc/%d/stat", pid);
pidstat = fopen(statpath, "r");
PR_smprintf_free(statpath);
if (!pidstat)
return NS_ERROR_FAILURE;
char stat[512];
memset(&stat, 0, 512);
@ -829,6 +831,7 @@ NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
if (n <= 0)
return NS_ERROR_FAILURE;
fclose(pidstat);
PR_smprintf_free(statpath);
PRTime starttime = 0;
sscanf(strrchr(stat, ')') + 2,
@ -836,8 +839,7 @@ NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
"%*u %*u %*u %*u %*u %*d %*d %*d %*d %llu",
&starttime);
printf("%llu, %llu\n", boottime, starttime * PR_USEC_PER_SEC);
*aTimestamp = boottime + (starttime * PR_USEC_PER_SEC);
*aTimestamp = boottime + ((starttime / tickspersecond) * PR_USEC_PER_SEC);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;