Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1696345rwd; Thu, 25 May 2023 17:07:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6VRnFW1B7iFgirDOUuBAWgWRatVwAC7Xku7WMDfbTPefzuJxd0zqGMUORDunUi7a4fk1Gr X-Received: by 2002:a17:902:e9cd:b0:1a6:dba5:2e60 with SMTP id 13-20020a170902e9cd00b001a6dba52e60mr417080plk.25.1685059625877; Thu, 25 May 2023 17:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685059625; cv=none; d=google.com; s=arc-20160816; b=M8xvZaGOUS/5+yKeQS11v9IblDgtw8NaTgJAOTpQ5/SIZWLumYbWyjOAB7CzsBi2Lg i0Q8MBvy9tBPHA3QINgPeiLFUV0EeBwXMuR2rIXwV16rR7fhgwSKFloble5vtjgaAn76 BejRvNtLKkXRaFf7qgbFuKGwWwy3ywnmBH1bB9uMfcYwRTKsECpZAKKToCQLM2sTxz5a k1d2jJdhJ3im2iXTMRZPifV9sbt6WZ6WI/rEuQ9gLPltTTet94y/0iTVT7gbsNZBuV0U KNB8MhOiUa/OYeRlL5Oyg59a+bpCPRfCRdwcRq7IL3vjUUyAPB6BJXgdoYD7caewbPGv 53Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=Hv3+9h2lVSiuHdkggdtIDHwDCe3yb3IHg4Jg3yIUd48=; b=nYU/sydcN7gsi5k+oNmsqQ8loAXzk3S8pUjkrokMQFJfICF3i9c55/KRrffQ/HTu5y zal4BJLmrhAo+pEuNdUyqM4P/mxD/rwThmsao+hzuUnYqfBg0eOpWCHmfa6azSdntd5V GVoZZZ2Aw5k6dBM/ET5fOsSHaaVU6nHY6zVOOkewHMxkXuOvOq1m62T1L99bvuK3EKkg EWguVnnJvnsRWGqoo9Vd44BAe+YAgsR+liD8UHptvCqk8tjhy7nvlNeAl7CNyYGfocxY zMvQvVoJLSIUML3NxYCB/s0CiZcapgXq2+/YdowPHGWgjmIhbN+QW5+lYnmWf+zyWLyM G8vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YsZplhjJ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m64-20020a633f43000000b0053eef99f924si2357301pga.261.2023.05.25.17.06.50; Thu, 25 May 2023 17:07:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YsZplhjJ; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbjEYXq1 (ORCPT + 99 others); Thu, 25 May 2023 19:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbjEYXq0 (ORCPT ); Thu, 25 May 2023 19:46:26 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38A92134 for ; Thu, 25 May 2023 16:46:25 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-255401f977dso224285a91.2 for ; Thu, 25 May 2023 16:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685058384; x=1687650384; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Hv3+9h2lVSiuHdkggdtIDHwDCe3yb3IHg4Jg3yIUd48=; b=YsZplhjJemigEa+/0dQ94vZnYBv6k6+frTubTXMCcTb7Rcu0NoILdUg//ymqNLSOhP Y2GHabYiaId2O/4iMurRfpcu9yEUTIO06ZaJnfn+aJxWnL4Acder2WlDhAfpJvcjOWKD ehYyxO3PgtdLhcxCAB1DurTTly6NDv70+L+ozd0uBRIJDoLw3CAD6w+/8M0o4PENGccy JU5XRSX57sj3H4FMt0yrxXKRCkK8p7LYKbnRMqSJzjex6AWCTd0fdDYaBbGOmTbZcDNn 5arslI6T3RT52vj+yXh2IYlEAa0jvyhJ6IV6JyFXd0VHEECmD2go0JL2DaIHtAjzyd37 Nv5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685058384; x=1687650384; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hv3+9h2lVSiuHdkggdtIDHwDCe3yb3IHg4Jg3yIUd48=; b=d4NK+H9JvE0Fo3GXwgltv3JQb+GGq0cavlY97pDC2cJ2BQNr/qesO6MvPpunxj/UFk vpUP3VuEbVQ1jhaXFRuCc4FsLpoknHu0g913DmSVhpi/xW0EYvYXXLGNxXpJKnAwHti9 NAZBjFCBiNXC4u+nddy7AS5lsHLNNX6WxjfSt1/nLy7mXt8S8yMAgPaExYG0q5Cd6qKr pAac65eMHpWn6fER2quh4Zq9H7ZU2jAQxzVJjonIeTVaMbJl/wgpQTWbKIYN2nsPk/lc fAYojp/KoMuHSS0snEm3CsFsD4XL2J2c57lWtDl60NSPcBgbf0FsrR3E0uawf9LuMRVo Gogg== X-Gm-Message-State: AC+VfDyPHOJwVMzOywCvioMJChMLYY5Ni+gkHbb4gbSl3GvAwNxzXxXf uu0eO7ukdTmV1js8aGc1JYMzK6SbWDE= X-Received: by 2002:a17:90a:cf85:b0:247:2152:6391 with SMTP id i5-20020a17090acf8500b0024721526391mr444613pju.17.1685058383785; Thu, 25 May 2023 16:46:23 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id r2-20020a654982000000b0050bc4ca9024sm1479473pgs.65.2023.05.25.16.46.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 16:46:22 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] monitor: Print process information Date: Thu, 25 May 2023 16:46:21 -0700 Message-Id: <20230525234621.3597759-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This prints the process information when available: bluetoothd[35]: @ MGMT Command: Rea.. (0x0001) plen 0 {0x0001} @ MGMT Event: Command Complete (0x0001) plen 6 {0x0001} Read Management Version Information (0x0001) plen 3 --- monitor/packet.c | 56 +++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index b492b8a757a5..04eb70141e68 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -315,13 +315,33 @@ void packet_set_msft_evt_prefix(const uint8_t *prefix, uint8_t len) memcpy(index_list[index_current].msft_evt_prefix, prefix, len); } +static void cred_pid(struct ucred *cred, char *str, size_t len) +{ + char *path = alloca(24); + char line[128]; + FILE *fp; + + snprintf(path, 23, "/proc/%u/comm", cred->pid); + + fp = fopen(path, "re"); + if (fp) { + if (fgets(line, sizeof(line), fp)) { + line[strcspn(line, "\r\n")] = '\0'; + snprintf(str, len, "%s[%u]", line, cred->pid); + } else + snprintf(str, len, "[%u]", cred->pid); + fclose(fp); + } else + snprintf(str, len, "[%u]", cred->pid); +} + static void print_packet(struct timeval *tv, struct ucred *cred, char ident, uint16_t index, const char *channel, const char *color, const char *label, const char *text, const char *extra) { int col = num_columns(); - char line[256], ts_str[96]; + char line[256], ts_str[96], pid_str[140]; int n, ts_len = 0, ts_pos = 0, len = 0, pos = 0; static size_t last_frame; @@ -418,7 +438,13 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, pos += n; } - n = sprintf(line + pos, "%c %s", ident, label ? label : ""); + if (cred) { + cred_pid(cred, pid_str, sizeof(pid_str)); + n = sprintf(line + pos, "%s: %c %s", pid_str, ident, + label ? label : ""); + } else + n = sprintf(line + pos, "%c %s", ident, label ? label : ""); + if (n > 0) { pos += n; len += n; @@ -12091,7 +12117,6 @@ void packet_user_logging(struct timeval *tv, struct ucred *cred, const char *ident, const void *data, uint16_t size) { - char pid_str[140]; const char *label; const char *color; @@ -12117,26 +12142,7 @@ void packet_user_logging(struct timeval *tv, struct ucred *cred, } if (cred) { - char *path = alloca(24); - char line[128]; - FILE *fp; - - snprintf(path, 23, "/proc/%u/comm", cred->pid); - - fp = fopen(path, "re"); - if (fp) { - if (fgets(line, sizeof(line), fp)) { - line[strcspn(line, "\r\n")] = '\0'; - snprintf(pid_str, sizeof(pid_str), "%s[%u]", - line, cred->pid); - } else - snprintf(pid_str, sizeof(pid_str), "%u", - cred->pid); - fclose(fp); - } else - snprintf(pid_str, sizeof(pid_str), "%u", cred->pid); - - label = pid_str; + label = NULL; } else { if (ident) label = ident; @@ -12146,8 +12152,8 @@ void packet_user_logging(struct timeval *tv, struct ucred *cred, if (ident && (ident[0] == '<' || ident[0] == '>')) { packet_decode(tv, cred, ident[0], index, color, - label == ident ? &ident[2] : label, - data, size); + label == ident ? &ident[2] : label, + data, size); return; } -- 2.40.1