Message ID | 1340191829-27444-7-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
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>
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>
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);