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 launched, startup, restored;
let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime); let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
displayTimestamp("launched", launched = runtime.launchTimestamp);
try {
displayTimestamp("launched", launched = runtime.launchTimestamp);
} catch(x) { }
displayTimestamp("started", startup = runtime.startupTimestamp); displayTimestamp("started", startup = runtime.startupTimestamp);
if (launched) if (launched)
displayDuration("started", startup - launched); displayDuration("started", startup - launched);

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

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