]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
samples/setuid.c: fix checkpatch.pl warnings
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 16 Mar 2022 16:07:47 +0000 (21:37 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 16 Mar 2022 21:38:20 +0000 (15:38 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
samples/c/setuid.c

index f7a0593758324d73ba78b34947f0d0ef317b077e..a51fdb3458462c635779495b2c3cbc1abba567a1 100644 (file)
@@ -5,14 +5,15 @@
  * Author:      Steve Olivieri <sjo@redhat.com>
  */
 
-#include <stdio.h>
 #include <stdlib.h>
-#include <sys/types.h>
 #include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
 #include <pwd.h>
 #include <grp.h>
-#include <errno.h>
-#include <string.h>
+
+#include <sys/types.h>
 
 /*
  * 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 <uid_value> \n", argv[0]);
+               printf("Usage: %s <uid_value>\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;