From patchwork Mon Mar 23 15:16:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1260108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=heIzkNLs; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48mJ1V1rWhz9sQt for ; Tue, 24 Mar 2020 02:18:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9363F85B4A; Mon, 23 Mar 2020 15:18:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wSuVfvRhl-wS; Mon, 23 Mar 2020 15:18:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id D1BC085EAA; Mon, 23 Mar 2020 15:18:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A87DDC1AE2; Mon, 23 Mar 2020 15:18:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 62AA8C0177 for ; Mon, 23 Mar 2020 15:18:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 01F7D204DF for ; Mon, 23 Mar 2020 15:18:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JEmvapCoi6T8 for ; Mon, 23 Mar 2020 15:18:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by silver.osuosl.org (Postfix) with ESMTPS id 45BB1231EF for ; Mon, 23 Mar 2020 15:17:01 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id r3so6019331pls.13 for ; Mon, 23 Mar 2020 08:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BfX7vkaTqxZZnCMEXEZ74yQsEmpCTP6slpeF4qNB+OA=; b=heIzkNLsl3U8LFpmllLN/Q+mR+lFaXB8ms7Yew7Iv692QWOPzJU/UAeBg2/DrZ/87k k74Sk9qbQ6Q1/E1UlJCSYT/eYSndf2jfkBkbb22M3DAhbCixO7/4eMsWqMgdSr1QDkY8 EjGENcGmatWvYAQ8f8xUATru0blMDQAl5Qdau1LUK1CJ18rdgIhWVgCb+GtIxglNTRxY DPlkkGOaOVzGbaXNSk6h6+TBmAXU5EPVL1rpcLOVgxLXJIhpsBHoOVYtbJ+OFy+K5nrs Z47nzj0BhcSfNNoPpiaFpMidJwY5lscFaJFexCYBdplFXDZcO9zQFyisc+Z+KH1HgvoU lbnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BfX7vkaTqxZZnCMEXEZ74yQsEmpCTP6slpeF4qNB+OA=; b=JyjuDI6iWwigOGPeC+3hmc1jvsQDi3NT2HYhgYWySp+xbxGWui1yKhKIaI4kYZ0feH /r93SY64XbikB4z7+GQF/8ncqBxu18cdmysdncEBrzgBs3kEWL1khntHAbdEKWUaUsrv ZJfk6VwKf86OG+FvpBZV+6Y0UEZZSLqoAEusC5HMRPBeTPQbSekrRI+ZY+a0a/Wa3Nk6 BS7LQcBUzoZ3l9puo2XH5f71pKlSCwRo52YRq4kZWApe6xucH02MK0aUso2lSy0l9ZWj Rn6XtqfazbG/pXkOfVEMSfU1vqd88wkgh9GWthj0bIsU5T5ysvj3uvleSRkyc3JVLY8J uXoQ== X-Gm-Message-State: ANhLgQ2ZFcducpv16ux3UYmsKUfsezBbNpnqPC9A0aFAs0jOaJ/h1TsV V7tCI9Dm0Fihk1VYm6SmYQO2ejXh X-Google-Smtp-Source: ADFU+vvybDXqkqu0u+14xrVw5liB03GlC4K52x43FccFRGZVfAC/g8yGtpxkf1UJckp9PHGWoGAtVg== X-Received: by 2002:a17:90b:4d07:: with SMTP id mw7mr25775817pjb.94.1584976619903; Mon, 23 Mar 2020 08:16:59 -0700 (PDT) Received: from sc9-mailhost3.vmware.com (c-76-21-95-192.hsd1.ca.comcast.net. [76.21.95.192]) by smtp.gmail.com with ESMTPSA id e187sm12774003pfe.143.2020.03.23.08.16.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2020 08:16:58 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Mon, 23 Mar 2020 08:16:30 -0700 Message-Id: <1584976590-28419-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [ovs-dev] [PATCH] fatal-signal: Log backtrace when no monitor daemon. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Currently the backtrace logging is only available when monitor daemon is running. This patch enables backtrace logging when no monitor daemon exists. At signal handling context, it detects whether monitor daemon exists. If not, write directly the backtrace to the vlog fd. Note that using VLOG_* macro doesn't work due to it's buffer I/O, so this patch directly issue write() syscall to the file descriptor. Signed-off-by: William Tu --- For some system we stop using monitor daemon and use systemd to monitor ovs-vswitchd, thus need this patch. Example of ovs-vswitchd.log: 2020-03-23T14:42:12.949Z|00049|memory|INFO|175332 kB peak resident set size after 10.0 seconds 2020-03-23T14:42:12.949Z|00050|memory|INFO|handlers:2 ports:3 revalidators:2 rules:8 udpif keys:8 SIGSEGV detected, backtrace: 0x0000000000486969 0x00007f7f5e57f4b0 0x000000000047daa8 0x0000000000504edd 0x00007f7f5f0476ba 0x00007f7f5e65141d 0x0000000000000000 <+0x0> travis: https://travis-ci.org/github/williamtu/ovs-travis/builds/665909423 --- include/openvswitch/vlog.h | 3 +++ lib/daemon-private.h | 1 + lib/daemon-unix.c | 2 +- lib/fatal-signal.c | 22 +++++++++++++++++++++- lib/vlog.c | 6 ++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h index 19da4ab62320..476bf3d6d5b4 100644 --- a/include/openvswitch/vlog.h +++ b/include/openvswitch/vlog.h @@ -143,6 +143,9 @@ void vlog_set_syslog_method(const char *method); /* Configure syslog target. */ void vlog_set_syslog_target(const char *target); +/* Return the log_fd. */ +int vlog_get_fd(void); + /* Initialization. */ void vlog_init(void); void vlog_enable_async(void); diff --git a/lib/daemon-private.h b/lib/daemon-private.h index 4e0667601001..2b90e004235c 100644 --- a/lib/daemon-private.h +++ b/lib/daemon-private.h @@ -20,6 +20,7 @@ extern bool detach; extern char *pidfile; extern int daemonize_fd; +extern bool monitor; char *make_pidfile_name(const char *name); diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c index 7e48630f0e93..e073b894ab49 100644 --- a/lib/daemon-unix.c +++ b/lib/daemon-unix.c @@ -80,7 +80,7 @@ int daemonize_fd = -1; /* --monitor: Should a supervisory process monitor the daemon and restart it if * it dies due to an error signal? */ -static bool monitor; +bool monitor; /* --user: Only root can use this option. Switch to new uid:gid after * initially running as root. */ diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index ba7f5bfd314d..35e26de97b84 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -187,7 +187,27 @@ send_backtrace_to_monitor(void) { dep++; } - ignore(write(daemonize_fd, unw_bt, dep * sizeof(struct unw_backtrace))); + if (monitor) { + ignore(write(daemonize_fd, unw_bt, + dep * sizeof(struct unw_backtrace))); + } else { + /* Since there is no monitor daemon running, write backtrace + * in current process. This is not asyn-signal-safe due to + * use of snprintf(). + */ + char str[] = "SIGSEGV detected, backtrace:\n"; + ignore(write(vlog_get_fd(), str, strlen(str))); + + for (int i = 0; i < dep; i++) { + char line[64]; + + snprintf(line, 64, "0x%016"PRIxPTR" <%s+0x%"PRIxPTR">\n", + unw_bt[i].ip, + unw_bt[i].func, + unw_bt[i].offset); + ignore(write(vlog_get_fd(), line, strlen(line))); + } + } } #else static inline void diff --git a/lib/vlog.c b/lib/vlog.c index 559943d87937..502b33fc831e 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -612,6 +612,12 @@ vlog_set_syslog_target(const char *target) ovs_rwlock_unlock(&pattern_rwlock); } +int +vlog_get_fd(void) +{ + return log_fd; +} + /* Returns 'false' if 'facility' is not a valid string. If 'facility' * is a valid string, sets 'value' with the integer value of 'facility' * and returns 'true'. */