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>
23#include <loggers/file_logger.h>
25
26using namespace application;
27using namespace basis;
28using namespace loggers;
29using namespace filesystem;
30using namespace textual;
31using 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
38class time_set_effective_id : public application_shell
39{
40public:
41 time_set_effective_id() : application_shell() {}
42 DEFINE_CLASS_NAME("time_set_effective_id");
43 int execute();
44};
45
46int time_set_effective_id::execute()
47{
48 FUNCDEF("execute");
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
81HOOPLE_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>
90 #include <basis/astring.cpp>
92 #include <basis/environment.cpp>
93 #include <basis/guards.cpp>
94 #include <basis/mutex.cpp>
103 #include <filesystem/directory.cpp>
104 #include <filesystem/filename.cpp>
105 #include <loggers/combo_logger.cpp>
108 #include <loggers/file_logger.cpp>
111 #include <structures/checksums.cpp>
118 #include <textual/parser_bits.cpp>
120 #include <timely/earth_time.cpp>
121 #include <timely/time_stamp.cpp>
122#endif // __BUILD_STATIC_APPLICATION__
123
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
Represents a point in time relative to the operating system startup time.
Definition time_stamp.h:38
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition time_stamp.h:61
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
#include <time.h>
#define LOG(to_print)