lldp_ARG_WITH([privsep-chroot], [Which directory to use to chroot lldpd], [${runstatedir}/lldpd])
lldp_ARG_WITH([lldpd-ctl-socket], [Path to socket for communication with lldpd], [${runstatedir}/lldpd.socket])
lldp_ARG_WITH([lldpd-pid-file], [Path to lldpd PID file], [${runstatedir}/lldpd.pid])
-lldp_ARG_WITH([lldpcli-lock-dir], [Which directory to use to put locks], [${localstatedir}/lock])
# Netlink
lldp_ARG_WITH_UNQUOTED([netlink-max-receive-bufsize], [Netlink maximum receive buffer size], [1024*1024])
if (best->execute) {
if (needlock) {
if (lockfd == -1) {
- char *_ctlname = NULL;
if (lockname == NULL &&
- ((_ctlname = strdup(ctlname)) == NULL ||
- asprintf(&lockname, LLDPCLI_LOCK_DIR "/%s.lck",
- basename(_ctlname)) == -1)) {
+ asprintf(&lockname, "%s.lock",
+ ctlname) == -1) {
log_warnx("lldpctl",
"not enough memory to build lock filename");
rc = -1;
- free(_ctlname);
goto end;
}
- free(_ctlname);
log_debug("lldpctl", "open %s for locking", lockname);
- if ((lockfd = open(lockname,
- O_CREAT|O_RDWR|O_NOFOLLOW, 0666)) == -1) {
+ if ((lockfd = open(lockname, O_RDWR)) == -1) {
log_warn("lldpctl", "cannot open lock %s", lockname);
rc = -1;
goto end;
static void
lldpd_exit(struct lldpd *cfg)
{
+ char *lockname = NULL;
struct lldpd_hardware *hardware, *hardware_next;
log_debug("main", "exit lldpd");
TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries)
lldpd_send_shutdown(hardware);
+ if (asprintf(&lockname, "%s.lock", cfg->g_ctlname) != -1) {
+ priv_ctl_cleanup(lockname);
+ free(lockname);
+ }
close(cfg->g_ctl);
priv_ctl_cleanup(cfg->g_ctlname);
log_debug("main", "cleanup hardware information");
log_warn("main", "unable to chmod control socket");
#endif
+ /* Create associated advisory lock file */
+ char *lockname = NULL;
+ int fd;
+ if (asprintf(&lockname, "%s.lock", ctlname) == -1)
+ fatal("main", "cannot build lock name");
+ if ((fd = open(lockname, O_CREAT|O_RDWR, 0000)) == -1)
+ fatal("main", "cannot create lock file for control socket");
+ close(fd);
+#ifdef ENABLE_PRIVSEP
+ if (chown(lockname, uid, gid) == -1)
+ log_warn("main", "unable to chown control socket lock");
+ if (chmod(lockname,
+ S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IWGRP | S_IXGRP) == -1)
+ log_warn("main", "unable to chmod control socket lock");
+#endif
+ free(lockname);
+
/* Disable SIGPIPE */
signal(SIGPIPE, SIG_IGN);