suggested bsd-setproctitle.c

Mark D. Roth roth at feep.net
Wed Nov 8 15:53:32 EST 2000


On Tue Nov 07 15:46 2000 +0100, Kevin Steves wrote:
> How does the attached patch work?  I tested on HP-UX
> !defined(HAVE___PROGNAME) and Linux defined(HAVE___PROGNAME).  I don't
> use const now to keep things consistent, and went back to #ifdef
> HAVE___PROGNAME.

Unfortunately, you're still setting __progname to a hard-coded value
instead of basename(argv[0]), which means that you don't get a
reasonable value when you invoke one of these programs using something
other than the default name.

I'd suggest the attached patch instead.  I'm not super familiar with
the code, so please let me know if I'm missing something here...
Thanks!

-- 
Mark D. Roth <roth at feep.net>
http://www.feep.net/~roth/
-------------- next part --------------
diff -urN openssh-2.3.0p1/bsd-setproctitle.c openssh-2.3.0p1-new/bsd-setproctitle.c
--- openssh-2.3.0p1/bsd-setproctitle.c	Wed Oct 18 08:11:44 2000
+++ openssh-2.3.0p1-new/bsd-setproctitle.c	Tue Nov  7 22:24:36 2000
@@ -56,11 +56,7 @@
 
 #define	MAX_PROCTITLE	2048
 
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else
-static const char *__progname = "sshd";
-#endif /* HAVE___PROGNAME */
 
 /*
  * Set Process Title (SPT) defines.  Modeled after sendmail's
diff -urN openssh-2.3.0p1/log-server.c openssh-2.3.0p1-new/log-server.c
--- openssh-2.3.0p1/log-server.c	Fri Sep 15 21:29:09 2000
+++ openssh-2.3.0p1-new/log-server.c	Tue Nov  7 22:24:51 2000
@@ -43,11 +43,7 @@
 #include "xmalloc.h"
 #include "ssh.h"
 
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "sshd";
-#endif /* HAVE___PROGNAME */
 
 static LogLevel log_level = SYSLOG_LEVEL_INFO;
 static int log_on_stderr = 0;
diff -urN openssh-2.3.0p1/session.c openssh-2.3.0p1-new/session.c
--- openssh-2.3.0p1/session.c	Fri Oct 27 22:19:58 2000
+++ openssh-2.3.0p1-new/session.c	Tue Nov  7 22:25:02 2000
@@ -128,11 +128,7 @@
 
 /* import */
 extern ServerOptions options;
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "sshd";
-#endif /* HAVE___PROGNAME */
 
 extern int log_stderr;
 extern int debug_flag;
diff -urN openssh-2.3.0p1/sftp-server.c openssh-2.3.0p1-new/sftp-server.c
--- openssh-2.3.0p1/sftp-server.c	Fri Sep 22 22:58:32 2000
+++ openssh-2.3.0p1-new/sftp-server.c	Tue Nov  7 22:51:49 2000
@@ -30,6 +30,10 @@
 #include "getput.h"
 #include "xmalloc.h"
 
+#ifndef HAVE___PROGNAME
+char *__progname;
+#endif /* ! HAVE___PROGNAME */
+
 /* version */
 #define	SSH_FILEXFER_VERSION		2
 
@@ -1014,6 +1018,12 @@
 	fd_set rset, wset;
 	int in, out, max;
 	ssize_t len, olen;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(av[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "sftp-server";
+#endif /* ! HAVE___PROGNAME */
 
 	handle_init();
 
diff -urN openssh-2.3.0p1/ssh-add.c openssh-2.3.0p1-new/ssh-add.c
--- openssh-2.3.0p1/ssh-add.c	Tue Oct 17 07:22:28 2000
+++ openssh-2.3.0p1-new/ssh-add.c	Tue Nov  7 22:49:42 2000
@@ -48,10 +48,8 @@
 #include "authfd.h"
 #include "authfile.h"
 
-#ifdef HAVE___PROGNAME
-extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "ssh-add";
+#ifndef HAVE___PROGNAME
+char *__progname;
 #endif /* HAVE___PROGNAME */
 
 void
@@ -247,6 +245,12 @@
 	int no_files = 1;
 	int i;
 	int deleting = 0;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(argv[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "ssh-add";
+#endif /* ! HAVE___PROGNAME */
 
 	init_rng();
 
diff -urN openssh-2.3.0p1/ssh-agent.c openssh-2.3.0p1-new/ssh-agent.c
--- openssh-2.3.0p1/ssh-agent.c	Fri Sep 29 07:01:37 2000
+++ openssh-2.3.0p1-new/ssh-agent.c	Tue Nov  7 22:46:04 2000
@@ -92,10 +92,8 @@
 char socket_name[1024];
 char socket_dir[1024];
 
-#ifdef HAVE___PROGNAME
-extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "ssh-agent";
+#ifndef HAVE___PROGNAME
+char *__progname;
 #endif /* HAVE___PROGNAME */
 
 void
@@ -667,6 +665,12 @@
 	pid_t pid;
 	char *shell, *format, *pidstr, pidstrbuf[1 + 3 * sizeof pid];
 	extern int optind;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(av[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "ssh-agent";
+#endif /* ! HAVE___PROGNAME */
 	
 	init_rng();
 	
diff -urN openssh-2.3.0p1/ssh-keygen.c openssh-2.3.0p1-new/ssh-keygen.c
--- openssh-2.3.0p1/ssh-keygen.c	Sat Oct 14 00:23:12 2000
+++ openssh-2.3.0p1-new/ssh-keygen.c	Tue Nov  7 22:46:08 2000
@@ -70,10 +70,8 @@
 int dsa_mode = 0;
 
 /* argv0 */
-#ifdef HAVE___PROGNAME
-extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "ssh-keygen";
+#ifndef HAVE___PROGNAME
+char *__progname;
 #endif /* HAVE___PROGNAME */
 
 char hostname[MAXHOSTNAMELEN];
@@ -602,6 +600,12 @@
 	Key *public;
 	extern int optind;
 	extern char *optarg;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(av[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "ssh-keygen";
+#endif /* ! HAVE___PROGNAME */
 
 	init_rng();
 
diff -urN openssh-2.3.0p1/ssh.c openssh-2.3.0p1-new/ssh.c
--- openssh-2.3.0p1/ssh.c	Fri Oct 27 22:19:58 2000
+++ openssh-2.3.0p1-new/ssh.c	Tue Nov  7 22:45:01 2000
@@ -59,10 +59,8 @@
 #include "authfd.h"
 #include "authfile.h"
 
-#ifdef HAVE___PROGNAME
-extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "ssh";
+#ifndef HAVE___PROGNAME
+char *__progname;
 #endif /* HAVE___PROGNAME */
 
 /* Flag indicating whether IPv4 or IPv6.  This can be set on the command line.
@@ -234,6 +232,12 @@
 	struct passwd *pw, pwcopy;
 	int dummy;
 	uid_t original_effective_uid;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(av[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "ssh";
+#endif /* ! HAVE___PROGNAME */
 
 	init_rng();
 
diff -urN openssh-2.3.0p1/sshconnect.c openssh-2.3.0p1-new/sshconnect.c
--- openssh-2.3.0p1/sshconnect.c	Sat Sep 23 01:15:57 2000
+++ openssh-2.3.0p1-new/sshconnect.c	Tue Nov  7 22:29:25 2000
@@ -35,11 +35,7 @@
 char *server_version_string = NULL;
 
 extern Options options;
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else /* HAVE___PROGNAME */
-static const char *__progname = "ssh";
-#endif /* HAVE___PROGNAME */
 
 /*
  * Connect to the given ssh server using a proxy command.
diff -urN openssh-2.3.0p1/sshd.c openssh-2.3.0p1-new/sshd.c
--- openssh-2.3.0p1/sshd.c	Sat Oct 14 00:23:13 2000
+++ openssh-2.3.0p1-new/sshd.c	Tue Nov  7 22:48:58 2000
@@ -82,6 +82,10 @@
 /* Server configuration options. */
 ServerOptions options;
 
+#ifndef HAVE___PROGNAME
+char *__progname;
+#endif /* ! HAVE___PROGNAME */
+
 /* Name of the server configuration file. */
 char *config_file_name = SERVER_CONFIG_FILE;
 
@@ -491,6 +495,12 @@
 	int listen_sock, maxfd;
 	int startup_p[2];
 	int startups = 0;
+
+#ifndef HAVE___PROGNAME
+	__progname = xstrdup(strrchr(av[0], '/') + 1);
+	if (__progname == NULL)
+		__progname = "sshd";
+#endif /* ! HAVE___PROGNAME */
 
 	init_rng();
 


More information about the openssh-unix-dev mailing list