summaryrefslogtreecommitdiffstats
path: root/login-utils/sulogin.c
diff options
context:
space:
mode:
authorKarel Zak2012-03-12 12:32:03 +0100
committerKarel Zak2012-03-12 12:32:03 +0100
commitadf97f07807896c28abd2f0f721a62b9469b5ad6 (patch)
tree40f4b2d5472ec78c036ac02d09e6fb819ec0d1d7 /login-utils/sulogin.c
parentsulogin: add long options (diff)
downloadkernel-qcow2-util-linux-adf97f07807896c28abd2f0f721a62b9469b5ad6.tar.gz
kernel-qcow2-util-linux-adf97f07807896c28abd2f0f721a62b9469b5ad6.tar.xz
kernel-qcow2-util-linux-adf97f07807896c28abd2f0f721a62b9469b5ad6.zip
sulogin: check chdir and getcwd return values [-Wunused-result]
sulogin.c: In function ‘sushell’: sulogin.c:338:7: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result] sulogin.c:359:8: warning: ignoring return value of ‘getcwd’, declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/sulogin.c')
-rw-r--r--login-utils/sulogin.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index 14843d0b4..013045936 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -327,15 +327,22 @@ static char *getpasswd(char *crypted)
*/
static void sushell(struct passwd *pwd)
{
- char shell[128];
- char home[128];
+ char shell[PATH_MAX];
+ char home[PATH_MAX];
char *p;
char *sushell;
/*
* Set directory and shell.
*/
- chdir(pwd->pw_dir);
+ if (chdir(pwd->pw_dir) != 0) {
+ warn(_("%s: change directory failed"), pwd->pw_dir);
+ printf(_("Logging in with home = \"/\".\n"));
+
+ if (chdir("/") != 0)
+ warn(_("change directory to system root failed"));
+ }
+
if ((p = getenv("SUSHELL")) != NULL)
sushell = p;
else if ((p = getenv("sushell")) != NULL)
@@ -356,8 +363,9 @@ static void sushell(struct passwd *pwd)
/*
* Set some important environment variables.
*/
- getcwd(home, sizeof(home));
- setenv("HOME", home, 1);
+ if (getcwd(home, sizeof(home)) != NULL)
+ setenv("HOME", home, 1);
+
setenv("LOGNAME", "root", 1);
setenv("USER", "root", 1);
if (!profile)