From: adilger Date: Mon, 23 Jun 2003 18:20:53 +0000 (+0000) Subject: Use a better variable name than "i" for the open file descriptor. X-Git-Tag: v1_7_110~2^11~109 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=fcde5378091005c6b8cdbc5d53c8fa43522a3891;p=fs%2Flustre-release.git Use a better variable name than "i" for the open file descriptor. --- diff --git a/lustre/tests/runas.c b/lustre/tests/runas.c index 8731699..11e888b 100644 --- a/lustre/tests/runas.c +++ b/lustre/tests/runas.c @@ -11,11 +11,10 @@ #define DEBUG 0 -void -Usage_and_abort() +void Usage_and_abort(void) { - fprintf(stderr, "Usage: runas -u user_id [ -g grp_id ]" \ - " command_to_be_run \n"); + fprintf(stderr, "Usage: runas -u user_id [ -g grp_id ]" + " command_to_be_run \n"); exit(-1); } @@ -27,8 +26,7 @@ Usage_and_abort() // ROOT runs "runas" for free // Other users run "runas" requires chmod 6755 "command_to_be_run" -int -main(int argc, char**argv) +int main(int argc, char **argv) { char **my_argv; int status; @@ -38,9 +36,8 @@ main(int argc, char**argv) uid_t user_id; gid_t grp_id; - if(argc == 1) { + if (argc == 1) Usage_and_abort(); - } // get UID and GID while ((c = getopt (argc, argv, "+u:g:h")) != -1) { @@ -48,58 +45,56 @@ main(int argc, char**argv) case 'u': user_id = (uid_t)atoi(optarg); uid_is_set = 1; - if(!gid_is_set) { - grp_id = user_id; - } - break; - - case 'g': - grp_id = (gid_t)atoi(optarg); - gid_is_set = 1; - break; - - case 'h': - Usage_and_abort (); - break; - - default: - // fprintf(stderr, "Bad parameters.\n"); - // Usage_and_abort (); - } + if (!gid_is_set) + grp_id = user_id; + break; + + case 'g': + grp_id = (gid_t)atoi(optarg); + gid_is_set = 1; + break; + + case 'h': + Usage_and_abort(); + break; + + default: + //fprintf(stderr, "Bad parameters.\n"); + //Usage_and_abort (); + } } - if (!uid_is_set){ - Usage_and_abort (); - } - + if (!uid_is_set) + Usage_and_abort(); - if(optind == argc) { + if (optind == argc) { fprintf(stderr, "Bad parameters.\n"); Usage_and_abort(); } // assemble the command my_argv = (char**)malloc(sizeof(char*)*(argc+1-optind)); - if(my_argv == NULL) { - fprintf(stderr, "Error in allocating memory. (%s)\n", strerror(errno)); - exit(-1); - } - - for(i=optind; i< argc; i++) { + if (my_argv == NULL) { + fprintf(stderr, "Error in allocating memory. (%s)\n", + strerror(errno)); + exit(-1); + } + + for (i = optind; i < argc; i++) { my_argv[i-optind] = argv[i]; -// printf("%s\n",my_argv[i-optind]); + //printf("%s\n",my_argv[i-optind]); } - my_argv[i-optind]=NULL; + my_argv[i-optind] = NULL; #if DEBUG - system("whoami"); + system("whoami"); #endif // set GID - status = setregid(grp_id, grp_id ); - if( status == -1) { + status = setregid(grp_id, grp_id); + if (status == -1) { fprintf(stderr, "Cannot change grp_ID to %d, errno=%d (%s)\n", - grp_id, errno, strerror(errno) ); + grp_id, errno, strerror(errno) ); exit(-1); } @@ -112,10 +107,9 @@ main(int argc, char**argv) } - fprintf(stderr, "running as USER(%d), Grp (%d): ", - user_id, grp_id ); + fprintf(stderr, "running as USER(%d), Grp (%d): ", user_id, grp_id ); - for(i=0; i