From patchwork Wed Jun 20 11:30:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6/6] lib: fwts_log: handle special logfile names Date: Wed, 20 Jun 2012 01:30:29 -0000 From: Colin King X-Patchwork-Id: 166016 Message-Id: <1340191829-27444-7-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com From: Colin Ian King Handle the case where user has specified a special log file name such as a char special device, like /dev/null, a named pipe, a name socket or symbolic link. In these cases, don't append a filename suffix but just return the filename as is. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Alex Hung --- src/lib/src/fwts_log.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c index d1f7fe6..55ebd06 100644 --- a/src/lib/src/fwts_log.c +++ b/src/lib/src/fwts_log.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -337,6 +339,20 @@ static char *fwts_log_filename(const char *filename, fwts_log_type type) size_t suffix_len; size_t trunc_len; size_t filename_len; + struct stat stat_buf; + + /* + * If the user specified a char special file, like /dev/null + * or a named pipe, socket or symlink we should just return + * that instead. + */ + if (stat(filename, &stat_buf) == 0) { + if (S_ISCHR(stat_buf.st_mode) || + S_ISFIFO(stat_buf.st_mode) || + S_ISSOCK(stat_buf.st_mode) || + S_ISLNK(stat_buf.st_mode)) + return strdup(filename); + } suffix = fwts_log_type_filename_suffix(type); suffix_len = strlen(suffix);