Skip to contentSkip to conversation

mdadm: monitor event argument passing

PATCH In review Paul Clements 2 participants 3 messages Mar 31, 2006 – Apr 3, 2006 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdadm: monitor event argument passing

I've been looking at the mdadm monitor, and thought it might be useful if it allowed extra context information (in the form of command line arguments) to be sent to the event program, so instead of just:

# mdadm -F /dev/md0 -p "md_event"

you could do something like:

# mdadm -F /dev/md0 -p "md_event -i <some_info>"

And the "-i <some_info>" will be passed on the command line to the event program. Of course you can usually figure out what the extra context should be in the event program itself, but it may take more work.

Here's a short patch (against mdadm 2.4) that does this.

Thanks,
Paul

 Monitor.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletion(-)
Monitor.c +22 -1
@@ -464,6 +464,27 @@ static void alert(char *event, char *dev
 		  int dosyslog)
 {
 	int priority;
+	int cnt = 0;
+	char path[PATH_MAX];
+	char *space, *ptr;
+	char *args[256];
+
+	if (cmd) {
+		strcpy(path, cmd);
+		ptr = path;
+		do {
+			space = strchr(ptr, ' ');
+			if (!space)
+				break;
+			args[cnt++] = ptr;
+			*space = 0;
+			ptr = space+1;
+		} while (1);
+		args[cnt++] = ptr;
+		args[cnt++] = event;
+		args[cnt++] = dev;
+		args[cnt++] = disc;
+	}
 
 	if (!cmd && !mailaddr) {
 		time_t now = time(0);
@@ -479,7 +500,7 @@ static void alert(char *event, char *dev
 		case -1:
 			break;
 		case 0:
-			execl(cmd, cmd, event, dev, disc, NULL);
+			execv(path, args); //execl(cmd,  cmd, event, dev, disc, NULL);
 			exit(2);
 		}
 	}
#1 lore raw
Quoted 7 lines · On Friday March 31, [email protected] wrote:

I've been looking at the mdadm monitor, and thought it might be useful if it allowed extra context information (in the form of command line arguments) to be sent to the event program, so instead of just:

# mdadm -F /dev/md0 -p "md_event"
Quoted 7 lines

you could do something like:

# mdadm -F /dev/md0 -p "md_event -i <some_info>"

And the "-i <some_info>" will be passed on the command line to the event program. Of course you can usually figure out what the extra context should be in the event program itself, but it may take more work.

I would recommend the use of environment variables for this:

md_event_context=<some_info> mdadm -F /dev/md0 -p md_event

It is true that this cannot be specified in mdadm.conf, but I don't think you really need it at all in that context. The <some_info> can be explicit in the script rather than in mdadm.conf.

Does that work for you?

NeilBrown

#2 lore raw
Quoted 10 lines · Neil Brown
Quoted 8 lines · On Friday March 31, [email protected] wrote:

I've been looking at the mdadm monitor, and thought it might be useful if it allowed extra context information (in the form of command line arguments) to be sent to the event program, so instead of just:

# mdadm -F /dev/md0 -p "md_event"

you could do something like:

# mdadm -F /dev/md0 -p "md_event -i <some_info>"
Quoted 8 lines
Quoted 1 line

And the "-i <some_info>" will be passed on the command line to the event program. Of course you can usually figure out what the extra context should be in the event program itself, but it may take more work.

I would recommend the use of environment variables for this:

md_event_context=<some_info> mdadm -F /dev/md0 -p md_event

Does that work for you?

Yes, that would work.

Thanks,
Paul