mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-03 19:03:24 +00:00
process-attributes now uses get_boot_time
I noticed this issue while looking into Bug#63496. GNU Emacs does not infer the boot time consistently on GNU/Linux and similar platforms: android_notifications_notify_1 and get_boot_sec use Gnulib’s boot-time module, but process-attributes has idiosyncratic code that evidently predates that module. The idiosyncratic code returns an unstable etime, which is a minor bug. Simplify process-attributes by just using Gnulib. This returns a stable etime. It may also fix Bug#63496; if not, we can fix Gnulib later. * src/sysdep.c: Include <boot-time.h>. (get_up_time) [GNU_LINUX || CYGWIN || __ANDROID__]: Remove. (system_process_attributes) [GNU_LINUX || CYGWIN || __ANDROID__]: Use get_boot_time instead of get_up_time.
This commit is contained in:
parent
ebdad09c5a
commit
477112ebc3
1 changed files with 5 additions and 36 deletions
41
src/sysdep.c
41
src/sysdep.c
|
@ -30,6 +30,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
#include <sys/random.h>
|
#include <sys/random.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <boot-time.h>
|
||||||
#include <c-ctype.h>
|
#include <c-ctype.h>
|
||||||
#include <close-stream.h>
|
#include <close-stream.h>
|
||||||
#include <pathmax.h>
|
#include <pathmax.h>
|
||||||
|
@ -3453,39 +3454,6 @@ put_jiffies (Lisp_Object attrs, Lisp_Object propname,
|
||||||
return Fcons (Fcons (propname, time_from_jiffies (ticks, hz, Qnil)), attrs);
|
return Fcons (Fcons (propname, time_from_jiffies (ticks, hz, Qnil)), attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Lisp_Object
|
|
||||||
get_up_time (void)
|
|
||||||
{
|
|
||||||
FILE *fup;
|
|
||||||
Lisp_Object up = Qnil;
|
|
||||||
|
|
||||||
block_input ();
|
|
||||||
fup = emacs_fopen ("/proc/uptime", "r");
|
|
||||||
|
|
||||||
if (fup)
|
|
||||||
{
|
|
||||||
unsigned long long upsec;
|
|
||||||
EMACS_UINT upfrac;
|
|
||||||
int upfrac_start, upfrac_end;
|
|
||||||
|
|
||||||
if (fscanf (fup, "%llu.%n%"pI"u%n",
|
|
||||||
&upsec, &upfrac_start, &upfrac, &upfrac_end)
|
|
||||||
== 2)
|
|
||||||
{
|
|
||||||
EMACS_INT hz = 1;
|
|
||||||
for (int i = upfrac_start; i < upfrac_end; i++)
|
|
||||||
hz *= 10;
|
|
||||||
Lisp_Object sec = make_uint (upsec);
|
|
||||||
Lisp_Object subsec = Fcons (make_fixnum (upfrac), make_fixnum (hz));
|
|
||||||
up = Ftime_add (sec, subsec);
|
|
||||||
}
|
|
||||||
emacs_fclose (fup);
|
|
||||||
}
|
|
||||||
unblock_input ();
|
|
||||||
|
|
||||||
return up;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if defined GNU_LINUX || defined __ANDROID__
|
# if defined GNU_LINUX || defined __ANDROID__
|
||||||
#define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
|
#define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
|
||||||
#define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
|
#define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
|
||||||
|
@ -3702,11 +3670,12 @@ system_process_attributes (Lisp_Object pid)
|
||||||
attrs = put_jiffies (attrs, Qcstime, cstime, hz);
|
attrs = put_jiffies (attrs, Qcstime, cstime, hz);
|
||||||
attrs = put_jiffies (attrs, Qctime, cstime + cutime, hz);
|
attrs = put_jiffies (attrs, Qctime, cstime + cutime, hz);
|
||||||
|
|
||||||
Lisp_Object uptime = get_up_time ();
|
struct timespec bt;
|
||||||
if (!NILP (uptime))
|
if (get_boot_time (&bt) == 0)
|
||||||
{
|
{
|
||||||
|
Lisp_Object boot = Ftime_convert (timespec_to_lisp (bt), hz);
|
||||||
Lisp_Object now = Ftime_convert (Qnil, hz);
|
Lisp_Object now = Ftime_convert (Qnil, hz);
|
||||||
Lisp_Object boot = Ftime_subtract (now, uptime);
|
Lisp_Object uptime = Ftime_subtract (now, boot);
|
||||||
Lisp_Object tstart = time_from_jiffies (start, hz, hz);
|
Lisp_Object tstart = time_from_jiffies (start, hz, hz);
|
||||||
Lisp_Object lstart =
|
Lisp_Object lstart =
|
||||||
Ftime_convert (Ftime_add (boot, tstart), Qnil);
|
Ftime_convert (Ftime_add (boot, tstart), Qnil);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue