dev_t alr_rdev;
};
+static unsigned int alr_log_count;
static struct alr_log *alr_log[1 << 20]; /* 20 == MINORBITS */
static int oal_version; /* FIXME ... major version, minor version */
static __u32 alr_filter = 0xffffffff; /* no filter by default */
free(al->alr_buf);
al->alr_buf = NULL;
al->alr_buf_size = 0;
+ alr_log_count--;
}
/* Add an access log (identified by path) to the epoll set. */
FATAL("cannot allocate struct alr_dev of size %zu: %s\n",
sizeof(*al), strerror(errno));
+ alr_log_count++;
al->alr_dev.alr_io = &alr_log_io;
al->alr_dev.alr_destroy = &alr_log_destroy;
al->alr_dev.alr_fd = fd;
return (rc < 0) ? ALR_EXIT_FAILURE : ALR_OK;
}
+/* batch file (stdout) poll callback: detect remote pipe close and exit. */
+static int alr_batch_file_io(int epoll_fd, struct alr_dev *ad, unsigned int mask)
+{
+ TRACE("%s\n", __func__);
+ DEBUG_U(mask);
+
+ if (mask & EPOLLHUP)
+ return ALR_EXIT_SUCCESS;
+
+ if (mask & EPOLLERR)
+ return ALR_EXIT_FAILURE;
+
+ return ALR_OK;
+}
+
static struct alr_dev *alr_dev_create(int epoll_fd, int fd, const char *name,
+ uint32_t events,
int (*io)(int, struct alr_dev *, unsigned int),
void (*destroy)(struct alr_dev *))
{
alr->alr_fd = fd;
struct epoll_event event = {
- .events = EPOLLIN | EPOLLHUP,
+ .events = events,
.data.ptr = alr,
};
" -F, --batch-fraction=P set batch printing fraction to P/100\n"
" -i, --batch-interval=INTERVAL print batch every INTERVAL seconds\n"
" -o, --batch-offset=OFFSET print batch at OFFSET seconds\n"
+" -e, --exit-on-close exit on close of all log devices\n"
" -I, --mdt-index-filter=INDEX set log MDT index filter to INDEX\n"
" -h, --help display this help and exit\n"
" -l, --list print YAML list of available access logs\n"
const char ctl_path[] = "/dev/"LUSTRE_ACCESS_LOG_DIR_NAME"/control";
struct alr_dev *alr_signal = NULL;
struct alr_dev *alr_batch_timer = NULL;
+ struct alr_dev *alr_batch_file_hup = NULL;
struct alr_dev *alr_ctl = NULL;
+ int exit_on_close = 0;
time_t batch_interval = 0;
time_t batch_offset = 0;
unsigned int m;
{ .name = "batch-fraction", .has_arg = required_argument, .val = 'F', },
{ .name = "batch-interval", .has_arg = required_argument, .val = 'i', },
{ .name = "batch-offset", .has_arg = required_argument, .val = 'o', },
+ { .name = "exit-on-close", .has_arg = no_argument, .val = 'e', },
{ .name = "mdt-index-filter", .has_arg = required_argument, .val = 'I' },
{ .name = "debug", .has_arg = optional_argument, .val = 'd', },
{ .name = "help", .has_arg = no_argument, .val = 'h', },
{ .name = NULL, },
};
- while ((c = getopt_long(argc, argv, "d::f:F:hi:I:ls:t::", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "d::ef:F:hi:I:ls:t::", options, NULL)) != -1) {
switch (c) {
+ case 'e':
+ exit_on_close = 1;
+ break;
case 'f':
alr_batch_file_path = optarg;
break;
if (signal_fd < 0)
FATAL("cannot create signalfd: %s\n", strerror(errno));
- alr_signal = alr_dev_create(epoll_fd, signal_fd, "signal", &alr_signal_io, NULL);
+ alr_signal = alr_dev_create(epoll_fd, signal_fd, "signal", EPOLLIN,
+ &alr_signal_io, NULL);
if (alr_signal == NULL)
FATAL("cannot register signalfd: %s\n", strerror(errno));
FATAL("cannot arm timerfd: %s\n", strerror(errno));
alr_batch_timer = alr_dev_create(epoll_fd, timer_fd, "batch_timer",
- &alr_batch_timer_io, NULL);
+ EPOLLIN, &alr_batch_timer_io, NULL);
if (alr_batch_timer == NULL)
FATAL("cannot register batch timerfd: %s\n", strerror(errno));
timer_fd = -1;
+ int batch_fd = dup(fileno(alr_batch_file));
+ if (batch_fd < 0)
+ FATAL("cannot duplicate batch file descriptor: %s\n",
+ strerror(errno));
+
+ /* We pass events = 0 since we only care about EPOLLHUP. */
+ alr_batch_file_hup = alr_dev_create(epoll_fd, batch_fd, "batch_file", 0,
+ &alr_batch_file_io, NULL);
+ if (alr_batch_file_hup == NULL)
+ FATAL("cannot register batch file HUP: %s\n", strerror(errno));
+
+ batch_fd = -1;
+
/* Open control device. */
int ctl_fd = open(ctl_path, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
if (ctl_fd < 0)
DEBUG_D(oal_log_major);
/* Add control device to epoll set. */
- alr_ctl = alr_dev_create(epoll_fd, ctl_fd, "control", &alr_ctl_io, NULL);
+ alr_ctl = alr_dev_create(epoll_fd, ctl_fd, "control", EPOLLIN,
+ &alr_ctl_io, NULL);
if (alr_ctl == NULL)
FATAL("cannot register control device: %s\n", strerror(errno));
break;
}
}
+
+ if (exit_on_close && alr_log_count == 0) {
+ DEBUG("no open logs devices, exiting\n");
+ exit_status = EXIT_SUCCESS;
+ goto out;
+ }
} while (!list_info);
exit_status = EXIT_SUCCESS;
alr_dev_free(epoll_fd, alr_ctl);
alr_dev_free(epoll_fd, alr_signal);
alr_dev_free(epoll_fd, alr_batch_timer);
+ alr_dev_free(epoll_fd, alr_batch_file_hup);
close(epoll_fd);
alr_batch_destroy(alr_batch);