From 123cccd8332df85343891e01d050cda2cf221a78 Mon Sep 17 00:00:00 2001 From: lhb-jr Date: Fri, 21 Mar 2014 12:04:32 -0400 Subject: workaround 'discards const' warning during compile modified: src/udev/udev-builtin-kmod.c Temporary copies of the arguments to the 'execv' call are made so that gcc doesn't give, possibly confusing warning about 'discarding const' during compilation. --- src/udev/udev-builtin-kmod.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index a9704c101c..57e2a9af7f 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -67,8 +67,21 @@ static int load_module(struct udev *udev, const char *alias) kmod_module_unref_list(list); return err; #else - char *const argv[] = { MODPROBE, "-bq", alias, 0 }; - return execute_command(MODPROBE, argv); + int retval; + + /* + These 3 temporaries are needed because argv (below) is a const pointer, not pointer to const + */ + char *tmp_alias = strdup(alias); + char *tmp_modprobe = strdup(MODPROBE); + char *tmp_bq = strdup("-bq"); + char *const argv[] = { tmp_modprobe, tmp_bq, tmp_alias, 0 }; + + retval = execute_command(MODPROBE, argv); + + free(tmp_alias); + free(tmp_modprobe); + free(tmp_bq); #endif } -- cgit v1.2.3-54-g00ecf From a45adc4f91de8b6a27387fe2ccd16b8b0f613d65 Mon Sep 17 00:00:00 2001 From: lhb-jr Date: Fri, 21 Mar 2014 12:19:04 -0400 Subject: completed fix to 'discard const' warning modified: src/udev/udev-builtin-kmod.c --- src/udev/udev-builtin-kmod.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index 57e2a9af7f..a8792e097f 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -38,10 +38,10 @@ static struct kmod_ctx *ctx; static int load_module(struct udev *udev, const char *alias) { + int err; #ifdef HAVE_LIBKMOD struct kmod_list *list = NULL; struct kmod_list *l; - int err; err = kmod_module_new_from_lookup(ctx, alias, &list); if (err < 0) @@ -65,9 +65,7 @@ static int load_module(struct udev *udev, const char *alias) } kmod_module_unref_list(list); - return err; #else - int retval; /* These 3 temporaries are needed because argv (below) is a const pointer, not pointer to const @@ -77,12 +75,15 @@ static int load_module(struct udev *udev, const char *alias) char *tmp_bq = strdup("-bq"); char *const argv[] = { tmp_modprobe, tmp_bq, tmp_alias, 0 }; - retval = execute_command(MODPROBE, argv); + err = execute_command(MODPROBE, argv); free(tmp_alias); free(tmp_modprobe); free(tmp_bq); #endif + /* both 'kmod_module_new_from_lookup' and 'execute_command' return <0 on error + so it is ok to assign both to 'err' */ + return err; } _printf_(6,0) -- cgit v1.2.3-54-g00ecf