From 6bcd9efc0c1b66cd3ab66668283b51031ce5658d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 10 Aug 2010 13:50:40 -0400 Subject: [PATCH] Use gettimeofday() directly instead of via the gettime() wrapper. --- common/Makefile.in | 3 +-- common/gettime.c | 37 ------------------------------------- compat/mkstemps.c | 4 +--- plugins/sudoers/sudoers.h | 3 --- plugins/sudoers/visudo.c | 4 ++-- src/sudo.h | 3 --- src/sudo_edit.c | 4 ++-- 7 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 common/gettime.c diff --git a/common/Makefile.in b/common/Makefile.in index c10cf9c47..815eb5a47 100644 --- a/common/Makefile.in +++ b/common/Makefile.in @@ -45,7 +45,7 @@ DEFS = @OSDEFS@ SHELL = @SHELL@ -LTOBJS = alloc.lo atobool.lo fileops.lo fmt_string.lo gettime.lo \ +LTOBJS = alloc.lo atobool.lo fileops.lo fmt_string.lo \ lbuf.lo list.lo term.lo zero_bytes.lo @COMMON_OBJS@ all: libcommon.la @@ -64,7 +64,6 @@ alloc.lo: $(srcdir)/alloc.c $(incdir)/compat.h $(incdir)/alloc.h $(incdir)/error atobool.lo: $(srcdir)/atobool.c $(incdir)/compat.h $(incdir)/missing.h $(top_builddir)/config.h fileops.lo: $(srcdir)/fileops.c $(incdir)/fileops.h $(top_builddir)/config.h fmt_string.lo: $(srcdir)/fmt_string.c $(incdir)/compat.h $(top_builddir)/config.h -gettime.lo: $(srcdir)/gettime.c $(incdir)/compat.h $(top_builddir)/config.h lbuf.lo: $(srcdir)/lbuf.c $(incdir)/compat.h $(incdir)/alloc.h $(incdir)/error.h $(incdir)/missing.h $(incdir)/lbuf.h $(top_builddir)/config.h list.lo: $(srcdir)/list.c $(incdir)/compat.h $(incdir)/list.h $(incdir)/error.h $(top_builddir)/config.h term.lo: $(srcdir)/term.c $(incdir)/compat.h $(top_builddir)/config.h diff --git a/common/gettime.c b/common/gettime.c deleted file mode 100644 index 103cc070f..000000000 --- a/common/gettime.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2004-2005, 2008, 2010 - * Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include -#include -#include -#if TIME_WITH_SYS_TIME -# include -#endif - -#include - -/* - * Get the current time via gettimeofday() for systems with - * timespecs in struct stat or, otherwise, using time(). - */ -int -gettime(struct timeval *tv) -{ - return gettimeofday(tv, NULL); -} diff --git a/compat/mkstemps.c b/compat/mkstemps.c index 1bd3c7819..d707f40e2 100644 --- a/compat/mkstemps.c +++ b/compat/mkstemps.c @@ -38,8 +38,6 @@ #include -extern int gettime(struct timeval *); - static unsigned int get_random(void); static void seed_random(void); @@ -113,7 +111,7 @@ seed_random(void) /* * Seed from time of day and process id multiplied by small primes. */ - (void) gettime(&tv); + (void) gettimeofday(&tv, NULL); seed = (tv.tv_sec % 10000) * 523 + tv.tv_usec * 13 + (getpid() % 1000) * 983; SRAND(seed); diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index ccd880d2f..902508773 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -250,9 +250,6 @@ char *sudo_getepw(const struct passwd *); /* zero_bytes.c */ void zero_bytes(volatile void *, size_t); -/* gettime.c */ -int gettime(struct timeval *); - /* sudo_nss.c */ void display_privs(struct sudo_nss_list *, struct passwd *); int display_cmnd(struct sudo_nss_list *, struct passwd *); diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index f89e3cf93..fb9741937 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -338,9 +338,9 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) * XPG4 specifies that vi's exit value is a function of the * number of errors during editing (?!?!). */ - gettime(&tv1); + gettimeofday(&tv1, NULL); if (run_command(editor, av) != -1) { - gettime(&tv2); + gettimeofday(&tv2, NULL); /* * Sanity checks. */ diff --git a/src/sudo.h b/src/sudo.h index aa6f5f902..07e43cb8a 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -207,9 +207,6 @@ int sudo_edit(struct command_details *details, char *argv[], char *envp[]); /* parse_args.c */ void usage(int) __attribute__((__noreturn__)); -/* gettime.c */ -int gettime(struct timeval *); - /* selinux.c */ int selinux_restore_tty(void); int selinux_setup(const char *role, const char *type, const char *ttyn, diff --git a/src/sudo_edit.c b/src/sudo_edit.c index 26cde3247..cb4163500 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -244,7 +244,7 @@ sudo_edit(struct command_details *command_details, char *argv[], char *envp[]) * Run the editor with the invoking user's creds, * keeping track of the time spent in the editor. */ - gettime(&tv1); + gettimeofday(&tv1, NULL); memcpy(&editor_details, command_details, sizeof(editor_details)); editor_details.uid = user_details.uid; editor_details.euid = user_details.uid; @@ -253,7 +253,7 @@ sudo_edit(struct command_details *command_details, char *argv[], char *envp[]) editor_details.ngroups = user_details.ngroups; editor_details.groups = user_details.groups; rval = run_command(&editor_details, nargv, envp); - gettime(&tv2); + gettimeofday(&tv2, NULL); /* Copy contents of temp files to real ones */ for (i = 0; i < nfiles; i++) { -- 2.40.0