From: Florian Forster Date: Sat, 10 Mar 2007 09:38:05 +0000 (+0100) Subject: exec plugin: Replace `getpwnam' with `getpwnam_r'. X-Git-Tag: collectd-4.0.0-rc4~78 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=18e6a1883e6eb739d448e60b9028334c83e0f4d6;p=collectd.git exec plugin: Replace `getpwnam' with `getpwnam_r'. --- diff --git a/src/exec.c b/src/exec.c index ee8f8bf9..63401bec 100644 --- 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) { - struct passwd *sp; 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); } - uid = sp->pw_uid; + uid = sp.pw_uid; if (uid == 0) { syslog (LOG_ERR, "exec plugin: Cowardly refusing to exec program as root.");