From: Florian Forster Date: Sat, 10 Mar 2007 09:49:18 +0000 (+0100) Subject: unixsock plugin: Replace `getgrnam' with `getgrnam_r'. X-Git-Tag: collectd-4.0.0-rc4~77 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=27eb0061898f9e90e70546d361baae2151db8f61;p=collectd.git unixsock plugin: Replace `getgrnam' with `getgrnam_r'. --- diff --git a/src/unixsock.c b/src/unixsock.c index 12ebc099..b4af8b38 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -387,21 +387,27 @@ static int us_open_socket (void) do { + char *grpname; struct group *g; + struct group sg; + char grbuf[2048]; - errno = 0; - g = getgrnam ((sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME); + grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME; + g = NULL; - if (errno != 0) + status = getgrnam_r (grpname, &sg, grbuf, sizeof (grbuf), &g); + if (status != 0) { - syslog (LOG_WARNING, "unixsock plugin: getgrnam (%s) failed: %s", - (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME, - strerror (errno)); + syslog (LOG_WARNING, "unixsock plugin: getgrnam_r (%s) failed: %s", + grpname, strerror (status)); break; } - if (g == NULL) + { + syslog (LOG_WARNING, "unixsock plugin: No such group: `%s'", + grpname); break; + } if (chown ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (uid_t) -1, g->gr_gid) != 0)