commit - 024cbc79bf3a72da2a3e3d6259a11f57bbe5049d
commit + 1c1c6f215843aeb46d2f3f09bb38b3871d282068
blob - 335a33c3cbd0861e8241810c8ee083f61e6e8e36
blob + b8133e506c3d0c18de6dbd984fece387d788c3c4
--- helpers.c
+++ helpers.c
long long int get_proc_uptime(pid_t pid)
{
- unsigned long long proc_uptime;
+ unsigned long long proc_uptime = 0;
#ifdef __linux__
- /*
- see proc(5) -> /proc/[pid]/stat
- */
+ /* see proc(5) -> /proc/[pid]/stat */
char filename[256];
FILE *f;
path[2] = KERN_PROC_PID;
path[3] = pid;
ret = sysctl(path, len_path, &proc, &siz, NULL, 0);
-
- proc_uptime = 0;
-#else
- proc_uptime = 0;
#endif
+
return proc_uptime;
}
blob - 3fa503ee9f36e7dcc6c550b293e1dcb6c8786169
blob + 614c4a414c3c9fcf5fca7a9a5a4831c8700a803a
--- pg_feedback.c
+++ pg_feedback.c
Datum
postmaster_uptime(PG_FUNCTION_ARGS)
{
- char pid[256];
- sprintf(pid, "%d", getppid());
- PG_RETURN_TEXT_P(cstring_to_text(pid));
+ pid_t ppid = getppid();
+ unsigned long long time = get_proc_uptime(ppid);
+ char *uptime_str = NULL;
+ snprintf(uptime_str, 256, "%lld", time);
+ PG_RETURN_TEXT_P(cstring_to_text(uptime_str));
}
PG_FUNCTION_INFO_V1(db_sys_id);
free(os->os_arch);
free(os);
- /* build a tuple */
attinmeta = TupleDescGetAttInMetadata(tupdesc);
tuple = BuildTupleFromCStrings(attinmeta, values);
- /* make the tuple into a datum */
result = HeapTupleGetDatum(tuple);
- /* clean up (this is not really necessary) */
pfree(values[0]);
pfree(values[1]);
pfree(values[2]);
pfree(values[5]);
pfree(values[6]);
pfree(values);
+
PG_RETURN_DATUM(result);
}