char errbuf[1024];
ERROR("unixsock plugin: socket failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ return -1;
}
sa.sun_family = AF_UNIX;
ERROR("unixsock plugin: bind failed: %s", errbuf);
close(sock_fd);
sock_fd = -1;
- return (-1);
+ return -1;
}
status = chmod(sa.sun_path, sock_perms);
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
- return (-1);
+ return -1;
}
status = listen(sock_fd, 8);
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
- return (-1);
+ return -1;
}
do {
const char *grpname;
struct group *g;
struct group sg;
- char grbuf[2048];
+
+ long int grbuf_size = sysconf(_SC_GETGR_R_SIZE_MAX);
+ if (grbuf_size <= 0)
+ grbuf_size = sysconf(_SC_PAGESIZE);
+ if (grbuf_size <= 0)
+ grbuf_size = 4096;
+ char grbuf[grbuf_size];
grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME;
g = NULL;
if (status != 0) {
char errbuf[1024];
WARNING("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ sstrerror(status, errbuf, sizeof(errbuf)));
break;
}
if (g == NULL) {
}
} while (0);
- return (0);
+ return 0;
} /* int us_open_socket */
static void *us_handle_client(void *arg) {
close(fdin);
close(fdout);
pthread_exit((void *)1);
- return ((void *)1);
+ return (void *)1;
}
fhout = fdopen(fdout, "w");
fclose(fhin); /* this closes fdin as well */
close(fdout);
pthread_exit((void *)1);
- return ((void *)1);
+ return (void *)1;
}
/* change output buffer to line buffered mode */
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
- return ((void *)0);
+ return (void *)0;
}
while (42) {
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
- return ((void *)1);
+ return (void *)1;
}
if (strcasecmp(fields[0], "getval") == 0) {
fclose(fhout);
pthread_exit((void *)0);
- return ((void *)0);
+ return (void *)0;
} /* void *us_handle_client */
static void *us_server_thread(void __attribute__((unused)) * arg) {
sstrerror(errno, errbuf, sizeof(errbuf)));
}
- return ((void *)0);
+ return (void *)0;
} /* void *us_server_thread */
static int us_config(const char *key, const char *val) {
if (strcasecmp(key, "SocketFile") == 0) {
char *new_sock_file = strdup(val);
if (new_sock_file == NULL)
- return (1);
+ return 1;
sfree(sock_file);
sock_file = new_sock_file;
} else if (strcasecmp(key, "SocketGroup") == 0) {
char *new_sock_group = strdup(val);
if (new_sock_group == NULL)
- return (1);
+ return 1;
sfree(sock_group);
sock_group = new_sock_group;
else
delete_socket = 0;
} else {
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* int us_config */
static int us_init(void) {
/* Initialize only once. */
if (have_init != 0)
- return (0);
+ return 0;
have_init = 1;
loop = 1;
char errbuf[1024];
ERROR("unixsock plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* int us_init */
static int us_shutdown(void) {
plugin_unregister_init("unixsock");
plugin_unregister_shutdown("unixsock");
- return (0);
+ return 0;
} /* int us_shutdown */
void module_register(void) {
plugin_register_init("unixsock", us_init);
plugin_register_shutdown("unixsock", us_shutdown);
} /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 sts=4 tw=78 : */