From patchwork Fri Feb 2 21:36:45 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: 10198141 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 684FE603D7 for ; Fri, 2 Feb 2018 21:36:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56ABE28C05 for ; Fri, 2 Feb 2018 21:36:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AD3628F87; Fri, 2 Feb 2018 21:36:51 +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 C3FF928C05 for ; Fri, 2 Feb 2018 21:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751797AbeBBVgu (ORCPT ); Fri, 2 Feb 2018 16:36:50 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:52216 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751544AbeBBVgt (ORCPT ); Fri, 2 Feb 2018 16:36:49 -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 w12LVqnx112248; Fri, 2 Feb 2018 21:36:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=GRGUk3rLO5h0Nz8cQ9WBv52viFKZOCkX1jwx2mZF9yo=; b=M39DBKIEGWA89FVGFuQgkJupchtRpaq2jkfglfm5sqjIgSV205g1zga9sGO+1HPa1Wfm Ya/0VHVlgT86IRHvgPBJfCs4AnFuGFnJ5Kednbev9mGgzYF8tlztkCAzgfUTDwB/Bsg3 clJ/lCDc5iOsaV+Dz3G9pcEraCGgLg4EkYsbXCsLJHJ5k4eYfCsUyTeenTfABoUzOcUO C6DAVV7YR0S6NnT9VEhjuzEkqCOxyhHlBrKoyJFIfE6H/h2xsd+Fj/Db3idW3NgBk3zb 9OaMEHmgv+GR36w/ZQDnS7/3xcUTSsRh3VjtnC+aEAr9YHUqSfhKPAenJN3qwyQYlZMm hw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2fvxv408s6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Feb 2018 21:36:47 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w12LakmA008255 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 2 Feb 2018 21:36:47 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w12LakMU015925; Fri, 2 Feb 2018 21:36:46 GMT Received: from localhost (/10.159.251.82) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 02 Feb 2018 13:36:46 -0800 Subject: [PATCH 4/4] xfs_scrub: log operational messages when interactive From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Fri, 02 Feb 2018 13:36:45 -0800 Message-ID: <151760740564.29371.3036567105667619649.stgit@magnolia> In-Reply-To: <151760738102.29371.13542858379823064383.stgit@magnolia> References: <151760738102.29371.13542858379823064383.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8793 signatures=668661 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-1802020259 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 17c3699..0326e34 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 * @@ -64,6 +67,12 @@ static const char *err_str[] = { [S_PREEN] = "Optimized", }; +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) { @@ -73,6 +82,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, @@ -110,6 +121,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");