-static int nc_open_unix_socket (const char *path, /* {{{ */
- const char *group)
-{
- struct sockaddr_un sa;
- int fd;
- char errbuf[1024];
- int status;
-
- if (path == NULL)
- return (-1);
-
- DEBUG ("netcmd plugin: nc_open_unix_socket (path = %s, group = %s);",
- (path != NULL) ? path : "(null)",
- (group != NULL) ? group : "(null)");
- if (strncasecmp ("unix:", path, strlen ("unix:")) == 0)
- path += strlen ("unix:");
-
- fd = socket (PF_UNIX, SOCK_STREAM, 0);
- if (fd < 0)
- {
- ERROR ("netcmd plugin: socket(2) failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
- }
-
- memset (&sa, '\0', sizeof (sa));
- sa.sun_family = AF_UNIX;
- sstrncpy (sa.sun_path, path, sizeof (sa.sun_path));
- /* unlink (sa.sun_path); */
-
- DEBUG ("netcmd plugin: socket path = %s", sa.sun_path);
-
- status = bind (fd, (struct sockaddr *) &sa, sizeof (sa));
- if (status != 0)
- {
- ERROR ("netcmd plugin: bind failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- close (fd);
- fd = -1;
- return (-1);
- }
-
- /* FIXME: Copy unix_sock_perms stuff from unixsock. */
- chmod (sa.sun_path, unix_sock_perms);
-
- status = listen (fd, 8);
- if (status != 0)
- {
- ERROR ("netcmd plugin: listen failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- close (fd);
- fd = -1;
- return (-1);
- }
-
- /* If `group' is not NULL, `chown' the file. */
- while (group != NULL) /* {{{ */
- {
- struct group *g;
- struct group sg;
- char grbuf[2048];
-
- g = NULL;
- status = getgrnam_r (group, &sg, grbuf, sizeof (grbuf), &g);
- if (status != 0)
- {
- WARNING ("netcmd plugin: getgrnam_r (%s) failed: %s", group,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- break;
- }
-
- if (g == NULL)
- {
- WARNING ("netcmd plugin: No such group: `%s'", group);
- break;
- }
-
- status = chown (sa.sun_path, (uid_t) -1, g->gr_gid);
- if (status != 0)
- {
- WARNING ("netcmd plugin: chown (%s, -1, %i) failed: %s",
- sa.sun_path, (int) g->gr_gid,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- }
-
- break;
- } /* }}} while (group != NULL) */
-
- status = nc_register_fd (fd, sa.sun_path);
- if (status != 0)
- {
- close (fd);
- unlink (sa.sun_path);
- return (status);
- }
-
- return (0);
-} /* }}} int nc_open_unix_socket */
-
-static int nc_open_network_socket (const char *node, /* {{{ */
- const char *service)