1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/version.h
nagachika ef1ed1b53a merge revision(s) c15cddd1d5: [Backport #16787]
Allow Dir.home to work for non-login procs when $HOME not set

	Allow the 'Dir.home' method to reliably locate the user's home directory when
	all three of the following are true at the same time:

	    1. Ruby is running on a Unix-like OS
	    2. The $HOME environment variable is not set
	    3. The process is not a descendant of login(1) (or a work-alike)

	The prior behavior was that the lookup could only work for login-descended
	processes.

	This is accomplished by looking up the user's record in the password database
	by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3))
	which is still attempted first (based on the name, if any, returned by
	getlogin_r(3)).

	If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at
	compile time, will fallback on using their respective non-*_r() variants:
	getlogin(3), getpwnam(3), and/or getpwuid(3).

	The rationale for attempting to do the lookup by name prior to doing it by uid
	is to accommodate the possibility of multiple login names (each with its own
	record in the password database, so each with a potentially different home
	directory) being mapped to the same uid (as is explicitly allowed for by
	POSIX; see getlogin(3posix)).

	Preserves the existing behavior for login-descended processes, and adds the
	new capability of having Dir.home being able to find the user's home directory
	for non-login-descended processes.

	Fixes [Bug #16787]

	Related discussion:
	    https://bugs.ruby-lang.org/issues/16787
	    https://github.com/ruby/ruby/pull/3034
	---
	 configure.ac       |   5 +
	 file.c             |  51 +++++++---
	 internal/process.h |   6 ++
	 process.c          | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
	 4 files changed, 311 insertions(+), 17 deletions(-)
2021-03-20 13:56:13 +09:00

77 lines
2.3 KiB
C

# define RUBY_VERSION_MAJOR RUBY_API_VERSION_MAJOR
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 167
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 3
#define RUBY_RELEASE_DAY 20
#include "ruby/version.h"
#ifndef TOKEN_PASTE
#define TOKEN_PASTE(x,y) x##y
#endif
#define ONLY_ONE_DIGIT(x) TOKEN_PASTE(10,x) < 1000
#define WITH_ZERO_PADDING(x) TOKEN_PASTE(0,x)
#define RUBY_BIRTH_YEAR_STR STRINGIZE(RUBY_BIRTH_YEAR)
#define RUBY_RELEASE_YEAR_STR STRINGIZE(RUBY_RELEASE_YEAR)
#if ONLY_ONE_DIGIT(RUBY_RELEASE_MONTH)
#define RUBY_RELEASE_MONTH_STR STRINGIZE(WITH_ZERO_PADDING(RUBY_RELEASE_MONTH))
#else
#define RUBY_RELEASE_MONTH_STR STRINGIZE(RUBY_RELEASE_MONTH)
#endif
#if ONLY_ONE_DIGIT(RUBY_RELEASE_DAY)
#define RUBY_RELEASE_DAY_STR STRINGIZE(WITH_ZERO_PADDING(RUBY_RELEASE_DAY))
#else
#define RUBY_RELEASE_DAY_STR STRINGIZE(RUBY_RELEASE_DAY)
#endif
#if !defined RUBY_LIB_VERSION && defined RUBY_LIB_VERSION_STYLE
# if RUBY_LIB_VERSION_STYLE == 3
# define RUBY_LIB_VERSION STRINGIZE(RUBY_API_VERSION_MAJOR)"."STRINGIZE(RUBY_API_VERSION_MINOR)"."STRINGIZE(RUBY_API_VERSION_TEENY)
# elif RUBY_LIB_VERSION_STYLE == 2
# define RUBY_LIB_VERSION STRINGIZE(RUBY_API_VERSION_MAJOR)"."STRINGIZE(RUBY_API_VERSION_MINOR)
# endif
#endif
#if RUBY_PATCHLEVEL == -1
#define RUBY_PATCHLEVEL_STR "dev"
#else
#define RUBY_PATCHLEVEL_STR "p"STRINGIZE(RUBY_PATCHLEVEL)
#endif
#ifndef RUBY_REVISION
# include "revision.h"
#endif
#ifdef RUBY_REVISION
# if RUBY_PATCHLEVEL == -1
# ifndef RUBY_BRANCH_NAME
# define RUBY_BRANCH_NAME "master"
# endif
# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
# else
# define RUBY_REVISION_STR " revision "RUBY_REVISION
# endif
#else
# define RUBY_REVISION "HEAD"
# define RUBY_REVISION_STR ""
#endif
#if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
# undef RUBY_RELEASE_DATETIME
# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
#endif
# define RUBY_DESCRIPTION_WITH(opt) \
"ruby "RUBY_VERSION \
RUBY_PATCHLEVEL_STR \
" ("RUBY_RELEASE_DATETIME \
RUBY_REVISION_STR")"opt" " \
"["RUBY_PLATFORM"]"
# define RUBY_COPYRIGHT \
"ruby - Copyright (C) " \
RUBY_BIRTH_YEAR_STR"-" \
RUBY_RELEASE_YEAR_STR" " \
RUBY_AUTHOR