From: Kamalesh Babulal Date: Wed, 16 Mar 2022 16:07:47 +0000 (+0530) Subject: samples/setuid.c: fix checkpatch.pl warnings X-Git-Tag: v3.0~148 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbbaec0e5d6bd46b9022560e00b1a1f1673d83ad;p=thirdparty%2Flibcgroup.git samples/setuid.c: fix checkpatch.pl warnings Fix all of the warnings/errors reported by Linux Kernel's checkpatch.pl, except SPDX_LICENSE_TAG. It also introduces reverse xmas tree local variable declarations and header file reordering. In summary, this patch fixes the following checkpatch.pl recommendations: 0 errors, 1 warnings, 82 lines checked Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/samples/c/setuid.c b/samples/c/setuid.c index f7a05937..a51fdb34 100644 --- a/samples/c/setuid.c +++ b/samples/c/setuid.c @@ -5,14 +5,15 @@ * Author: Steve Olivieri */ -#include #include -#include #include +#include +#include +#include #include #include -#include -#include + +#include /* * This is just a simple program for changing a UID or a GID. Comment out @@ -30,22 +31,24 @@ int main(int argc, char *argv[]) int ret = 0; if (argc < 2) { - printf("Usage: %s \n", argv[0]); + printf("Usage: %s \n", argv[0]); goto finished; } pwd = getpwnam(argv[1]); if (!pwd) { fprintf(stderr, "getpwnam() failed: %s\n", - strerror(errno)); + strerror(errno)); ret = -errno; goto finished; } + uid = pwd->pw_uid; fprintf(stdout, "Setting UID to %s (%d).\n", pwd->pw_name, uid); - if ((ret = setuid(uid))) { + ret = setuid(uid); + if (ret != 0) { fprintf(stderr, "Call to setuid() failed with error: %s\n", - strerror(errno)); + strerror(errno)); ret = -errno; goto finished; } @@ -63,9 +66,8 @@ int main(int argc, char *argv[]) // } // } - while (1) { + while (1) usleep(3000000); - } finished: return ret;