[前][次][番号順一覧][スレッド一覧]

ruby-changes:42747

From: nobu <ko1@a...>
Date: Sat, 30 Apr 2016 09:12:45 +0900 (JST)
Subject: [ruby-changes:42747] nobu:r54822 (trunk): pty.c: user shell

nobu	2016-04-30 10:09:07 +0900 (Sat, 30 Apr 2016)

  New Revision: 54822

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54822

  Log:
    pty.c: user shell
    
    * ext/pty/pty.c (establishShell): honor USER environment variable
      and login name over uid, one pid can be shared by some login
      names.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pty/extconf.rb
    trunk/ext/pty/pty.c
Index: ext/pty/extconf.rb
===================================================================
--- ext/pty/extconf.rb	(revision 54821)
+++ ext/pty/extconf.rb	(revision 54822)
@@ -9,6 +9,7 @@ if /mswin|mingw|bccwin|nacl/ !~ RUBY_PLA https://github.com/ruby/ruby/blob/trunk/ext/pty/extconf.rb#L9
   have_header("libutil.h")
   have_header("util.h") # OpenBSD openpty
   have_header("pty.h")
+  have_header("pwd.h")
   have_library("util", "openpty")
   if have_func("posix_openpt") or
       have_func("openpty") or
Index: ext/pty/pty.c
===================================================================
--- ext/pty/pty.c	(revision 54821)
+++ ext/pty/pty.c	(revision 54822)
@@ -9,7 +9,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/pty/pty.c#L9
 #include	<sys/file.h>
 #include	<fcntl.h>
 #include	<errno.h>
+#ifdef HAVE_PWD_H
 #include	<pwd.h>
+#endif
 #ifdef HAVE_SYS_IOCTL_H
 #include	<sys/ioctl.h>
 #endif
@@ -157,7 +159,6 @@ establishShell(int argc, VALUE *argv, st https://github.com/ruby/ruby/blob/trunk/ext/pty/pty.c#L159
     int 		master, slave, status = 0;
     rb_pid_t		pid;
     char		*p, *getenv();
-    struct passwd	*pwent;
     VALUE		v;
     struct child_info   carg;
     char		errbuf[32];
@@ -169,11 +170,16 @@ establishShell(int argc, VALUE *argv, st https://github.com/ruby/ruby/blob/trunk/ext/pty/pty.c#L170
 	    shellname = p;
 	}
 	else {
-	    pwent = getpwuid(getuid());
+#if defined HAVE_PWD_H
+	    const char *username = getenv("USER");
+	    struct passwd *pwent = getpwnam(username ? username : getlogin());
 	    if (pwent && pwent->pw_shell)
 		shellname = pwent->pw_shell;
 	    else
 		shellname = "/bin/sh";
+#else
+	    shellname = "/bin/sh";
+#endif
 	}
 	v = rb_str_new2(shellname);
 	argc = 1;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54821)
+++ ChangeLog	(revision 54822)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 30 10:09:04 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/pty/pty.c (establishShell): honor USER environment variable
+	  and login name over uid, one pid can be shared by some login
+	  names.
+
 Fri Apr 29 22:40:28 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* doc/maintainers.rdoc (ext/io/nonblock): still maintained, as

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]