Changes from previous version:
* put the return value check to separate subpackages
* change the test (info.hierarchy == hierarchy) to
(info.hierarchy != hierarchy) to decrease the nesting depth
* use memset
This patch fixes lssubsys output - it fixes two problems:
1/ if there was subsystem attached to not-mounted hierarchy then
lssubsys -a
does not show this subsystems
EXAMPLE:
FIXED:
$ ./lssubsys -am
cpuset
ns <- controller is in hierarchy but it is not mounted
cpu,devices <- controller is in hierarchy but it is not mounted
cpuacct /cgroup/memoryd
memory /cgroup/memory
freezer
net_cls /cgroup/net_cls
Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Jan Safranek <jsafrane@redhat.com>
Jan Safranek [Mon, 2 Aug 2010 14:30:45 +0000 (16:30 +0200)]
Fix initscript exit codes.
Fix initscript exit codes
- propagate errors from functions to final exit status
- use exit status '1' for generic errors
- return status '2' when the service is called with unknown arguments
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Eric Brower [Tue, 27 Jul 2010 05:49:37 +0000 (22:49 -0700)]
Update documentation with the new return values
Header file documentation changes; cgroup_create_cgroup() and
cgroup_create_cgroup_from_parent() return ECGROUPNOTEQUAL when create
is successful, but not all controller parameters are successfully
copied.
Signed-off-by: Eric Brower <ebrower@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Eric Brower [Tue, 27 Jul 2010 05:50:40 +0000 (22:50 -0700)]
split on-disk cgroup validation from parent name generation
Split cgroup_find_parent cgroup/parent on-disk validation from cgroup parent
name generation. This solves a chicken-and-egg problem for callers that need
to obtain a parent name from a cgroup that has not yet been created, such as
cgroup_create_cgroup_from_parent(). The new function enforces the documented
behavior (return NULL) when a "root" cgroup is specified.
Modify cgroup_create_cgroup_from_parent() to use this new function, and clean up
a few possibly-erroneous return values.
Eric Brower [Tue, 27 Jul 2010 05:49:16 +0000 (22:49 -0700)]
Return ECGROUPNOTEQUAL to indicate partial create success
Return ECGROUPNOTEQUAL when copying controller parameters fails--
this allows callers to differentiate between cgroup creation failures and
controller configuration failures, and makes explicit that this function
can return an error code but still have created the cgroup. Callers,
such as cgroup_create_cgroup_from_parent(), can now explicitly ignore
(the unfortunately expected) controller configuration errors.
This patch fixes the return values to meet the standarts.
changed values are:
cgconfig:
* start action: 6: program is not configured
* status action: 3: program is not running
cgred:
* start action: 7: program is not running
* start action: 6: program is not configured
* status action: 3: program is not running
* status action: 2: program is dead and /var/run pid file exists
* stop action: 0: if the service is not running
Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Jan Safranek [Mon, 7 Jun 2010 09:58:46 +0000 (11:58 +0200)]
Fix overlaping src and dest buffers in sprintf()
libcgroup compiled with various optimization flags produce strange results
when sprintf's destination and source pointers overlap or are the same.
In addition, use strncpy() instead. This is more or less useless, because
cg_build_path() does not check sizes either, but just for my personal feeling
of correct C code...
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Dhaval Giani [Fri, 4 Jun 2010 11:30:58 +0000 (13:30 +0200)]
libcgroup: Do not call exit from within the main library
The autogenerated code fromt the lexer was calling exit on a
fatal error. Do not do that. Instead log the message.
While it is still not clear if this is the correct response
for YY_FATAL_ERROR, we need to gracefully handle errors, and
since this is a path which is very rarely hit, this is still
a low risk change and so we will merge it.
Jan Safranek [Mon, 31 May 2010 15:15:22 +0000 (17:15 +0200)]
Add configure option to set destination directory of pam module.
Add configure option to set destination directory of pam module. The module
can be used right after 'make install', no moving of libraries is required.
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Jan Safranek [Mon, 31 May 2010 15:15:08 +0000 (17:15 +0200)]
Rework the way how the libraries are installed.
As pointed out by Kay Sievers on IRC, the pkgconfig file should point to
/usr/lib, where libcgroup.so symlink is located, not to /lib, where is the
real library libcgroup.so.1.0.36.
Therefore it's better to install libraries to /usr/lib, which generated
the right libcgroup.pc and then move all necessary libs to /lib.
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Dhaval Giani [Mon, 17 May 2010 16:15:59 +0000 (18:15 +0200)]
libcgroup: Introduce cgroup_basename and modify the functions to use it.
basename() is not safe as it modifies the pointers from time to time.
In order to prevent it, write a safe version of basename which uses basename
internally.
As a side effect, it also clears up the following warning,
api.c: In function ‘cgroup_find_matching_rule’:
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
api.c:2201: warning: passing argument 1 of ‘__xpg_basename’ discards qualifiers from pointer target type
/usr/include/libgen.h:35: note: expected ‘char *’ but argument is of type ‘const char *’
Dhaval Giani [Mon, 17 May 2010 16:15:58 +0000 (18:15 +0200)]
libcgroup: Fix warnings warning about comparisions between signed and unsigned integers
Fix warnings such as
api.c:539: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
api.c:539: warning: signed and unsigned type in conditional expression [-Wsign-compare]
Dhaval Giani [Mon, 17 May 2010 16:15:57 +0000 (18:15 +0200)]
libcgroup: Fix warnings warning of shadowed declaration
Fixes warnings such as
api.c:2764: warning: declaration of ‘stat’ shadows a global declaration [-Wshadow]
/usr/include/sys/stat.h:453: warning: shadowed declaration is here [-Wshadow]
Dhaval Giani [Mon, 17 May 2010 16:15:55 +0000 (18:15 +0200)]
libcgroup: cast CGRULE macros to uid_t
Clears up a few warnings.
api.c:2366: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
api.c:2368: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
api.c:2373: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
api.c:2375: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
Allow cgroup_config_table to be dynamically handled
Allow cgconfigparser to create groups > MAX_GROUPS
From: Balbir Singh <balbir@linux.vnet.ibm.com>
Rafael Tinoco <rafael.tinoco@locaweb.com.br> noticed that the maximum
number of cgroups created using cgconfigparser fell short of 2000. Balbir
found a limitation in the code, that limited this number to a predefined
maximum. This patch fixes the limitation, although not in the most
optimized way, since we want to avoid double parsing of the configuraiton
file.
This patch realloc's the data structure that holds parsed cgroups.
Tested via setting MAX_CGROUPS=1 and loading a configuration file with
2 groups defined. Also tested with a large cgroup file
Test results after loading large_cgconfig.conf (generated using a
script). The size is large, but I wanted to send out the test case
since it adds to our regression bucket.
Jan Safranek [Mon, 12 Apr 2010 10:49:08 +0000 (12:49 +0200)]
Use int for getopt() results
On ppc, char is unsigned and getopt()/getopt_long() returning -1 (= end of
arguments) is translated to 255 and results in 'Invalid command line option'.
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Jan Safranek [Mon, 29 Mar 2010 10:07:00 +0000 (12:07 +0200)]
Add documentation main page
Add very simple main page to include/libcgroup.h. It contains just very
basic info and links to the other modules. Feel free to elaborate more on
this, it could contain lot more:
- how to complie with libcgroup (=pkgconfig)?
- how to report errors
- links to samples
- link to home page
- info about threading
etc.
Jan Safranek [Mon, 29 Mar 2010 10:00:41 +0000 (12:00 +0200)]
Update doxygen config file
Update doxygen config file to 1.6.1 + add comments + change following
settings:
OUTPUT_DIRECTORY = doc/generated
ALWAYS_DETAILED_SEC = YES - we want all function in detailed list
JAVADOC_AUTOBRIEF = YES - IMHO the least painfull way to extract brief
desxcription, see doxygen docs for the other ways. But still painful enough :(
OPTIMIZE_OUTPUT_FOR_C = YES - we're C project
IDL_PROPERTY_SUPPORT = NO - we're C project
WARN_NO_PARAMDOC = YES - document all function parameters please!
INPUT = include - generate public docs only
GENERATE_LATEX = NO - no LaTeX for now, maybe later
*_GRAPH = NO - no call/include graphs in public docs
api: don't keep one copy of the mount table per .c file
The mount table variables need to be declared in the header file and
defined in the .c file. If we don't do that every .o file will end up
with its own copy of those variables.
add const where applicable, drop const where unnecessary
This patch adds the const qualifier to a number of function arguments
(mostly string arguments) so that client libraries can pass their own
const strings to the library without having to cast their const'ness
away.
This also drops a couple of consts where call-by-value is done anyway,
and which hence has no effect and just misleads the users and adds
unnecessary noise to the signal. After all this is C, not C++.
include: refuse inclusion of seperate header files
Later on it might make sense to move around function definitions between
header files. Hence make sure that nobody includes any header file
directly except the main one.
Signed-off-by: Lennart Poettering <lennart@poettering.net> Reviewed-By: Jan Safranek <jsafrane@redhat.com> Acked-by: Dhaval Giani <dhaval.giani@gmail.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Dhaval Giani [Thu, 18 Feb 2010 14:56:31 +0000 (15:56 +0100)]
libcgroup: Add pkg-config data
libcgroup was not making an entry into the pkg-config database, which
makes life easier when using multiple libraries. Add the needed data
in order to be registered with the pkg-config database on installation.
Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com> Reviewed-by: Jan Safranek <jsafrane@redhat.com> Acked-by: Lennart Poettering <lennnart@poettering.net>
Jan Safranek [Fri, 12 Mar 2010 15:50:20 +0000 (16:50 +0100)]
Split header file III
Changelog:
- since there are no global macros, base.h is gone
- since there is no base.h, all headers need to include <features.h> to get
__BEGIN_DECLS
- new init.h with cgroup_init() and cgroup_get_subsys_mount_point()
- new error.h with error handling enum and related stuff
- use #ifndef _LIBCGROUP_*_H instead _LIBCG_*_H in header guards
- fix few checkpatch complaints (long lines, whitespaces, ...)
The patch includes Makefile and .spec changes. I tested it compiles,
make dist produces tarball with all headers, so does also the rpm.
'make' should automatically catch all changes in new headers and
recompile dependent (=all) sources when any header changes.
libcgroup.h
- does not declare anything, it just includes all the other files. In
future, it might contain base of doxygen documentation (some
introduction etc.)
libcgroup/error.h
- the big enum with errors + error related functions
libcgroup/init.h
- libcgroup_init() and cgroup_get_subsys_mount_point()
libcgroup/groups.h
- group manipulation stuff (create/modify/delete/free, incl. controllers and
get/set values) + definition of struct cgroup (=must be included by
libcgroup/tasks.h, which needs it)
libcgroup/iterators.h
- various walks, *_begin/next/end
In addition, I probably removed some #includes, which are not needed now when
looking for the minimal #include set to build the project. I also hope I did not
miss any function declaration or macro...
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Jan Safranek [Fri, 12 Mar 2010 15:50:10 +0000 (16:50 +0100)]
Move private definitions to private header
Most of the macro definitions in licgroup.h are internal, let's move them
to private header. Applications should not depend on them. The only one
really needed is CG_VALUE_MAX, which is used in struct cgroup_stat.
Signed-off-by: Jan Safranek <jsafrane@redhat.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Jon Bernard [Tue, 9 Mar 2010 21:10:39 +0000 (16:10 -0500)]
Use memset to initialize sigaction struct
The sa_restorer field is not present on some architectures, like alpha.
By using memset, the structure is initialized appropriately regardless of
struct contents.
Signed-off-by: Jon Bernard <jbernard@debian.org> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
Chris [Tue, 9 Mar 2010 16:04:46 +0000 (11:04 -0500)]
init script can miss default group
If there is a directive like *:httpd before * in the cgconfig file, all
processes end up being moved into the wrong group on cgconfig startup, and
the default group is never made. This fixes it for me:
fix cgroup_get_value_string problem with *.stat output
fix cgroup_get_value_string problem with *.stat output
the problem was in the low limit for value for the output of stat variables - now there are used the functions cgroup_read_stats_{begin/next/end} for this purpose
v2:
removed bunch of unnecessary error messages
This patch adds to cgget option -a:
-a print the variables for all controllers which consists given cgroup
adds new option -g to cgget command
* the option has one argument - controller
* cgget -g devices / returns the values of all variables of controller
devices
* the option could be used multiple times
Ken'ichi Ohmichi [Thu, 28 Jan 2010 05:45:48 +0000 (11:15 +0530)]
[PATCH-v2] Add the write error handling to cg_set_control_value().
Changelog since v1:
o Use fopen/fprintf/fclose instead of open/write/close.
o Add the error handling against fclose.
cg_set_control_value() is the function for setting a value to a file
of cgroup file system. And current function does not handle the error
of writing to a file. So we cannot know whether setting value is
enable or not. This patch add the error handling for knowing it.