PR# 14451 Compiler crashes if HOME environment variable not set
Problem Report Summary
Submitter: prestoat2000
Category: Compiler
Priority: Medium
Date: 2008/06/05
Class: Bug
Severity: Serious
Number: 14451
Release: 6.2.73753
Confidential: No
Status: Analyzed
Responsible: paulbates
Environment: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.8.1.13) Gecko/20080328 Firefox/2.0.0.13
Solaris 10 on SPARC
Synopsis: Compiler crashes if HOME environment variable not set
Description
If the HOME environment variable is not set on Unix, compiler crashes. It should instead report an error if it requires that this variable be set and should perhaps check that it is an existing directory. Here is the top few stack frames from the trace: ------------------------------------------------------------------------------- Class / Object Routine Nature of exception Effect ------------------------------------------------------------------------------- ES_EIFFEL_LAYOUT user_directory_name @6 Segmentation violation: <0000000004F91EA8> (From EIFFEL_ENV) Operating system signal. Exit ------------------------------------------------------------------------------- ES_EIFFEL_LAYOUT user_directory_name @6 <0000000004F91EA8> (From EIFFEL_ENV) Routine failure. Exit ------------------------------------------------------------------------------- ES_EIFFEL_LAYOUT user_files_path @3 <0000000004F91EA8> (From EIFFEL_ENV) Routine failure. Exit ------------------------------------------------------------------------------- ES_EIFFEL_LAYOUT check_environment_variable @43 <0000000004F91EA8> (From EIFFEL_ENV) Routine failure. Exit -------------------------------------------------------------------------------
To Reproduce
Setup to use Eiffel on Unix, the do "unsetenv HOME" Run "ec". Compiler crashes.
Problem Report Interactions
One more comment on this: the current solution is worse than the old behavior (a crash). Just in case you're not familiar with this, the operating system does not know about "~". If you check whether directory "~" exists in a C program, you will get a "no" answer unless there is a directory whose actual name is "~" in the current working directory. When you give commands to the shell, it translates "~" into the value of the "home" shell variable and then passes the translated value to the OS. The "home" shell variable is set by the shell at some point from the value of the HOME environment variable, which gets its value either inherited from a parent process or via a call to getpwuid. I assumed you already know this, but if you do then I don't understand why you would return "~" for the value of the home directory in path_name.c if the HOME environment variable is not set, since it can't possibly work as intended.
I don't know how likely it is that HOME is undefined, but it seems to me that Eiffel should do something reasonable if it isn't. The only reasonable thing to do on a Unix platform is to call `getpwuid' to find out what the home directory is. There is no other way to find out, as far as I know. The shell has to call getpwuid or getpwuid_r once at login to set the "home" shell variable and the HOME environment variable values. I don't think the C code to do this is very complicated. There is a similar example in file.c routine `file_owner'. Another option would be to return "" (empty string) if HOME is undefined but presumably this would violate the expectation of callers of {EXECUTION_ENVIRONMENT}.home_directory_name. If you did this, then estudio could refuse to run if HOME is not set, just as it does if ISE_EIFFEL is not set. I don't think this is a great solution. A third option is to raise an exception if HOME environment variable is not set, but then all programs would have to c .... Output truncated, Click download to get the full message
I thought of using something along those lines, but the likelyhood that HOME is not defined is pretty low, isn't it? Moreover, in some of what I've read ~ will be $HOME is set, otherwise the value of your passwd file, but I must say it is not clear where to find reference documentation on that topic.
I don't think the solution (returning "~" if HOME environment variable is not set) is going to fly. "~" is translated by the shell to the user's home directory, but the shell is not involved here. I think the correct solution is to call getpwuid (or its reentrant counterpart getpwuid_r, if available), passing the value of either `getuid()' (real user id) or `geteuid()' (effective user ID). Then get the value of the pw_dir field from the returned struct passwd * pointer, call RTMS on it and return that value. If I manually set the HOME environment variable to "~", the command line compiler runs OK but estudio asks me for an activation code, presumably because it can't find my license since it doesn't know where my home directory is. Reopening report.
David, this problem has been addressed in rev#78008