OSDN Git Service

partprobe: Detect/report any error when writing to stdout.
authorJim Meyering <jim@meyering.net>
Sun, 25 Feb 2007 17:46:05 +0000 (18:46 +0100)
committerJim Meyering <jim@meyering.net>
Sun, 25 Feb 2007 17:46:05 +0000 (18:46 +0100)
* partprobe/Makefile.am (partprobe_LDADD): Add lib/libparted.la.
* partprobe/partprobe.c:
Include "closeout.h" for close_stdout.
Include "version-etc.h" for version_etc prototype.
Declare global, program_name.
(PROGRAM_NAME, AUTHORS): Define.
(help): Use PROGRAM_NAME, rather than hard-coding it.
(version): Use gnulib's version_etc.
(main): Set program_name.
Use atexit to close stdout carefully upon exit.

partprobe/Makefile.am
partprobe/partprobe.c

index a0dffdc..4b236e1 100644 (file)
@@ -4,8 +4,11 @@ sbin_PROGRAMS = partprobe
 
 partprobe_SOURCES = partprobe.c
 
-partprobe_LDADD = @INTLLIBS@ @LIBS@ \
-              $(top_builddir)/libparted/libparted.la @PARTED_LIBS@ 
+partprobe_LDADD = \
+  $(top_builddir)/lib/libparted.la \
+  $(top_builddir)/libparted/libparted.la \
+  $(INTLLIBS) $(LIBS) \
+  $(PARTED_LIBS)
 
 partprobe_LDFLAGS = @PARTEDLDFLAGS@
 
index f86c370..9a26e9a 100644 (file)
@@ -1,6 +1,6 @@
 /*
     partprobe - informs the OS kernel of partition layout
-    Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+    Copyright (C) 2001, 2002, 2007 Free Software Foundation, Inc.
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
  *
  *      CFLAGS=-Os ./configure --disable-nls --disable-shared --disable-debug
  *                 --enable-discover-only
- * 
+ *
  * And strip(1) afterwards!
  */
 
 #include <stdio.h>
 #include <string.h>
 
+#include "closeout.h"
+#include "version-etc.h"
+
+#define AUTHORS \
+  "<http://parted.alioth.debian.org/cgi-bin/trac.cgi/browser/AUTHORS>"
+
+/* The official name of this program (e.g., no `g' prefix).  */
+#define PROGRAM_NAME "partprobe"
+
+char *program_name;
+
 /* initialized to 0 according to the language lawyers */
 static int     opt_no_probe;
 static int     opt_summary;
@@ -98,16 +109,17 @@ error:
 static void
 help ()
 {
-       printf ("usage:  partprobe [-d] [-h] [-s] [-v] [DEVICES...]\n\n"
+       printf ("usage: %s [-d] [-h] [-s] [-v] [DEVICES...]\n\n"
                "-d     don't update the kernel\n"
                "-s     print a summary of contents\n"
-               "-v     version info\n");
+               "-v     version info\n", PROGRAM_NAME);
 }
 
 static void
 version ()
 {
-       printf ("partprobe (" PACKAGE VERSION ")\n");
+       version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, VERSION, AUTHORS,
+                     (char *) NULL);
 }
 
 int
@@ -118,6 +130,9 @@ main (int argc, char* argv[])
        PedDevice*      dev;
        int             status = 1;
 
+       program_name = argv[0];
+       atexit (close_stdout);
+
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
                        dev_passed = 1;
@@ -158,4 +173,3 @@ main (int argc, char* argv[])
 
        return !status;
 }
-