projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove; this doesn't belong here.
[gnulib.git]
/
lib
/
getloadavg.c
diff --git
a/lib/getloadavg.c
b/lib/getloadavg.c
index
eb533f1
..
ed079b2
100644
(file)
--- a/
lib/getloadavg.c
+++ b/
lib/getloadavg.c
@@
-1,7
+1,7
@@
/* Get the system load averages.
Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
/* Get the system load averages.
Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
- 1995, 1997, 1999, 2000, 2003 Free Software Foundation, Inc.
+ 1995, 1997, 1999, 2000, 2003
, 2004
Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with gnulib.
Bugs can be reported to bug-gnulib@gnu.org.
NOTE: The canonical source of this file is maintained with gnulib.
Bugs can be reported to bug-gnulib@gnu.org.
@@
-111,9
+111,12
@@
extern int errno;
# include <locale.h>
#endif
#ifndef HAVE_SETLOCALE
# include <locale.h>
#endif
#ifndef HAVE_SETLOCALE
-# define setlocale(Category, Locale)
/* empty */
+# define setlocale(Category, Locale)
((char *) NULL)
#endif
#endif
+#include "cloexec.h"
+#include "xalloc.h"
+
#ifndef HAVE_GETLOADAVG
/* The existing Emacs configuration files define a macro called
#ifndef HAVE_GETLOADAVG
/* The existing Emacs configuration files define a macro called
@@
-481,7
+484,7
@@
static unsigned int samples;
static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
# endif /* DGUX */
static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
# endif /* DGUX */
-#if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
+#
if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE)
/* File descriptor open to /dev/kmem or VMS load ave driver. */
static int channel;
/* Nonzero iff channel is valid. */
/* File descriptor open to /dev/kmem or VMS load ave driver. */
static int channel;
/* Nonzero iff channel is valid. */
@@
-497,7
+500,7
@@
static struct nlist nl[2];
static kvm_t *kd;
# endif /* SUNOS_5 */
static kvm_t *kd;
# endif /* SUNOS_5 */
-#endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
+#
endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
\f
/* Put the 1 minute, 5 minute and 15 minute load averages
into the first NELEM elements of LOADAVG.
\f
/* Put the 1 minute, 5 minute and 15 minute load averages
into the first NELEM elements of LOADAVG.
@@
-592,6
+595,7
@@
getloadavg (double loadavg[], int nelem)
char ldavgbuf[40];
double load_ave[3];
int fd, count;
char ldavgbuf[40];
double load_ave[3];
int fd, count;
+ char *old_locale;
fd = open (LINUX_LDAV_FILE, O_RDONLY);
if (fd == -1)
fd = open (LINUX_LDAV_FILE, O_RDONLY);
if (fd == -1)
@@
-602,10
+606,14
@@
getloadavg (double loadavg[], int nelem)
return -1;
/* The following sscanf must use the C locale. */
return -1;
/* The following sscanf must use the C locale. */
+ old_locale = setlocale (LC_NUMERIC, NULL);
+ if (old_locale)
+ old_locale = xstrdup (old_locale);
setlocale (LC_NUMERIC, "C");
count = sscanf (ldavgbuf, "%lf %lf %lf",
&load_ave[0], &load_ave[1], &load_ave[2]);
setlocale (LC_NUMERIC, "C");
count = sscanf (ldavgbuf, "%lf %lf %lf",
&load_ave[0], &load_ave[1], &load_ave[2]);
- setlocale (LC_NUMERIC, "");
+ setlocale (LC_NUMERIC, old_locale);
+ free (old_locale);
if (count < 1)
return -1;
if (count < 1)
return -1;
@@
-924,12
+932,7
@@
getloadavg (double loadavg[], int nelem)
{
/* Set the channel to close on exec, so it does not
litter any child's descriptor table. */
{
/* Set the channel to close on exec, so it does not
litter any child's descriptor table. */
-# ifdef F_SETFD
-# ifndef FD_CLOEXEC
-# define FD_CLOEXEC 1
-# endif
- (void) fcntl (channel, F_SETFD, FD_CLOEXEC);
-# endif
+ set_cloexec_flag (channel, true);
getloadavg_initialized = 1;
}
# else /* SUNOS_5 */
getloadavg_initialized = 1;
}
# else /* SUNOS_5 */