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

Keng-Yu Lin kengyu at canonical.com
Wed Jun 20 15:02:10 UTC 2012


On Wed, Jun 20, 2012 at 7:30 PM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at 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 at 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 at canonical.com>




More information about the fwts-devel mailing list