]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/ipcmk.c
Make the ways of using output stream consistent in usage()
[thirdparty/util-linux.git] / sys-utils / ipcmk.c
index df836525a1a743b417a57df4b6beb110168e9990..67a7637f629ef4a7543b1465fb4acf2147f408d4 100644 (file)
@@ -40,7 +40,7 @@ static int create_shm(size_t size, int permission)
 {
        key_t key;
 
-       random_get_bytes(&key, sizeof(key));
+       ul_random_get_bytes(&key, sizeof(key));
        return shmget(key, size, permission | IPC_CREAT);
 }
 
@@ -48,7 +48,7 @@ static int create_msg(int permission)
 {
        key_t key;
 
-       random_get_bytes(&key, sizeof(key));
+       ul_random_get_bytes(&key, sizeof(key));
        return msgget(key, permission | IPC_CREAT);
 }
 
@@ -56,7 +56,7 @@ static int create_sem(int nsems, int permission)
 {
        key_t key;
 
-       random_get_bytes(&key, sizeof(key));
+       ul_random_get_bytes(&key, sizeof(key));
        return semget(key, nsems, permission | IPC_CREAT);
 }
 
@@ -76,8 +76,12 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -p, --mode <mode>        permission for the resource (default is 0644)\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(26));
-       printf(USAGE_MAN_TAIL("ipcmk(1)"));
+       fprintf(out, USAGE_HELP_OPTIONS(26));
+
+       fputs(USAGE_ARGUMENTS, out);
+       fprintf(out, USAGE_ARG_SIZE(_("<size>")));
+
+       fprintf(out, USAGE_MAN_TAIL("ipcmk(1)"));
 
        exit(EXIT_SUCCESS);
 }
@@ -102,7 +106,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) {
                switch(opt) {
@@ -118,14 +122,18 @@ int main(int argc, char **argv)
                        ask_sem = 1;
                        break;
                case 'p':
-                       permission = strtoul(optarg, NULL, 8);
+               {
+                       char *end = NULL;
+                       errno = 0;
+                       permission = strtoul(optarg, &end, 8);
+                       if (errno || optarg == end || (end && *end))
+                               err(EXIT_FAILURE, _("failed to parse mode"));
                        break;
+               }
                case 'h':
                        usage();
-                       break;
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
+                       print_version(EXIT_SUCCESS);
                default:
                        errtryhelp(EXIT_FAILURE);
                }