memset(&s_un, 0, sizeof(s_un));
s_un.sun_family = AF_UNIX;
- strlcpy(s_un.sun_path, LDPD_SOCKET, sizeof(s_un.sun_path));
+ strlcpy(s_un.sun_path, ctl_sock_path, sizeof(s_un.sun_path));
- if (unlink(LDPD_SOCKET) == -1)
+ if (unlink(ctl_sock_path) == -1)
if (errno != ENOENT) {
- log_warn("%s: unlink %s", __func__, LDPD_SOCKET);
+ log_warn("%s: unlink %s", __func__, ctl_sock_path);
close(fd);
return (-1);
}
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
- log_warn("%s: bind: %s", __func__, LDPD_SOCKET);
+ log_warn("%s: bind: %s", __func__, ctl_sock_path);
close(fd);
umask(old_umask);
return (-1);
}
umask(old_umask);
- if (chmod(LDPD_SOCKET, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
+ if (chmod(ctl_sock_path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
log_warn("%s: chmod", __func__);
close(fd);
- (void)unlink(LDPD_SOCKET);
+ (void)unlink(ctl_sock_path);
return (-1);
}
{
accept_del(control_fd);
close(control_fd);
- unlink(LDPD_SOCKET);
+ unlink(ctl_sock_path);
}
/* ARGSUSED */
static void ldpd_shutdown(void);
static pid_t start_child(enum ldpd_process, char *, int,
- const char *, const char *);
+ const char *, const char *, const char *);
static int main_dispatch_ldpe(struct thread *);
static int main_dispatch_lde(struct thread *);
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
/* VTY Socket prefix */
char vty_sock_path[MAXPATHLEN] = LDP_VTYSH_PATH;
+/* CTL Socket path */
+char ctl_sock_path[MAXPATHLEN] = LDPD_SOCKET;
+
/* LDPd options. */
#define OPTION_VTYSOCK 1000
+#define OPTION_CTLSOCK 1001
static struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
{ "vty_addr", required_argument, NULL, 'A'},
{ "vty_port", required_argument, NULL, 'P'},
{ "vty_socket", required_argument, NULL, OPTION_VTYSOCK},
+ { "ctl_socket", required_argument, NULL, OPTION_CTLSOCK},
{ "user", required_argument, NULL, 'u'},
{ "group", required_argument, NULL, 'g'},
{ "version", no_argument, NULL, 'v'},
-A, --vty_addr Set vty's bind address\n\
-P, --vty_port Set vty's port number\n\
--vty_socket Override vty socket path\n\
+ --ctl_socket Override ctl socket path\n\
-u, --user User to run as\n\
-g, --group Group to run as\n\
-v, --version Print program version\n\
char *vty_addr = NULL;
int vty_port = LDP_VTY_PORT;
char *vty_sock_name;
+ char *ctl_sock_custom_path = NULL;
+ char *ctl_sock_name;
int daemon_mode = 0;
const char *user = NULL;
const char *group = NULL;
case OPTION_VTYSOCK:
set_socket_path(vty_sock_path, LDP_VTYSH_PATH, optarg, sizeof (vty_sock_path));
break;
+ case OPTION_CTLSOCK:
+ ctl_sock_name = strrchr(LDPD_SOCKET, '/');
+ if (ctl_sock_name)
+ /* skip '/' */
+ ctl_sock_name++;
+ else
+ /*
+ * LDPD_SOCKET configured as relative path
+ * during config? Should really never happen for
+ * sensible config
+ */
+ ctl_sock_name = (char *)LDPD_SOCKET;
+ ctl_sock_custom_path = optarg;
+ strlcpy(ctl_sock_path, ctl_sock_custom_path,
+ sizeof(ctl_sock_path));
+ strlcat(ctl_sock_path, "/", sizeof(ctl_sock_path));
+ strlcat(ctl_sock_path, ctl_sock_name,
+ sizeof(ctl_sock_path));
+ break;
case 'u':
user = optarg;
break;
if (lflag)
lde(user, group);
else if (eflag)
- ldpe(user, group);
+ ldpe(user, group, ctl_sock_path);
master = thread_master_create();
/* start children */
lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
- pipe_parent2lde[1], user, group);
+ pipe_parent2lde[1], user, group, ctl_sock_custom_path);
ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
- pipe_parent2ldpe[1], user, group);
+ pipe_parent2ldpe[1], user, group, ctl_sock_custom_path);
/* drop privileges */
if (user)
static pid_t
start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
- const char *group)
+ const char *group, const char *ctl_sock_custom_path)
{
- char *argv[7];
+ char *argv[9];
int argc = 0;
pid_t pid;
argv[argc++] = (char *)"-g";
argv[argc++] = (char *)group;
}
+ if (ctl_sock_custom_path) {
+ argv[argc++] = (char *)"--ctl_socket";
+ argv[argc++] = (char *)ctl_sock_custom_path;
+ }
argv[argc++] = NULL;
execvp(argv0, argv);