static void lxc_monitor_fifo_send(struct lxc_msg *msg, const char *lxcpath) { int fd,ret; char fifo_path[PATH_MAX]; BUILD_BUG_ON(sizeof(*msg) > PIPE_BUF); /* write not guaranteed atomic */ ret = lxc_monitor_fifo_name(lxcpath, fifo_path, sizeof(fifo_path), 0); if (ret < 0) return; process_lock(); fd = open(fifo_path, O_WRONLY); process_unlock(); if (fd < 0) { /* it is normal for this open to fail when there is no monitor * running, so we don't log it */ return; } ret = write(fd, msg, sizeof(*msg)); if (ret != sizeof(*msg)) { process_lock(); close(fd); process_unlock(); SYSERROR("failed to write monitor fifo %s", fifo_path); return; } process_lock(); close(fd); process_unlock(); }
static int lxc_monitord_fifo_create(struct lxc_monitor *mon) { struct flock lk; char fifo_path[PATH_MAX]; int ret; ret = lxc_monitor_fifo_name(mon->lxcpath, fifo_path, sizeof(fifo_path), 1); if (ret < 0) return ret; ret = mknod(fifo_path, S_IFIFO|S_IRUSR|S_IWUSR, 0); if (ret < 0 && errno != EEXIST) { INFO("failed to mknod monitor fifo %s %s", fifo_path, strerror(errno)); return -1; } mon->fifofd = open(fifo_path, O_RDWR); if (mon->fifofd < 0) { unlink(fifo_path); ERROR("failed to open monitor fifo"); return -1; } lk.l_type = F_WRLCK; lk.l_whence = SEEK_SET; lk.l_start = 0; lk.l_len = 0; if (fcntl(mon->fifofd, F_SETLK, &lk) != 0) { /* another lxc-monitord is already running, don't start up */ DEBUG("lxc-monitord already running on lxcpath %s", mon->lxcpath); close(mon->fifofd); return -1; } return 0; }
static int lxc_monitord_fifo_delete(struct lxc_monitor *mon) { char fifo_path[PATH_MAX]; int ret; ret = lxc_monitor_fifo_name(mon->lxcpath, fifo_path, sizeof(fifo_path), 0); if (ret < 0) return ret; unlink(fifo_path); return 0; }
static int lxc_monitord_fifo_create(struct lxc_monitor *mon) { char fifo_path[PATH_MAX]; int ret; ret = lxc_monitor_fifo_name(mon->lxcpath, fifo_path, sizeof(fifo_path), 1); if (ret < 0) return ret; ret = mknod(fifo_path, S_IFIFO|S_IRUSR|S_IWUSR, 0); if (ret < 0) { INFO("monitor fifo %s exists, already running?", fifo_path); return -1; } mon->fifofd = open(fifo_path, O_RDWR); if (mon->fifofd < 0) { unlink(fifo_path); ERROR("failed to open monitor fifo"); return -1; } return 0; }
static void lxc_monitor_fifo_send(struct lxc_msg *msg, const char *lxcpath) { int fd,ret; char fifo_path[PATH_MAX]; BUILD_BUG_ON(sizeof(*msg) > PIPE_BUF); /* write not guaranteed atomic */ ret = lxc_monitor_fifo_name(lxcpath, fifo_path, sizeof(fifo_path), 0); if (ret < 0) return; /* open the fifo nonblock in case the monitor is dead, we don't want * the open to wait for a reader since it may never come. */ fd = open(fifo_path, O_WRONLY|O_NONBLOCK); if (fd < 0) { /* it is normal for this open to fail ENXIO when there is no * monitor running, so we don't log it */ return; } if (fcntl(fd, F_SETFL, O_WRONLY) < 0) { close(fd); return; } ret = write(fd, msg, sizeof(*msg)); if (ret != sizeof(*msg)) { close(fd); SYSERROR("failed to write monitor fifo %s", fifo_path); return; } close(fd); }