Patchwork [6/6] lib: fwts_log: handle special logfile names

login
register
mail settings
Submitter Colin King
Date June 20, 2012, 11:30 a.m.
Message ID <1340191829-27444-7-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/166016/
State Accepted
Headers show

Comments

Colin King - June 20, 2012, 11:30 a.m.
From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
 src/lib/src/fwts_log.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Keng-Yu Lin - June 20, 2012, 3:02 p.m.
On Wed, Jun 20, 2012 at 7:30 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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 <colin.king@canonical.com>
> ---
>  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 <string.h>
>  #include <unistd.h>
>  #include <sys/ioctl.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
>  #include <time.h>
>  #include <ctype.h>
>
> @@ -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);
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung - June 21, 2012, 1:04 a.m.
On 06/20/2012 07:30 PM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> 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<colin.king@canonical.com>
> ---
>   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<string.h>
>   #include<unistd.h>
>   #include<sys/ioctl.h>
> +#include<sys/types.h>
> +#include<sys/stat.h>
>   #include<time.h>
>   #include<ctype.h>
>
> @@ -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);
Acked-by: Alex Hung <alex.hung@canonical.com>

Patch

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 <string.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <time.h>
 #include <ctype.h>
 
@@ -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);