delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/30/02:03:02

X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
Subject: RE: ssh-agent variables available to any user process
Date: Wed, 30 Aug 2006 08:02:46 +0200
Message-ID: <F0D7281DAB048B438E8F5EC4ECEFBDDCE4FE8E@esmail.elsag.de>
From: =?iso-8859-1?Q?J=F6rg_Schaible?= <Joerg DOT Schaible AT Elsag-Solutions DOT com>
To: "[ML] CygWin " <cygwin AT cygwin DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id k7U62wft010733

Lapo Luchini wrote on Wednesday, August 30, 2006 12:42 AM:

> Under FreeBSD, I launch ssh-agent in my .xsession script and its
> environment is automatically inherited by every shell I then
> open in my
> X11 session.
> No such luck with Windows, but I found a way to propagate a
> environment variable to any (future) user process after the user is
> already logged.
> (or, at the very least...) Works for me.
> 
> Variables will be then available on any shell and program opened after
> the attached script is executed.
> (put it in "Startup" menu in order to execute it at logon time)

I use a similar approach for years utilizing keychain. In my ~/.profile I have following lines:

====== %< =======
if test -z "`pidof ssh-agent`"; then
    keychain ~/.ssh/id_dsa
    . ~/.keychain/`hostname`-sh
    # Create batch files to be called from running shells
    cat ~/.keychain/`hostname`-sh | sed -e "s/;.*$//g" | u2d > ~/.keychain/`hostname`-command.bat
    # Set environment directly
    regtool -s set /machine/SYSTEM/CurrentControlSet/Control/Session\ Manager/Environment/SSH_AUTH_SOCK $SSH_AUTH_SOCK
    regtool -s set /machine/SYSTEM/CurrentControlSet/Control/Session\ Manager/Environment/SSH_AGENT_PID $SSH_AGENT_PID
    # Broadcast of WM_SETTINGCHANGE
    update-env
else
    . ~/.keychain/`hostname`-sh
fi
====== %< =======

And update-env.c is:

====== %< =======
#include <windows.h>
int main() {
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment");
}
====== %< =======

build with Makefile:

====== %< =======
all: update-env.exe

%.exe: %.c
	gcc -mno-cygwin $^ -o $*
	strip $@
====== %< =======

I never found a way to broadcast the WM_SETTINGCHANGE directly form the script without the little helper app.

- Jörg

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019