projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8170b5a
)
exec plugin: Replace `getpwnam' with `getpwnam_r'.
author
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Sat, 10 Mar 2007 09:38:05 +0000
(10:38 +0100)
committer
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Sat, 10 Mar 2007 09:38:05 +0000
(10:38 +0100)
src/exec.c
patch
|
blob
|
history
diff --git
a/src/exec.c
b/src/exec.c
index
ee8f8bf
..
63401be
100644
(file)
--- a/
src/exec.c
+++ b/
src/exec.c
@@
-166,20
+166,28
@@
static void submit_gauge (const char *type_instance, gauge_t value)
static void exec_child (program_list_t *pl)
{
static void exec_child (program_list_t *pl)
{
- struct passwd *sp;
int status;
int uid;
char *arg0;
int status;
int uid;
char *arg0;
- /* FIXME: Not thread safe! */
- sp = getpwnam (pl->user);
- if (sp == NULL)
+ struct passwd *sp_ptr;
+ struct passwd sp;
+ char pwnambuf[2048];
+
+ sp_ptr = NULL;
+ status = getpwnam_r (pl->user, &sp, pwnambuf, sizeof (pwnambuf), &sp_ptr);
+ if (status != 0)
+ {
+ syslog (LOG_ERR, "exec plugin: getpwnam_r failed: %s", strerror (status));
+ exit (-1);
+ }
+ if (sp_ptr == NULL)
{
{
- syslog (LOG_ERR, "exec plugin:
getpwnam failed: %s", strerror (errno)
);
+ syslog (LOG_ERR, "exec plugin:
No such user: `%s'", pl->user
);
exit (-1);
}
exit (-1);
}
- uid = sp
->
pw_uid;
+ uid = sp
.
pw_uid;
if (uid == 0)
{
syslog (LOG_ERR, "exec plugin: Cowardly refusing to exec program as root.");
if (uid == 0)
{
syslog (LOG_ERR, "exec plugin: Cowardly refusing to exec program as root.");