From patchwork Thu Mar 1 19:13:14 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: 10252227 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 5460C6037D for ; Thu, 1 Mar 2018 19:13:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442B428524 for ; Thu, 1 Mar 2018 19:13:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38CCA2852C; Thu, 1 Mar 2018 19:13:22 +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 B3E7728524 for ; Thu, 1 Mar 2018 19:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161149AbeCATNU (ORCPT ); Thu, 1 Mar 2018 14:13:20 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:55384 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161105AbeCATNT (ORCPT ); Thu, 1 Mar 2018 14:13:19 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w21JCWca142618; Thu, 1 Mar 2018 19:13:17 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=0owy0jH4CiF2wUEiHYQeEEfOATrQKaal07QSWHkZUF4=; b=CjO8+HnruWbOpiBhqYy2vCoEuf1Fm9Ge6kieVFpahc1SEGqT9T4oOdba1ut717XF8ab2 3hmPJkXoql0wAG8ijXiKLqZhnh1JQWl1SzvHW3AnNNkWneKX51DiFGp2/McIeokgSnGL /YT/XaxRFdfAExdkIZFuu9OQrbsgVSwz59Uj4Km7wpqhQw4Sgrl1qdjb6vsft4kt7uUF 2L1HXgfX8VbCpQUeWxWUHJ0sJofHH1k4ksXAxVYVpg0xEB0U0Y48PIpSSu5JvzqtciFR 0pghid+BAGhul/0WXd1ZxXK+ClxvKyV3QS5ZwcRcoSlp5oWdBLElozkJ58Qw/9B2PsL5 qA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2gepqfr73e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Mar 2018 19:13:17 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w21JDF7c024929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 1 Mar 2018 19:13:16 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w21JDFIa016859; Thu, 1 Mar 2018 19:13:15 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Mar 2018 11:13:15 -0800 Subject: [PATCH 03/16] 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, djwong@kernel.org Date: Thu, 01 Mar 2018 11:13:14 -0800 Message-ID: <151993159412.22223.9791048469399407816.stgit@magnolia> In-Reply-To: <151993157539.22223.6269629008244777191.stgit@magnolia> References: <151993157539.22223.6269629008244777191.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8819 signatures=668682 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-1803010237 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..672f286 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)) && !debug) { + 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");