Andre Noll [Sun, 9 Jun 2013 16:31:55 +0000 (18:31 +0200)]
Avoid gcc warning.
Introduce a default case for the body of the switch statement in
print_statistics() to avoid the following gcc-4.8.1 warning:
select.c: In function 'print_statistics':
select.c:806:2: warning: enumeration value 'select_mode__NULL' not handled in switch [-Wswitch]
switch (select_conf.select_mode_arg) {
^
Andre Noll [Mon, 25 Jun 2012 18:59:17 +0000 (20:59 +0200)]
split_args(): Do not insist on checking the return value.
Currently, split_args() of string.c has the __must_check attribute
which instructs gcc to warn whenever the return value of this function
is ignored by the caller.
However, since the returned array is NULL terminated anyway, there
are situations the return value my safely be ignored, for example if
the returned array is passed to execvp(), which does not receive a
length argument.
This patch removes the __must_check attribute and fixes a "set but
not used" warning on newer gcc versions.
Andre Noll [Mon, 25 Jun 2012 18:48:53 +0000 (20:48 +0200)]
Fix check for return value of catch_signal().
Commit 2d7a4d61 made adu's signal handling portable by switching from
signal() to sigaction() for installing signal handlers. This commit
added the new function catch_signal() which returns the return value
of the underlying call to sigaction(), i.e. zero on success, and -1
on errors.
However, embarrassingly enough, one caller of catch_signal() still
checked this return value against SIG_ERR, which is the value that
is returned from signal() on errors.
Fix this bug by testing the return value against zero.
Andre Noll [Mon, 25 Jun 2012 16:23:15 +0000 (18:23 +0200)]
Makefile: Honor CPPFLAGS also when creating dependencies.
Makefile.deps is created using a cc -MM -MG command which might need
the CPPFLAGS provided by the user, just as the ordinary cc commands
for creating an object file.
For example, the user might have passed -I$HOME/include, since
libosl was installed in $HOME. In this case we need to pass
this to the cc command that creates the Makefile as well.
Andre Noll [Thu, 2 Feb 2012 16:07:35 +0000 (17:07 +0100)]
Fix signal handling.
Using signal() to set the disposition of a signal is always a bad idea
as POSIX does not specify whether a system call which was interrupted
should be restarted or not.
For interactive sessions, the Linux behaviour is to automatically
restart slow system calls, specifically read(2) in case nothing had
been read before the interrupt arrived. This is rather unfortunate
as adu calls fgets(3) (hence read(2)) in an endless loop to read the
user input. Therefore automatically restarted read() calls result
in interactive sessions that can not be terminated easily, as was
noticed by Sebastian Stark.
This patch makes the signal initialization code call sigaction()
instead of signal() to set up the handlers. This buys us well-defined
semantics across all operating systems, namely to *not* restart slow
system calls. As a side effect of this change, interactive sessions
can now be terminated by sending SIGINT (e.g., by pressing CTRL+C).
Andre Noll [Mon, 2 Nov 2009 13:43:51 +0000 (14:43 +0100)]
Set CC to gcc by default.
On systems where cc != gcc, compilation likely fails because we are
using quite some gccisms in adu. So default to gcc but let the user
override the default by setting CC manually.
The straight-forward CC ?= gcc does not work with gnu make as make
assigns CC the default value "cc".
Thanks to Steffen Schmidt for pointing out this shortcoming.
Andre Noll [Fri, 21 Aug 2009 11:25:04 +0000 (13:25 +0200)]
Transform the database_dir/database_root arg into an absolute path.
adu --create failed badly if called with --database_dir or
--database_root being relative path. This patch fixes the bug.
Unfortunately, it's not completely trivial to obtain the cwd
in a portable and secure manner. The method used in the
new absolute_path() function, while still not bullet-proof, is
the best what one can do if portability is an issue.
Andre Noll [Mon, 15 Jun 2009 18:14:30 +0000 (20:14 +0200)]
Documenatation improvements.
This patch adds an illustration of the user-list mode to README and an
examples section to the man page. Thanks to Klaus Kopec who suggested
this improvement.
Sebastian Stark [Wed, 4 Feb 2009 10:16:01 +0000 (11:16 +0100)]
new option database-root
If database-root is given, the database dir is computed by
appending the base dir to it. Obviously this works only if
base dir is given, even for select mode.
The needed directory structure is created below database-root
by the new function mkpath(), which recursively creates any
directory needed to copy the structure of base dir. This
has the side-effect that the database dir is always created
for the user (if permissions allow) which wasn't the case
before.
database_dir is now a global variable just like conf and should
be used whenever conf.database_dir_arg was used before.
Andre Noll [Tue, 23 Dec 2008 16:26:52 +0000 (17:26 +0100)]
Make it compile on FreeBSD and NetBSD.
off_t on BSD is 64 bit even on 32bit machines, so there are no
special tricks needed to get large file support. In fact, getconf
has no options for large file support and struct stat64 and lstat64()
do not exist on BSD systems. This caused the compilation to fail on
those systems.
Fix this problem by checking for BSD via uname -s in the Makefile. If
uname indicates we're on BSD, then do not use getconf and #define
stat64 and lstat64() to stat and lstat() respectively.
Andre Noll [Wed, 17 Dec 2008 22:32:21 +0000 (23:32 +0100)]
Fix a design bug concerning struct user_info.
It was a bad idea to include the accounting data (#files, #dirs,
information about the user only.
So move the accounting data to user_summary_info. This allows
to get rid of the ugly uid_hash_table_sort_idx construct and of
sort_hash_table(). These were only needed because of the broken
design. We now never sort the hash table but allocate an array of
user_summary_info structures on each query and sort that array instead.
This patch not only simplifies code but also fixes a real bug noted by
Sebastian Stark: If the user_summary was requested more than once in
interactive mode, the old code computed incorrect values because the
above mentioned accounting fields were only initialized once. The new
code gets this right automatically because a fresh array is created
on each query.
Andre Noll [Sun, 9 Nov 2008 19:37:09 +0000 (20:37 +0100)]
Make the header line configurable.
This replaces the --no-header flag by --header string option. The
argument is the header of the summary/list.
This was not a straight-forward task because the headers for the
user lists contain the uid and the user name. So introduce another
set of format string directives to still allow this.
Andre Noll [Sun, 9 Nov 2008 14:33:16 +0000 (15:33 +0100)]
Fix sorting of the uid hash table.
We must not blindy sort the whole table because in interactive mode
this table may be modified by later commands and lookup_uid() gets
confused if the entries have been permuted. So introduce
uid_hash_table_sort_idx, an array of indices that describes the current
sorting of the hash table. The order of the entries in the table itsself
never gets changed any more with this patch.
Also, simplify the uid comparators by introducing a wrapper that does
the casts which were previously contained in each comparator.
Andre Noll [Sun, 9 Nov 2008 00:45:42 +0000 (01:45 +0100)]
Do not close tables on each query.
This speeds up interactive mode where many queries may be executed
in a row. User tables are opened on demand (if the uid is admissible)
and only closed on exit. Also the dir table is opened only once per
session rather than on each query.
Andre Noll [Sat, 8 Nov 2008 22:05:54 +0000 (23:05 +0100)]
User handling improvments.
- move global variable num_uids to user.c.
- logging improvements.
- replace search_uid() by create_user_table(). search_uid() had a
horrible interface.
- in user.c, use FOR_EACH_USER() to loop over all users rather than
for_each_admissible_user().
Andre Noll [Wed, 5 Nov 2008 17:30:28 +0000 (18:30 +0100)]
Fix return codes for loop functions.
The four different loop functions must set the return value in
their private struct because these functions are called from
within the osl library which will replace any negative return value
by -E_OSL_LOOP.