Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmgTL-0003gS-BB for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Nov 2021 18:12:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mmgTJ-0004Zs-2f for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Nov 2021 18:12:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmgTI-0004Zj-Pa for pgsql-hackers@lists.postgresql.org; Mon, 15 Nov 2021 18:12:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmgTG-0004iA-Fx for pgsql-hackers@lists.postgresql.org; Mon, 15 Nov 2021 18:12:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1AFICimM2141903; Mon, 15 Nov 2021 13:12:44 -0500 From: Tom Lane To: "Bossart, Nathan" cc: "pgsql-hackers@lists.postgresql.org" Subject: Re: Improving psql's \password command In-reply-to: References: <747443.1635536754@sss.pgh.pa.us> <765509.1635552418@sss.pgh.pa.us> <7BAC8A28-148B-4B03-A345-D68071388300@amazon.com> <1553329.1636647111@sss.pgh.pa.us> <1847699.1636747076@sss.pgh.pa.us> Comments: In-reply-to "Bossart, Nathan" message dated "Mon, 15 Nov 2021 17:46:31 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2141901.1636999964.1@sss.pgh.pa.us> Date: Mon, 15 Nov 2021 13:12:44 -0500 Message-ID: <2141902.1636999964@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Bossart, Nathan" writes: > Here is an attempt at adding control-C support for \password. With > this patch, we pass sigint_interrupt_jmp and sigint_interrupt_enabled > all the way down to pg_get_line_append(), which is admittedly a bit > more complicated than I think would be ideal. I see a couple of other > calls to simple_prompt() (e.g., \prompt and \connect), and I think the > same infrastructure could be used for those as well. I'll send some > follow-up patches for those if this approach seems reasonable. Hm. It's not as bad as I thought it might be, but I still dislike importing into common/string.h --- that seems like a mighty ugly dependency to have there. I guess one idea to avoid that is to declare SigintInterruptContext.jmpbuf as "void *". Alternatively we could push those function declarations into some specialized header. Some other random observations (not a full review): * API spec for SigintInterruptContext needs to be a bit more detailed. Maybe "... via an existing SIGINT signal handler that will longjmp to the specified place, but only when *enabled is true". * I don't believe that this bit is necessary, or if it is, the comment fails to justify it: - initStringInfo(&buf); + /* make sure buf is palloc'd so we don't lose changes after a longjmp */ + buf = makeStringInfo(); * You're failing to re-enable sigint_ctx->enabled when looping around for another fgets call. * Personally I'd write those assignments like *(sigint_ctx->enabled) = true; as that seems clearer. regards, tom lane