[PATCH] ssh: set proctitle for mux master

Bert Wesarg bert.wesarg at googlemail.com
Tue Feb 15 03:56:05 EST 2011


On Mon, Feb 7, 2011 at 22:11, Bert Wesarg <bert.wesarg at googlemail.com> wrote:
> Preserving the command line from the invoking ssh command doesn't
> make much sense, so use setproctitle() to hide the arguments.
> ---
>  ssh.c |   20 +++++++++++++++++---
>  1 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/ssh.c b/ssh.c
> index d32ef78..8ebcc88 100644
> --- a/ssh.c
> +++ b/ssh.c
> @@ -230,12 +230,25 @@ main(int ac, char **av)
>        struct servent *sp;
>        Forward fwd;
>
> -       /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
> -       sanitise_stdfd();
> -
>        __progname = ssh_get_progname(av[0]);
>        init_rng();
>
> +#ifndef HAVE_SETPROCTITLE
> +       /* Prepare for later setproctitle emulation */
> +       {
> +               /* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
> +               char **saved_argv = xcalloc(ac + 1, sizeof(*saved_argv));
> +               for (i = 0; i < ac; i++)
> +                       saved_argv[i] = xstrdup(av[i]);
> +               saved_argv[i] = NULL;
> +               compat_init_setproctitle(ac, av);
> +               av = saved_argv;
> +       }
> +#endif
> +
> +       /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
> +       sanitise_stdfd();
> +
>        /*
>         * Discard other fds that are hanging around. These can cause problem
>         * with backgrounded ssh processes started by ControlPersist.
> @@ -965,6 +978,7 @@ control_persist_detach(void)
>                if (devnull > STDERR_FILENO)
>                        close(devnull);
>        }
> +       setproctitle("%s [mux]", options.control_path);

I would also suggest that the mux master chdir into /.

Bert

>  }
>
>  /* Do fork() after authentication. Used by "ssh -f" */
> --
> 1.7.3.3.1603.g7f137
>
>


More information about the openssh-unix-dev mailing list