mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-03-02 19:15:18 +02:00
.
This commit is contained in:
31
src/date.c
31
src/date.c
@@ -68,7 +68,6 @@ size_t strftime ();
|
||||
time_t time ();
|
||||
#endif
|
||||
|
||||
int putenv ();
|
||||
int stime ();
|
||||
|
||||
char *xrealloc ();
|
||||
@@ -79,16 +78,6 @@ void error ();
|
||||
static void show_date ();
|
||||
static void usage ();
|
||||
|
||||
/* putenv string to use Universal Coordinated Time.
|
||||
POSIX.2 says it should be "TZ=UCT0" or "TZ=GMT0". */
|
||||
#ifndef TZ_UCT
|
||||
#if defined(hpux) || defined(__hpux__) || defined(ultrix) || defined(__ultrix__) || defined(USG)
|
||||
#define TZ_UCT "TZ=GMT0"
|
||||
#else
|
||||
#define TZ_UCT "TZ="
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* The name this program was run with, for error messages. */
|
||||
char *program_name;
|
||||
|
||||
@@ -109,6 +98,8 @@ static struct option const long_options[] =
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
static int universal_time = 0;
|
||||
|
||||
void
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
@@ -118,7 +109,6 @@ main (argc, argv)
|
||||
char *datestr = NULL;
|
||||
time_t when;
|
||||
int set_date = 0;
|
||||
int universal_time = 0;
|
||||
|
||||
program_name = argv[0];
|
||||
|
||||
@@ -154,9 +144,6 @@ main (argc, argv)
|
||||
if (argc - optind > 1)
|
||||
usage (1);
|
||||
|
||||
if (universal_time && putenv (TZ_UCT) != 0)
|
||||
error (1, 0, "virtual memory exhausted");
|
||||
|
||||
time (&when);
|
||||
|
||||
if (datestr)
|
||||
@@ -195,13 +182,17 @@ show_date (format, when)
|
||||
char *out = NULL;
|
||||
size_t out_length = 0;
|
||||
|
||||
tm = localtime (&when);
|
||||
tm = (universal_time ? gmtime : localtime) (&when);
|
||||
|
||||
if (format == NULL)
|
||||
/* Print the date in the default format. Vanilla ANSI C strftime
|
||||
doesn't support %e, but POSIX requires it. If you don't use
|
||||
a GNU strftime, make sure yours supports %e. */
|
||||
format = "%a %b %e %H:%M:%S %Z %Y";
|
||||
{
|
||||
/* Print the date in the default format. Vanilla ANSI C strftime
|
||||
doesn't support %e, but POSIX requires it. If you don't use
|
||||
a GNU strftime, make sure yours supports %e. */
|
||||
format = (universal_time
|
||||
? "%a %b %e %H:%M:%S GMT %Y"
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
}
|
||||
else if (*format == '\0')
|
||||
{
|
||||
printf ("\n");
|
||||
|
||||
@@ -46,6 +46,6 @@ if [ $# -eq 0 ]; then
|
||||
id -Gn
|
||||
else
|
||||
for name in "$@"; do
|
||||
echo $name : `id -Gn $name`
|
||||
echo $name : `id -Gn -- $name`
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -59,14 +59,14 @@ if [ -t 1 ]; then
|
||||
if cat /dev/null >> nohup.out; then
|
||||
echo "nohup: appending output to \`nohup.out'" 2>&1
|
||||
umask $oldmask
|
||||
exec nice -5 "$@" >> nohup.out 2>&1
|
||||
exec nice -5 -- "$@" >> nohup.out 2>&1
|
||||
else
|
||||
cat /dev/null >> $HOME/nohup.out
|
||||
echo "nohup: appending output to \`$HOME/nohup.out'" 2>&1
|
||||
umask $oldmask
|
||||
exec nice -5 "$@" >> $HOME/nohup.out 2>&1
|
||||
exec nice -5 -- "$@" >> $HOME/nohup.out 2>&1
|
||||
fi
|
||||
else
|
||||
umask $oldmask
|
||||
exec nice -5 "$@"
|
||||
exec nice -5 -- "$@"
|
||||
fi
|
||||
|
||||
30
src/su.c
30
src/su.c
@@ -150,6 +150,7 @@ void setusershell ();
|
||||
char *basename ();
|
||||
char *xmalloc ();
|
||||
char *xrealloc ();
|
||||
char *xstrdup ();
|
||||
void error ();
|
||||
|
||||
static char *concat ();
|
||||
@@ -205,6 +206,7 @@ main (argc, argv)
|
||||
char **additional_args = 0;
|
||||
char *shell = 0;
|
||||
struct passwd *pw;
|
||||
struct passwd pw_copy;
|
||||
|
||||
program_name = argv[0];
|
||||
fast_startup = 0;
|
||||
@@ -268,6 +270,16 @@ main (argc, argv)
|
||||
if (pw == 0)
|
||||
error (1, 0, "user %s does not exist", new_user);
|
||||
endpwent ();
|
||||
|
||||
/* Make a copy of the password information and point pw at the local
|
||||
copy instead. Otherwise, some systems (e.g. Linux) would clobber
|
||||
the static data through the getlogin call from log_su. */
|
||||
pw_copy = *pw;
|
||||
pw = &pw_copy;
|
||||
pw->pw_name = xstrdup (pw->pw_name);
|
||||
pw->pw_dir = xstrdup (pw->pw_dir);
|
||||
pw->pw_shell = xstrdup (pw->pw_shell);
|
||||
|
||||
if (!correct_password (pw))
|
||||
{
|
||||
#ifdef SYSLOG_FAILURE
|
||||
@@ -296,13 +308,21 @@ main (argc, argv)
|
||||
shell = 0;
|
||||
}
|
||||
if (shell == 0)
|
||||
shell = pw->pw_shell;
|
||||
shell = strcpy (xmalloc (strlen (shell) + 1), shell);
|
||||
{
|
||||
/* FIXME: Using malloc (through xstrdup) to allocate this space
|
||||
is a minor memory leak. Consider using alloca instead. */
|
||||
shell = xstrdup (pw->pw_shell);
|
||||
}
|
||||
modify_environment (pw, shell);
|
||||
|
||||
change_identity (pw);
|
||||
if (simulate_login && chdir (pw->pw_dir))
|
||||
error (0, errno, "warning: cannot change directory to %s", pw->pw_dir);
|
||||
|
||||
free (pw->pw_name);
|
||||
free (pw->pw_dir);
|
||||
free (pw->pw_shell);
|
||||
|
||||
run_shell (shell, command, additional_args);
|
||||
}
|
||||
|
||||
@@ -439,7 +459,7 @@ run_shell (shell, command, additional_args)
|
||||
if (additional_args)
|
||||
for (; *additional_args; ++additional_args)
|
||||
args[argno++] = *additional_args;
|
||||
args[argno] = 0;
|
||||
args[argno] = NULL;
|
||||
execv (shell, args);
|
||||
error (1, errno, "cannot run %s", shell);
|
||||
}
|
||||
@@ -463,10 +483,10 @@ log_su (pw, successful)
|
||||
/* The utmp entry (via getlogin) is probably the best way to identify
|
||||
the user, especially if someone su's from a su-shell. */
|
||||
old_user = getlogin ();
|
||||
if (old_user == 0)
|
||||
if (old_user == NULL)
|
||||
old_user = "";
|
||||
tty = ttyname (2);
|
||||
if (tty == 0)
|
||||
if (tty == NULL)
|
||||
tty = "";
|
||||
/* 4.2BSD openlog doesn't have the third parameter. */
|
||||
openlog (basename (program_name), 0
|
||||
|
||||
Reference in New Issue
Block a user