rsp.ret = 0;
if (log->clear) {
+ int ret;
+ size_t len;
+ char *tmp;
+
/* clear the ringbuffer */
lxc_ringbuf_clear(buf);
goto out;
}
}
+
+ /* rotate the console log file */
+ if (!console->log_path || console->log_rotate == 0)
+ goto out;
+
+ /* be very certain things are kosher */
+ rsp.ret = -EBADF;
+ if (console->log_fd < 0)
+ goto out;
+
+ len = strlen(console->log_path) + sizeof(".1");
+ tmp = alloca(len);
+
+ rsp.ret = -EFBIG;
+ ret = snprintf(tmp, len, "%s.1", console->log_path);
+ if (ret < 0 || (size_t)ret >= len)
+ goto out;
+
+ close(console->log_fd);
+ console->log_fd = -1;
+ rsp.ret = lxc_unpriv(rename(console->log_path, tmp));
+ if (rsp.ret < 0)
+ goto out;
+
+ rsp.ret = lxc_console_create_log_file(console);
} else if (rsp.datalen > 0) {
lxc_ringbuf_move_read_addr(buf, rsp.datalen);
}
if (lxc_safe_uint(value, &lxc_conf->console.log_rotate) < 0)
return -1;
- if (lxc_conf->console.log_rotate > 1)
+ if (lxc_conf->console.log_rotate > 1) {
+ ERROR("The \"lxc.console.rotate\" config key can only be set "
+ "to 0 or 1");
return -1;
+ }
return 0;
}
* This is the console log file. Please note that the console log file is
* (implementation wise not content wise) independent of the console ringbuffer.
*/
-static int lxc_console_create_log_file(struct lxc_console *console)
+int lxc_console_create_log_file(struct lxc_console *console)
{
if (!console->log_path)
return 0;
extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
extern int lxc_console_write_ringbuffer(struct lxc_console *console);
+extern int lxc_console_create_log_file(struct lxc_console *console);
#endif