]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Change way of printing name of a process
authorPawel Baldysiak <pawel.baldysiak@intel.com>
Wed, 11 Feb 2015 21:25:03 +0000 (22:25 +0100)
committerNeilBrown <neilb@suse.de>
Thu, 12 Feb 2015 01:11:01 +0000 (12:11 +1100)
Sometimes mdadm prints messages with wrong name "mdmon",
and vice versa.
This patch solves this problem by changing method of determining
process name.
Now "Name" will be set in const at start of a program,
previously was hardcoded as #define.

Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
Incremental.c
Monitor.c
ReadMe.c
mdadm.c
mdadm.h
mdmon.c
mdmon.h
super-intel.c
sysfs.c
xmalloc.c

diff --git a/Grow.c b/Grow.c
index 6ff225a95b1be081c5e4948b662dacc3d590cce4..4a01a3165f5c0ee7522d4e587c5f1cf8d203a873 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -1919,7 +1919,7 @@ size_change_error:
                int err;
                err = remove_disks_for_takeover(st, sra, array.layout);
                if (err) {
                int err;
                err = remove_disks_for_takeover(st, sra, array.layout);
                if (err) {
-                       dprintf(Name": Array cannot be reshaped\n");
+                       dprintf("%s: Array cannot be reshaped\n", Name);
                        if (cfd > -1)
                                close(cfd);
                        rv = 1;
                        if (cfd > -1)
                                close(cfd);
                        rv = 1;
@@ -2133,7 +2133,7 @@ static int verify_reshape_position(struct mdinfo *info, int level)
                char *ep;
                unsigned long long position = strtoull(buf, &ep, 0);
 
                char *ep;
                unsigned long long position = strtoull(buf, &ep, 0);
 
-               dprintf(Name": Read sync_max sysfs entry is: %s\n", buf);
+               dprintf("%s: Read sync_max sysfs entry is: %s\n", Name, buf);
                if (!(ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))) {
                        position *= get_data_disks(level,
                                                   info->new_layout,
                if (!(ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))) {
                        position *= get_data_disks(level,
                                                   info->new_layout,
@@ -3494,8 +3494,8 @@ int reshape_container(char *container, char *devname,
                return 1;
        default: /* parent */
                if (!freeze_reshape)
                return 1;
        default: /* parent */
                if (!freeze_reshape)
-                       printf(Name ": multi-array reshape continues"
-                              " in background\n");
+                       printf("%s: multi-array reshape continues"
+                              " in background\n", Name);
                return 0;
        case 0: /* child */
                map_fork();
                return 0;
        case 0: /* child */
                map_fork();
@@ -3557,8 +3557,8 @@ int reshape_container(char *container, char *devname,
 
                fd = open_dev(mdstat->devnm);
                if (fd < 0) {
 
                fd = open_dev(mdstat->devnm);
                if (fd < 0) {
-                       printf(Name ": Device %s cannot be opened for reshape.",
-                              adev);
+                       printf("%s: Device %s cannot be opened for reshape.",
+                              Name, adev);
                        break;
                }
 
                        break;
                }
 
@@ -3573,8 +3573,8 @@ int reshape_container(char *container, char *devname,
                         * This is possibly interim until the behaviour of
                         * reshape_array is resolved().
                         */
                         * This is possibly interim until the behaviour of
                         * reshape_array is resolved().
                         */
-                       printf(Name ": Multiple reshape execution detected for "
-                              "device  %s.", adev);
+                       printf("%s: Multiple reshape execution detected for "
+                              "device  %s.", Name, adev);
                        close(fd);
                        break;
                }
                        close(fd);
                        break;
                }
@@ -4611,7 +4611,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                        st->ss->free_super(st);
                        offsets[j] = dinfo.data_offset * 512;
                }
                        st->ss->free_super(st);
                        offsets[j] = dinfo.data_offset * 512;
                }
-               printf(Name ": restoring critical section\n");
+               printf("%s: restoring critical section\n", Name);
 
                if (restore_stripes(fdlist, offsets,
                                    info->array.raid_disks,
 
                if (restore_stripes(fdlist, offsets,
                                    info->array.raid_disks,
index 13b68bc0adea3fb86038fd7f1d4d13dcab0a1b90..38c9989b30ae1ca8f463415cd120977953fbffb2 100644 (file)
@@ -1710,9 +1710,9 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
        char buf[32];
 
        if (!id_path)
        char buf[32];
 
        if (!id_path)
-               dprintf(Name ": incremental removal without --path <id_path> "
+               dprintf("%s: incremental removal without --path <id_path> "
                        "lacks the possibility to re-add new device in this "
                        "lacks the possibility to re-add new device in this "
-                       "port\n");
+                       "port\n", Name);
 
        if (strchr(devname, '/')) {
                pr_err("incremental removal requires a "
 
        if (strchr(devname, '/')) {
                pr_err("incremental removal requires a "
index 66d67baf5c987e107df52e7ad4cdd8e874755d29..43470f8e57196aea79de9b6fa6e207505c1ffc62 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -381,14 +381,14 @@ static void alert(char *event, char *dev, char *disc, struct alert_info *info)
                        if (info->mailfrom)
                                fprintf(mp, "From: %s\n", info->mailfrom);
                        else
                        if (info->mailfrom)
                                fprintf(mp, "From: %s\n", info->mailfrom);
                        else
-                               fprintf(mp, "From: " Name " monitoring <root>\n");
+                               fprintf(mp, "From: %s monitoring <root>\n", Name);
                        fprintf(mp, "To: %s\n", info->mailaddr);
                        fprintf(mp, "Subject: %s event on %s:%s\n\n",
                                event, dev, hname);
 
                        fprintf(mp,
                                "This is an automatically generated"
                        fprintf(mp, "To: %s\n", info->mailaddr);
                        fprintf(mp, "Subject: %s event on %s:%s\n\n",
                                event, dev, hname);
 
                        fprintf(mp,
                                "This is an automatically generated"
-                               " mail message from " Name "\n");
+                               " mail message from %s\n", Name);
                        fprintf(mp, "running on %s\n\n", hname);
 
                        fprintf(mp,
                        fprintf(mp, "running on %s\n\n", hname);
 
                        fprintf(mp,
index 445c38824c521e5f0e42d6c591279dc570c4b878..87a4916b80970da9221e6c2d9fc2b38d732e3d21 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -30,7 +30,7 @@
 #ifndef VERS_DATE
 #define VERS_DATE "21st August 2014"
 #endif
 #ifndef VERS_DATE
 #define VERS_DATE "21st August 2014"
 #endif
-char Version[] = Name " - v" VERSION " - " VERS_DATE "\n";
+char Version[] = "mdadm - v" VERSION " - " VERS_DATE "\n";
 
 /*
  * File: ReadMe.c
 
 /*
  * File: ReadMe.c
diff --git a/mdadm.c b/mdadm.c
index c856fcd6335020c00d0edad82616d7109378aa55..475c71ca3f219b1cfc493888007fd24670559c56 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -38,6 +38,7 @@ static int misc_list(struct mddev_dev *devlist,
                     struct mddev_ident *ident,
                     char *dump_directory,
                     struct supertype *ss, struct context *c);
                     struct mddev_ident *ident,
                     char *dump_directory,
                     struct supertype *ss, struct context *c);
+const char Name[] = "mdadm";
 
 int main(int argc, char *argv[])
 {
 
 int main(int argc, char *argv[])
 {
@@ -771,12 +772,12 @@ int main(int argc, char *argv[])
                        if (strcmp(c.update,"?") == 0 ||
                            strcmp(c.update, "help") == 0) {
                                outf = stdout;
                        if (strcmp(c.update,"?") == 0 ||
                            strcmp(c.update, "help") == 0) {
                                outf = stdout;
-                               fprintf(outf, Name ": ");
+                               fprintf(outf, "%s: ", Name);
                        } else {
                                outf = stderr;
                                fprintf(outf,
                        } else {
                                outf = stderr;
                                fprintf(outf,
-                                       Name ": '--update=%s' is invalid.  ",
-                                       c.update);
+                                       "%s: '--update=%s' is invalid.  ",
+                                       Name, c.update);
                        }
                        fprintf(outf, "Valid --update options are:\n"
                "     'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
                        }
                        fprintf(outf, "Valid --update options are:\n"
                "     'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
diff --git a/mdadm.h b/mdadm.h
index fc1fd31854292042d67b554ae42c0bbc51f5d280..c8d079cfe0ead43d5dfe27464b32d8e78a6ea385 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -180,6 +180,8 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
+extern const char Name[];
+
 /* general information that might be extracted from a superblock */
 struct mdinfo {
        mdu_array_info_t        array;
 /* general information that might be extracted from a superblock */
 struct mdinfo {
        mdu_array_info_t        array;
@@ -262,8 +264,6 @@ struct createinfo {
        struct supertype *supertype;
 };
 
        struct supertype *supertype;
 };
 
-#define Name "mdadm"
-
 enum mode {
        ASSEMBLE=1,
        BUILD,
 enum mode {
        ASSEMBLE=1,
        BUILD,
@@ -1457,7 +1457,7 @@ static inline int xasprintf(char **strp, const char *fmt, ...) {
        return ret;
 }
 
        return ret;
 }
 
-#define pr_err(fmt ...) fprintf(stderr, Name ": " fmt)
+#define pr_err(fmt, args...) fprintf(stderr, "%s: "fmt, Name, ##args)
 #define cont_err(fmt ...) fprintf(stderr, "       " fmt)
 
 void *xmalloc(size_t len);
 #define cont_err(fmt ...) fprintf(stderr, "       " fmt)
 
 void *xmalloc(size_t len);
diff --git a/mdmon.c b/mdmon.c
index 27045a122cb4bbf4d73c3bc2d5ed8020cdd03103..ee12b7c788ac0fc969499204343db8f39b124843 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -67,6 +67,8 @@
 #include       "mdadm.h"
 #include       "mdmon.h"
 
 #include       "mdadm.h"
 #include       "mdmon.h"
 
+char const Name[] = "mdmon";
+
 struct active_array *discard_this;
 struct active_array *pending_discard;
 
 struct active_array *discard_this;
 struct active_array *pending_discard;
 
diff --git a/mdmon.h b/mdmon.h
index 5a8e1209822c3ff2ca3fe5ab95796ff085973766..aa750c6811e146c9cc9b402783600d47ef75b6cd 100644 (file)
--- a/mdmon.h
+++ b/mdmon.h
@@ -18,8 +18,7 @@
  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#undef pr_err
-#define pr_err(fmt ...) fprintf(stderr, "mdmon: " fmt)
+extern const char Name[];
 
 enum array_state { clear, inactive, suspended, readonly, read_auto,
                   clean, active, write_pending, active_idle, bad_word};
 
 enum array_state { clear, inactive, suspended, readonly, read_auto,
                   clean, active, write_pending, active_idle, bad_word};
index 4b23b9ab7dde091b69ca9ec985a13acd13e28c85..d90033932a17462aaabd8b43a8c50ca309a4e4d2 100644 (file)
@@ -1386,7 +1386,7 @@ static int imsm_check_attributes(__u32 attributes)
                }
 
                if (not_supported)
                }
 
                if (not_supported)
-                       dprintf(Name "(IMSM): Unknown attributes : %x\n", not_supported);
+                       dprintf("%s (IMSM): Unknown attributes : %x\n", Name, not_supported);
 
                ret_val = 0;
        }
 
                ret_val = 0;
        }
diff --git a/sysfs.c b/sysfs.c
index 9a1d856960e82ba78d16b12b6da5cf4bf0efe455..ceab27f5eb1eb22f544bfc504e093eb2f08f6d43 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -413,8 +413,8 @@ int sysfs_set_str(struct mdinfo *sra, struct mdinfo *dev,
        n = write(fd, val, strlen(val));
        close(fd);
        if (n != strlen(val)) {
        n = write(fd, val, strlen(val));
        close(fd);
        if (n != strlen(val)) {
-               dprintf(Name ": failed to write '%s' to '%s' (%s)\n",
-                       val, fname, strerror(errno));
+               dprintf("%s: failed to write '%s' to '%s' (%s)\n",
+                       Name, val, fname, strerror(errno));
                return -1;
        }
        return 0;
                return -1;
        }
        return 0;
@@ -450,8 +450,8 @@ int sysfs_uevent(struct mdinfo *sra, char *event)
        n = write(fd, event, strlen(event));
        close(fd);
        if (n != (int)strlen(event)) {
        n = write(fd, event, strlen(event));
        close(fd);
        if (n != (int)strlen(event)) {
-               dprintf(Name ": failed to write '%s' to '%s' (%s)\n",
-                       event, fname, strerror(errno));
+               dprintf("%s: failed to write '%s' to '%s' (%s)\n",
+                       Name, event, fname, strerror(errno));
                return -1;
        }
        return 0;
                return -1;
        }
        return 0;
index 8d42a7c4ef4ebb57a7a2c71cd9cf887f9db98a15..75ae4e249cea07b4867b28084699b76f651d69bc 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -37,7 +37,8 @@ void *xmalloc(size_t len)
        char *msg;
        if (rv)
                return rv;
        char *msg;
        if (rv)
                return rv;
-       msg = Name ": memory allocation failure - aborting\n";
+       msg = ": memory allocation failure - aborting\n";
+       write(2, Name, strlen(Name));
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
@@ -47,7 +48,8 @@ void *xrealloc(void *ptr, size_t len)
        char *msg;
        if (rv)
                return rv;
        char *msg;
        if (rv)
                return rv;
-       msg = Name ": memory allocation failure - aborting\n";
+       msg =  ": memory allocation failure - aborting\n";
+       write(2, Name, strlen(Name));
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
@@ -57,7 +59,8 @@ void *xcalloc(size_t num, size_t size)
        char *msg;
        if (rv)
                return rv;
        char *msg;
        if (rv)
                return rv;
-       msg = Name ": memory allocation failure - aborting\n";
+       msg =  ": memory allocation failure - aborting\n";
+       write(2, Name, strlen(Name));
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
        exit(4+!!write(2, msg, strlen(msg)));
 }
 
@@ -67,6 +70,7 @@ char *xstrdup(const char *str)
        char *msg;
        if (rv)
                return rv;
        char *msg;
        if (rv)
                return rv;
-       msg = Name ": memory allocation failure - aborting\n";
+       msg =  ": memory allocation failure - aborting\n";
+       write(2, Name, strlen(Name));
        exit(4+!!write(2, msg, strlen(msg)));
 }
        exit(4+!!write(2, msg, strlen(msg)));
 }