Browse Source

Allow group id to be set for unix sockets with -g command line parameter

master
Con Kolivas 11 years ago
parent
commit
ebb932691a
  1. 2
      configure.ac
  2. 18
      src/ckpool.c
  3. 3
      src/ckpool.h

2
configure.ac

@ -37,7 +37,7 @@ AC_CHECK_HEADERS(endian.h sys/endian.h arpa/inet.h sys/poll.h syslog.h)
AC_CHECK_HEADERS(alloca.h pthread.h stdio.h math.h signal.h sys/prctl.h) AC_CHECK_HEADERS(alloca.h pthread.h stdio.h math.h signal.h sys/prctl.h)
AC_CHECK_HEADERS(sys/types.h sys/socket.h sys/stat.h linux/un.h netdb.h) AC_CHECK_HEADERS(sys/types.h sys/socket.h sys/stat.h linux/un.h netdb.h)
AC_CHECK_HEADERS(stdint.h netinet/in.h netinet/tcp.h sys/ioctl.h) AC_CHECK_HEADERS(stdint.h netinet/in.h netinet/tcp.h sys/ioctl.h)
AC_CHECK_HEADERS(libpq-fe.h postgresql/libpq-fe.h) AC_CHECK_HEADERS(libpq-fe.h postgresql/libpq-fe.h grp.h)
PTHREAD_LIBS="-lpthread" PTHREAD_LIBS="-lpthread"
MATH_LIBS="-lm" MATH_LIBS="-lm"

18
src/ckpool.c

@ -15,6 +15,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <grp.h>
#include <jansson.h> #include <jansson.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -422,6 +423,7 @@ static bool write_pid(ckpool_t *ckp, const char *path, pid_t pid)
static void create_process_unixsock(proc_instance_t *pi) static void create_process_unixsock(proc_instance_t *pi)
{ {
unixsock_t *us = &pi->us; unixsock_t *us = &pi->us;
ckpool_t *ckp = pi->ckp;
us->path = strdup(pi->ckp->socket_dir); us->path = strdup(pi->ckp->socket_dir);
realloc_strcat(&us->path, pi->sockname); realloc_strcat(&us->path, pi->sockname);
@ -429,6 +431,8 @@ static void create_process_unixsock(proc_instance_t *pi)
us->sockd = open_unix_server(us->path); us->sockd = open_unix_server(us->path);
if (unlikely(us->sockd < 0)) if (unlikely(us->sockd < 0))
quit(1, "Failed to open %s socket", pi->sockname); quit(1, "Failed to open %s socket", pi->sockname);
if (chown(us->path, -1, ckp->gr_gid))
quit(1, "Failed to set %s to group id %d", us->path, ckp->gr_gid);
} }
static void write_namepid(proc_instance_t *pi) static void write_namepid(proc_instance_t *pi)
@ -746,11 +750,14 @@ int main(int argc, char **argv)
memset(&ckp, 0, sizeof(ckp)); memset(&ckp, 0, sizeof(ckp));
ckp.loglevel = LOG_NOTICE; ckp.loglevel = LOG_NOTICE;
while ((c = getopt(argc, argv, "c:kl:n:ps:")) != -1) { while ((c = getopt(argc, argv, "c:g:kl:n:ps:")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
ckp.config = optarg; ckp.config = optarg;
break; break;
case 'g':
ckp.grpnam = optarg;
break;
case 'k': case 'k':
ckp.killold = true; ckp.killold = true;
break; break;
@ -783,6 +790,15 @@ int main(int argc, char **argv)
prctl(PR_SET_NAME, buf, 0, 0, 0); prctl(PR_SET_NAME, buf, 0, 0, 0);
memset(buf, 0, 15); memset(buf, 0, 15);
if (ckp.grpnam) {
struct group *group = getgrnam(ckp.grpnam);
if (!group)
quit(1, "Failed to find group %s", ckp.grpnam);
ckp.gr_gid = group->gr_gid;
} else
ckp.gr_gid = getegid();
if (!ckp.config) { if (!ckp.config) {
ckp.config = strdup(ckp.name); ckp.config = strdup(ckp.name);
realloc_strcat(&ckp.config, ".conf"); realloc_strcat(&ckp.config, ".conf");

3
src/ckpool.h

@ -67,6 +67,9 @@ struct ckpool_instance {
char *name; char *name;
/* Directory where sockets are created */ /* Directory where sockets are created */
char *socket_dir; char *socket_dir;
/* Group ID for unix sockets */
char *grpnam;
gid_t gr_gid;
/* Directory where logs are written */ /* Directory where logs are written */
char *logdir; char *logdir;
/* Logfile */ /* Logfile */

Loading…
Cancel
Save