Write the read data into a given logfile and not only into stdout.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "options.h"
#include "baud.h"
#include "options.h"
#include "baud.h"
{
struct epoll_event ev;
struct plotter_options options;
{
struct epoll_event ev;
struct plotter_options options;
+ int fd, baud, ret, out_fd = STDOUT_FILENO;
int epoll_fd;
char buf[256];
int epoll_fd;
char buf[256];
if (baud != options.baud_rate) {
pr_err("Failed to set baudrate to %d, only got %d\n",
options.baud_rate, baud);
if (baud != options.baud_rate) {
pr_err("Failed to set baudrate to %d, only got %d\n",
options.baud_rate, baud);
+ ret = 1;
+ goto out;
+ }
+
+ if (options.output_path) {
+ pr_debug("Opening %s for writing the log file\n",
+ options.output_path);
+
+ out_fd = open(options.output_path,
+ O_CREAT | O_APPEND | O_WRONLY, 0664);
+ if (out_fd < 0) {
+ pr_err("Failed to open file %s for writing: %m\n",
+ options.output_path);
+ ret = 1;
+ goto out;
+ }
}
epoll_fd = epoll_create(1);
}
epoll_fd = epoll_create(1);