1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 19:42:48 -05:00

Factor out Unix Pageant's socket creation.

The code in Pageant that sets up the Unix socket and its containing
directory now lives in a separate file, uxagentsock.c, where it will
also be callable from the upcoming new SSH server when it wants to
create a similar socket for agent forwarding.

While I'm at it, I've also added a feature to create a watchdog
subprocess that will try to clean up the socket and directory once
Pageant itself terminates, in the hope of leaving less cruft lying
around /tmp.
This commit is contained in:
Simon Tatham
2018-10-14 18:48:02 +01:00
parent b94c6a7e38
commit f4db9196da
5 changed files with 98 additions and 18 deletions

View File

@ -20,9 +20,6 @@
#include "misc.h"
#include "pageant.h"
SockAddr *unix_sock_addr(const char *path);
Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug);
void cmdline_error(const char *fmt, ...)
{
va_list ap;
@ -711,7 +708,7 @@ static const PlugVtable X11Connection_plugvt = {
void run_agent(void)
{
const char *err;
char *username, *socketdir;
char *errw;
struct pageant_listen_state *pl;
Plug *pl_plug;
Socket *sock;
@ -743,19 +740,12 @@ void run_agent(void)
/*
* Set up a listening socket and run Pageant on it.
*/
username = get_username();
socketdir = dupprintf("%s.%s", PAGEANT_DIR_PREFIX, username);
sfree(username);
assert(*socketdir == '/');
if ((err = make_dir_and_check_ours(socketdir)) != NULL) {
fprintf(stderr, "pageant: %s: %s\n", socketdir, err);
exit(1);
}
socketname = dupprintf("%s/pageant.%d", socketdir, (int)getpid());
pl = pageant_listener_new(&pl_plug);
sock = new_unix_listener(unix_sock_addr(socketname), pl_plug);
if ((err = sk_socket_error(sock)) != NULL) {
fprintf(stderr, "pageant: %s: %s\n", socketname, err);
sock = platform_make_agent_socket(pl_plug, PAGEANT_DIR_PREFIX,
&errw, &socketname);
if (!sock) {
fprintf(stderr, "pageant: %s\n", errw);
sfree(errw);
exit(1);
}
pageant_listener_got_socket(pl, sock);