From patchwork Thu Feb 1 18:17:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10195835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1190660247 for ; Thu, 1 Feb 2018 18:17:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08BD728C82 for ; Thu, 1 Feb 2018 18:17:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEB7B28C85; Thu, 1 Feb 2018 18:17:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8038428C82 for ; Thu, 1 Feb 2018 18:17:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753004AbeBASRh (ORCPT ); Thu, 1 Feb 2018 13:17:37 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:35472 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbeBASRg (ORCPT ); Thu, 1 Feb 2018 13:17:36 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w11IGsYu159082; Thu, 1 Feb 2018 18:17:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=6nwWQJuC3/6w8Y/RNS61Ai928BADJs4XE4s4gWY64rI=; b=csIf4+pkPvx9q2wjlOw4JTcnXpkUSVaTDrNoIB0nSZY7rET9YaICySEKWDhqMq+DXimX bccNHyTRlLiFRvHIXFWbPyUFANO7Y6/TfLwabGU9jiMtnD2kesamVgdcRmfrpvabojDv +9zCawyiY6pQH+xkI/AHITOyow6CjS4gHccgIjlvcFwOTIRyVKIDPHmCdzJ5757z4NuY uaRvXd60+swHzyh+EZ3kh06Nszq+sUV6C0gC3dhy4d9OT9NLPqfJhzQ3CqnqbfyzoVoU nVhnzduWosH9F4r2UVtpBLsCzmVdmQpZ4tDbTzKTirfNYEMMnFsvRKpO49ShPWk+Wrki eQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2fv1xaa4xh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Feb 2018 18:17:33 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w11IHWtl014567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 1 Feb 2018 18:17:33 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w11IHW9U007982; Thu, 1 Feb 2018 18:17:32 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Feb 2018 10:17:32 -0800 Date: Thu, 1 Feb 2018 10:17:31 -0800 From: "Darrick J. Wong" To: Eric Sandeen Cc: xfs Subject: [PATCH] xfs_scrub: log operational messages when interactive Message-ID: <20180201181731.GQ4849@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8792 signatures=668660 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802010234 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Record the output of an interactive session in the system log so that future support requests can get a better picture of what happened. Signed-off-by: Darrick J. Wong --- scrub/common.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/scrub/common.c b/scrub/common.c index 18171d1..7af7677 100644 --- a/scrub/common.c +++ b/scrub/common.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "platform_defs.h" #include "xfs.h" #include "xfs_fs.h" @@ -29,6 +30,8 @@ #include "common.h" #include "progress.h" +extern char *progname; + /* * Reporting Status to the Console * @@ -62,6 +65,12 @@ static const char *err_str[] = { [S_INFO] = "Info", }; +static int log_level[] = { + [S_ERROR] = LOG_ERR, + [S_WARN] = LOG_WARNING, + [S_INFO] = LOG_INFO, +}; + /* If stream is a tty, clear to end of line to clean up progress bar. */ static inline const char *stream_start(FILE *stream) { @@ -71,6 +80,8 @@ static inline const char *stream_start(FILE *stream) } /* Print a warning string and some warning text. */ +#define LOG_BUFSZ 4096 +#define LOGNAME_BUFSZ 256 void __str_out( struct scrub_ctx *ctx, @@ -103,6 +114,32 @@ __str_out( va_end(args); } + /* If we're running interactively, log the message to syslog too. */ + if (isatty(fileno(stdin))) { + char logname[LOGNAME_BUFSZ]; + + snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, + ctx->mntpoint); + openlog(logname, LOG_PID, LOG_DAEMON); + + if (error) { + syslog(LOG_ERR, "%s: %s: %s.", + _(err_str[level]), descr, + strerror_r(error, buf, DESCR_BUFSZ)); + } else { + char buf[LOG_BUFSZ]; + int sz; + + sz = snprintf(buf, LOG_BUFSZ, "%s: %s: ", + _(err_str[level]), descr); + va_start(args, format); + vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args); + va_end(args); + syslog(log_level[level], "%s", buf); + } + closelog(); + } + if (debug) fprintf(stream, _(" (%s line %d)"), file, line); fprintf(stream, "\n");