feisty meow concerns codebase
2.140
time_set_effective_id.cpp
Go to the documentation of this file.
1
/*
2
* Name : time_set_effective_id
3
* Author : Chris Koeritz
4
* Purpose:
5
*
6
* A simple test of how long it takes to call set effective id on Unix.
7
* For this to really work as designed, it should be run as root.
8
*
9
* Copyright (c) 2003-$now By Author. This program is free software; you can
10
* redistribute it and/or modify it under the terms of the GNU General Public
11
* License as published by the Free Software Foundation; either version 2 of
12
* the License or (at your option) any later version. This is online at:
13
* http://www.fsf.org/copyleft/gpl.html
14
* Please send any updates to: fred@gruntose.com
15
*/
16
17
#include <
basis/functions.h
>
18
#include <
basis/astring.h
>
19
#include <
structures/set.h
>
20
#include <
timely/time_stamp.h
>
21
#include <
application/hoople_main.h
>
22
#include <
loggers/console_logger.h
>
23
#include <
loggers/file_logger.h
>
24
#include <
structures/static_memory_gremlin.h
>
25
26
using namespace
application
;
27
using namespace
basis
;
28
using namespace
loggers
;
29
using namespace
filesystem
;
30
using namespace
textual
;
31
using namespace
timely
;
32
33
#undef BASE_LOG
34
#define BASE_LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
35
#undef LOG
36
#define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(to_print))
37
38
class
time_set_effective_id :
public
application_shell
39
{
40
public
:
41
time_set_effective_id() :
application_shell
() {}
42
DEFINE_CLASS_NAME
(
"time_set_effective_id"
);
43
int
execute();
44
};
45
46
int
time_set_effective_id::execute()
47
{
48
FUNCDEF
(
"execute"
);
49
SETUP_COMBO_LOGGER
;
50
51
#ifndef __WIN32__
52
int
test_runs = 1000000;
53
54
time_stamp
start;
// start of test.
55
for
(
int
i = 0; i < test_runs; i++) {
56
// set effective id to fred.
57
int
ret = seteuid(1008);
58
if
(ret != 0) {
59
LOG
(
"failure to change effective user id to normal user."
);
60
exit(1);
61
}
62
// set effective id to root.
63
ret = seteuid(0);
64
if
(ret != 0) {
65
LOG
(
"failure to change effective user id to root."
);
66
exit(1);
67
}
68
}
69
time_stamp
completion_time;
// end of test.
70
71
double
durat = completion_time.
value
() - start.
value
();
72
double
secs = durat / 1000.0;
// convert to seconds.
73
LOG
(
a_sprintf
(
"test run took %0.2f milliseconds or %0.2f seconds or %0.2f minutes."
, durat, secs, secs / 60.0));
74
// divide by two because we're doing two calls above.
75
LOG
(
a_sprintf
(
"individual call takes %0.0f milliseconds."
, durat /
double
(test_runs) / 2.0));
76
#endif
77
78
return
0;
79
}
80
81
HOOPLE_MAIN
(time_set_effective_id, )
82
83
#ifdef __BUILD_STATIC_APPLICATION__
84
// static dependencies found by buildor_gen_deps.sh:
85
#include <
algorithms/sorts.cpp
>
86
#include <
application/application_shell.cpp
>
87
#include <
application/callstack_tracker.cpp
>
88
#include <
application/command_line.cpp
>
89
#include <
application/windoze_helper.cpp
>
90
#include <
basis/astring.cpp
>
91
#include <
basis/common_outcomes.cpp
>
92
#include <
basis/environment.cpp
>
93
#include <
basis/guards.cpp
>
94
#include <
basis/mutex.cpp
>
95
#include <
basis/utf_conversion.cpp
>
96
#include <
configuration/application_configuration.cpp
>
97
#include <
configuration/configurator.cpp
>
98
#include <
configuration/ini_configurator.cpp
>
99
#include <
configuration/ini_parser.cpp
>
100
#include <
configuration/table_configurator.cpp
>
101
#include <
configuration/variable_tokenizer.cpp
>
102
#include <
filesystem/byte_filer.cpp
>
103
#include <
filesystem/directory.cpp
>
104
#include <
filesystem/filename.cpp
>
105
#include <
loggers/combo_logger.cpp
>
106
#include <
loggers/console_logger.cpp
>
107
#include <
loggers/critical_events.cpp
>
108
#include <
loggers/file_logger.cpp
>
109
#include <
loggers/program_wide_logger.cpp
>
110
#include <
structures/bit_vector.cpp
>
111
#include <
structures/checksums.cpp
>
112
#include <
structures/object_packers.cpp
>
113
#include <
structures/static_memory_gremlin.cpp
>
114
#include <
structures/string_hasher.cpp
>
115
#include <
structures/string_table.cpp
>
116
#include <
structures/version_record.cpp
>
117
#include <
textual/byte_formatter.cpp
>
118
#include <
textual/parser_bits.cpp
>
119
#include <
textual/string_manipulation.cpp
>
120
#include <
timely/earth_time.cpp
>
121
#include <
timely/time_stamp.cpp
>
122
#endif
// __BUILD_STATIC_APPLICATION__
123
application_configuration.cpp
application_shell.cpp
astring.cpp
astring.h
bit_vector.cpp
byte_filer.cpp
byte_formatter.cpp
callstack_tracker.cpp
checksums.cpp
application::application_shell
The application_shell is a base object for console programs.
Definition:
application_shell.h:33
basis::a_sprintf
a_sprintf is a specialization of astring that provides printf style support.
Definition:
astring.h:440
timely::time_stamp
Represents a point in time relative to the operating system startup time.
Definition:
time_stamp.h:38
timely::time_stamp::value
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition:
time_stamp.h:61
combo_logger.cpp
SETUP_COMBO_LOGGER
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
Definition:
combo_logger.h:49
command_line.cpp
common_outcomes.cpp
configurator.cpp
console_logger.cpp
console_logger.h
critical_events.cpp
directory.cpp
earth_time.cpp
DEFINE_CLASS_NAME
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition:
enhance_cpp.h:42
FUNCDEF
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition:
enhance_cpp.h:54
environment.cpp
file_logger.cpp
file_logger.h
filename.cpp
functions.h
guards.cpp
hoople_main.h
Provides macros that implement the 'main' program of an application.
HOOPLE_MAIN
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition:
hoople_main.h:61
ini_configurator.cpp
ini_parser.cpp
mutex.cpp
application
Implements an application lock to ensure only one is running at once.
Definition:
application_shell.cpp:40
basis
The guards collection helps in testing preconditions and reporting errors.
Definition:
array.h:30
filesystem
A platform independent way to obtain the timestamp of a file.
Definition:
byte_filer.cpp:37
loggers
A logger that sends to the console screen using the standard output device.
Definition:
combo_logger.cpp:36
textual
Definition:
byte_formatter.cpp:38
timely
#include <time.h>
Definition:
earth_time.cpp:37
object_packers.cpp
parser_bits.cpp
program_wide_logger.cpp
set.h
sorts.cpp
static_memory_gremlin.cpp
static_memory_gremlin.h
string_hasher.cpp
string_manipulation.cpp
string_table.cpp
table_configurator.cpp
LOG
#define LOG(to_print)
Definition:
time_set_effective_id.cpp:36
time_stamp.cpp
time_stamp.h
utf_conversion.cpp
variable_tokenizer.cpp
version_record.cpp
windoze_helper.cpp
nucleus
applications
utilities
time_set_effective_id.cpp
Generated by
1.9.1