[PATCH] lua: always return luaL_error in actions
by Pino Toscano
Even if luaL_error is a "no return" function for the Lua runtime, adopt
also in action functions the "return" idiom recommeded for it.
This also helps code analyzers in not thinking that "g" might still be
null after the null check followed by luaL_error.
---
generator/lua.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/generator/lua.ml b/generator/lua.ml
index 9bd4006..5d5619c 100644
--- a/generator/lua.ml
+++ b/generator/lua.ml
@@ -482,8 +482,8 @@ guestfs_lua_delete_event_callback (lua_State *L)
pr "\n";
pr " if (g == NULL)\n";
- pr " luaL_error (L, \"Guestfs.%%s: handle is closed\",\n";
- pr " \"%s\");\n" name;
+ pr " return luaL_error (L, \"Guestfs.%%s: handle is closed\",\n";
+ pr " \"%s\");\n" name;
pr "\n";
iteri (
--
1.9.3
10 years, 3 months
[PATCH] rescue: fix sscanf placeholders for --smp and --memsize
by Pino Toscano
Use %d to parse them as int (since the variables for them as int)
instead of %u, even if they both need to be at least > 0.
--smp was already checked to be >= 1 while --memsize not, so check that
the specified memory size is not < 128 (which is semi-arbitrary, but
enough as a minimum threshold).
---
rescue/rescue.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/rescue/rescue.c b/rescue/rescue.c
index dc56d4b..1c556e5 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -157,7 +157,7 @@ main (int argc, char *argv[])
else
format = optarg;
} else if (STREQ (long_options[option_index].name, "smp")) {
- if (sscanf (optarg, "%u", &smp) != 1) {
+ if (sscanf (optarg, "%d", &smp) != 1) {
fprintf (stderr, _("%s: could not parse --smp parameter '%s'\n"),
program_name, optarg);
exit (EXIT_FAILURE);
@@ -208,11 +208,19 @@ main (int argc, char *argv[])
break;
case 'm':
- if (sscanf (optarg, "%u", &memsize) != 1) {
+ if (sscanf (optarg, "%d", &memsize) != 1) {
fprintf (stderr, _("%s: could not parse memory size '%s'\n"),
program_name, optarg);
exit (EXIT_FAILURE);
}
+ /* Check with a semi-arbitrary value, but avoids too small values
+ * (including <= 0)
+ */
+ if (memsize < 128) {
+ fprintf (stderr, _("%s: memory size %d is too small\n"),
+ program_name, memsize);
+ exit (EXIT_FAILURE);
+ }
break;
case 'r':
--
1.9.3
10 years, 3 months
[PATCH 0/2] Fix errors found by Clang static analyzer
by Peter Wu
Hi,
Here is one trivial initialization fix and another patch to convert a huge macro
to an inline function. The result of the expansion would show up in an assertion
which triggered a -Woverlength-strings warning.
Peter Wu (2):
Fix garbage return value on error
Fix overly long assertion string
lib/hivex-internal.h | 28 ++++++++++++++++------------
lib/node.c | 18 +++++++++---------
lib/utf16.c | 2 +-
lib/value.c | 14 +++++++-------
lib/write.c | 22 +++++++++++-----------
5 files changed, 44 insertions(+), 40 deletions(-)
--
2.0.2
10 years, 3 months
Re: [Libguestfs] [PATCH 2/2] Use setfiles from the appliance for the SELinux relabel (RHBZ#1089100).
by Richard W.M. Jones
[Including libguestfs mailing list this time]
On Tue, May 27, 2014 at 06:05:15AM -0700, Colin Walters wrote:
> On Tue, May 27, 2014, at 02:04 AM, Richard W.M. Jones wrote:
> >
> > I'm still anxious for Colin to tell us if this API is suitable for his
> > needs.
>
> I'd like an API that allows me to only relabel *unlabeled* files.
> The use case here is: I have an existing disk image with an OS,
> I want to inject e.g. a systemd service into it. If I do this offline
> from libguestfs, the injected /usr/libexec/mydaemon and
> /usr/lib/systemd/system/mydaemon.service
> won't be labeled, but everything else will be.
>
> > I'm guessing that OStree does not have /etc/selinux/config,
>
> Right, it's in the "deployment root" of
> /ostree/deploy/$osname/deploy/$checksum/etc/selinux/config
Got it:
><fs> ll /ostree/deploy/project-atomic-controller/deploy/afc1794b4b42df77edf1988897b167573b99e299fa39a15b07b235a0e7387d02.0/etc/selinux/targeted/contexts/files/file_contexts
-rw-r--r--. 1 root root 352240 Apr 14 20:14 /sysroot/ostree/deploy/project-atomic-controller/deploy/afc1794b4b42df77edf1988897b167573b99e299fa39a15b07b235a0e7387d02.0/etc/selinux/targeted/contexts/files/file_contexts
> To figure that out you'd want to use the OSTree APIs; and then it
> introduces
> further questions around *which* deployments you want to relabel. All?
> Only
> one (the default?).
>
> What I do currently in my scripts is only relabel the default, and that
> would
> be the best default for an API.
>
> But a totally valid thing to do with OSTree is - say you're running
> RHEL7,
> and you want to check whether the latest Fedora kernel fixes an issue
> you're seeing. You can use ostree to dynamically parallel install
> Fedora content in a new deployment root, try it with near-total
> safety[1],
> and then if it doesn't work, just delete it and free up the space.
So I think an API which looks like this ...
required params:
None
optional params:
path =>
Either a directory to be relabelled recursively, or a single
file (defaults to "/").
root =>
Inspection root of guest. Optional, only makes sense when
'contexts' param is *omitted*.
contexts =>
The `file_contexts' file. Defaults to
/etc/selinux/$selinux_type/contexts/files/file_contexts
OSTree would probably want to pass:
/ostree/deploy/$osname/deploy/$checksum/etc/selinux/targeted/contexts/files/file_contexts
Inspection could be updated to parse /etc/selinux/config in order to
get the default SELinux policy and pass it back through an API such as
`inspect-get-selinux-type'.
If 'contexts' is omitted, 'root' must be supplied, and it causes an
internal call to guestfs_inspect_get_selinux_type (g, root) in order
to get the default policy.
What do you think?
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
10 years, 3 months
[PATCH] daemon: add and use a reply_with_unavailable_feature macro
by Pino Toscano
Handy macro to reply the right way for an unavailable feature.
While generally used so far in generated code, it can shorten that a
bit, and avoid copy&paste when wanting to do manual feature checking.
---
daemon/daemon.h | 6 ++++++
generator/daemon.ml | 6 +-----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 94537b7..fb74e91 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -245,6 +245,12 @@ extern void reply_with_perror_errno (int err, const char *fs, ...)
__attribute__((format (printf,2,3)));
#define reply_with_error(...) reply_with_error_errno(0, __VA_ARGS__)
#define reply_with_perror(...) reply_with_perror_errno(errno, __VA_ARGS__)
+#define reply_with_unavailable_feature(feature) \
+ reply_with_error_errno (ENOTSUP, \
+ "feature '%s' is not available in this\n" \
+ "build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\n" \
+ "how to check for the availability of features.", \
+ feature)
/* daemon functions that receive files (FileIn) should call
* receive_file for each FileIn parameter.
diff --git a/generator/daemon.ml b/generator/daemon.ml
index ca748d2..951729c 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -280,11 +280,7 @@ cleanup_free_mountable (mountable_t *mountable)
pr " if (! optgroup_%s_available ()) {\n" group;
if is_filein then
pr " cancel_receive ();\n";
- pr " reply_with_error_errno (ENOTSUP,\n";
- pr " \"feature '%%s' is not available in this\\n\"\n";
- pr " \"build of libguestfs. Read 'AVAILABILITY' in the guestfs(3) man page for\\n\"\n";
- pr " \"how to check for the availability of features.\",\n";
- pr " \"%s\");\n" group;
+ pr " reply_with_unavailable_feature (\"%s\");\n" group;
pr " goto done_no_free;\n";
pr " }\n";
pr "\n"
--
1.9.3
10 years, 3 months