All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Berra <bluca@comedia.it>
To: Neil Brown <neilb@cse.unsw.edu.au>
Cc: linux raid <linux-raid@vger.kernel.org>
Subject: small patches to mdadm
Date: Wed, 25 Aug 2004 09:22:36 +0200	[thread overview]
Message-ID: <20040825072235.GB5851@percy.comedia.it> (raw)

[-- Attachment #1: Type: text/plain, Size: 449 bytes --]

Neil,
i made some small patches to mdadm 1.7.0
the first is just some makefile cleanup
the second adds a -i (pid) option to monitor mode which causes mdadm to
write its own pid to the specified file, this comes useful to simplify
init scripts that call mdadm --monitor --daemonize.

Regards,
L.



-- 
Luca Berra -- bluca@comedia.it
        Communication Media & Services S.r.l.
 /"\
 \ /     ASCII RIBBON CAMPAIGN
  X        AGAINST HTML MAIL
 / \

[-- Attachment #2: mdadm-1.7.0-makefile.patch --]
[-- Type: text/plain, Size: 2983 bytes --]

--- mdadm-1.7.0/Makefile.makefile	2004-08-11 03:28:50.000000000 +0200
+++ mdadm-1.7.0/Makefile	2004-08-25 09:17:36.993441628 +0200
@@ -31,6 +31,11 @@
 # e.g.  make CXFLAGS=-O to optimise
 TCC = tcc
 UCLIBC_GCC = $(shell for nm in i386-uclibc-linux-gcc i386-uclibc-gcc; do which $$nm > /dev/null && { echo $$nm ; exit; } ; done; echo false No uclibc found )
+DIET_GCC = diet gcc
+
+KLIBC=/home/src/klibc/klibc-0.77
+
+KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32
 
 CC = gcc
 CXFLAGS = -ggdb
@@ -52,11 +57,9 @@
 MAN5DIR = $(MANDIR)/man5
 MAN8DIR = $(MANDIR)/man8
 
-
-KLIBC=/home/src/klibc/klibc-0.77
-
 OBJS =  mdadm.o config.o mdstat.o  ReadMe.o util.o Manage.o Assemble.o Build.o Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o
 SRCS =  mdadm.c config.c mdstat.c  ReadMe.c util.c Manage.c Assemble.c Build.c Create.c Detail.c Examine.c Grow.c Monitor.c dlink.c Kill.c Query.c
+ASSEMBLE_SRCS = mdassemble.c Assemble.c config.c dlink.c util.c
 
 all : mdadm mdadm.man md.man mdadm.conf.man
 
@@ -66,7 +69,7 @@
 	$(CC) $(LDFLAGS) -o mdadm $^
 
 mdadm.static : $(OBJS)
-	$(CC) $(LDFLAGS) --static -o mdadm.static $^
+	$(CC) $(LDFLAGS) -static -o mdadm.static $^
 
 mdadm.tcc : $(SRCS) mdadm.h
 	$(TCC) -o mdadm.tcc $(SRCS)
@@ -78,15 +81,22 @@
 	rm -f $(OBJS) 
 	gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS)
 
-mdassemble : mdassemble.c Assemble.c config.c dlink.c util.c mdadm.h
+mdassemble : $(ASSEMBLE_SRCS) mdadm.h
 	rm -f $(OBJS)
-	diet gcc -o mdassemble mdassemble.c Assemble.c config.c dlink.c util.c
+	$(DIET_GCC) -o mdassemble $(ASSEMBLE_SRCS) 
 
-# This doesn't work
-mdassemble.klibc : mdassemble.c Assemble.c config.c dlink.c util.c mdadm.h
+mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h
+	rm -f $(OBJS)
+	$(CC) $(LDFLAGS) -static -o mdassemble $(ASSEMBLE_SRCS)
+
+mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h
 	rm -f $(OBJS)
-	gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) -o mdassemble mdassemble.c Assemble.c config.c dlink.c util.c
+	$(UCLIBC_GCC) -DUCLIBC -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) 
 
+# This doesn't work
+mdassemble.klibc : $(ASSEMBLE_SRCS) mdadm.h
+	rm -f $(OBJS)
+	$(KLIBC_GCC) $(CFLAGS) -o mdassemble $(ASSEMBLE_SRCS)
 
 mdadm.man : mdadm.8
 	nroff -man mdadm.8 > mdadm.man
@@ -106,7 +116,8 @@
 	$(INSTALL) -D -m 644 mdadm.conf.5 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5
 
 clean : 
-	rm -f mdadm $(OBJS) core *.man mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt
+	rm -f mdadm $(OBJS) core *.man mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt \
+	mdassemble mdassemble.static mdassemble.uclibc mdassemble.klibc
 
 dist : clean
 	./makedist

[-- Attachment #3: mdadm-1.7.0-pidfile.patch --]
[-- Type: text/plain, Size: 3877 bytes --]

--- mdadm-1.7.0/ReadMe.c.pidfile	2004-08-11 04:05:15.000000000 +0200
+++ mdadm-1.7.0/ReadMe.c	2004-08-25 07:59:23.224003584 +0200
@@ -90,7 +90,7 @@
  *     At the time if writing, there is only minimal support.
  */
 
-char short_options[]="-ABCDEFGQhVvbc:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1t";
+char short_options[]="-ABCDEFGQhVvbc:i:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1t";
 struct option long_options[] = {
     {"manage",    0, 0, '@'},
     {"misc",      0, 0, '#'},
@@ -157,6 +157,7 @@
     {"daemonise", 0, 0, 'f'},
     {"daemonize", 0, 0, 'f'},
     {"oneshot",   0, 0, '1'},
+    {"pid",   1, 0, 'i'},
     
     {0, 0, 0, 0}
 };
@@ -418,6 +419,7 @@
 "  --config=     -c   : specify a different config file\n"
 "  --scan        -s   : find mail-address/program in config file\n"
 "  --daemonise   -f   : Fork and continue in child, parent exits\n"
+"  --pid=        -i   : In daemon mode write pid to specified file instead of stdout\n"
 "  --oneshot     -1   : Check for degraded arrays, then exit\n"
 "  --test        -t   : Generate a TestMessage event against each array at startup\n"
 ;
--- mdadm-1.7.0/Monitor.c.pidfile	2004-08-11 03:52:40.000000000 +0200
+++ mdadm-1.7.0/Monitor.c	2004-08-25 08:25:14.554960895 +0200
@@ -47,7 +47,7 @@
 int Monitor(mddev_dev_t devlist,
 	    char *mailaddr, char *alert_cmd,
 	    int period, int daemonise, int scan, int oneshot,
-	    char *config, int test)
+	    char *config, int test, char* pidfile)
 {
 	/*
 	 * Every few seconds, scan every md device looking for changes
@@ -127,7 +127,18 @@
 	if (daemonise) {
 		int pid = fork();
 		if (pid > 0) {
-			printf("%d\n", pid);
+			if (!pidfile)
+				printf("%d\n", pid);
+			else {
+				FILE *pid_file;
+				pid_file=fopen(pidfile, "w");
+				if (!pid_file)
+					perror("cannot create pid file");
+				else {
+					fprintf(pid_file,"%d\n", pid);
+					fclose(pid_file);
+				}
+			}
 			return 0;
 		}
 		if (pid < 0) {
@@ -428,6 +439,8 @@
 		}
 		test = 0;
 	}
+	if (pidfile)
+		unlink(pidfile);
 	return 0;
 }
 
--- mdadm-1.7.0/mdadm.c.pidfile	2004-08-11 03:35:16.000000000 +0200
+++ mdadm-1.7.0/mdadm.c	2004-08-25 07:59:23.226003626 +0200
@@ -233,6 +233,7 @@
 	char *program = NULL;
 	int delay = 0;
 	int daemonise = 0;
+	char *pidfile = NULL;
 	int oneshot = 0;
 
 	int copies;
@@ -677,6 +678,13 @@
 		case O(MONITOR,'f'): /* daemonise */
 			daemonise = 1;
 			continue;
+		case O(MONITOR,'i'): /* pid */
+			if (pidfile)
+				fprintf(stderr, Name ": only specify one pid file. %s ignored.\n",
+					optarg);
+			else
+				pidfile = optarg;
+			continue;
 		case O(MONITOR,'1'): /* oneshot */
 			oneshot = 1;
 			continue;
@@ -963,8 +971,13 @@
 			rv = 1;
 			break;
 		}
+		if (pidfile && !daemonise) {
+			fprintf(stderr, Name ": Cannot write a pid file when not in daemon mode\n");
+			rv = 1;
+			break;
+		}
 		rv= Monitor(devlist, mailaddr, program,
-			    delay?delay:60, daemonise, scan, oneshot, configfile, test);
+			    delay?delay:60, daemonise, scan, oneshot, configfile, test, pidfile);
 		break;
 
 	case GROW:
--- mdadm-1.7.0/mdadm.h.pidfile	2004-08-11 03:28:50.000000000 +0200
+++ mdadm-1.7.0/mdadm.h	2004-08-25 07:59:23.227003647 +0200
@@ -187,7 +187,7 @@
 extern int Monitor(mddev_dev_t devlist,
 		   char *mailaddr, char *alert_cmd,
 		   int period, int daemonise, int scan, int oneshot,
-		   char *config, int test);
+		   char *config, int test, char *pidfile);
 
 extern int Kill(char *dev, int force);
 
--- mdadm-1.7.0/mdadm.8.pidfile	2004-08-11 04:05:28.000000000 +0200
+++ mdadm-1.7.0/mdadm.8	2004-08-25 08:11:28.142831013 +0200
@@ -540,6 +540,13 @@
 is found in the config file.
 
 .TP
+.BR -i ", " --pid
+When
+.B mdadm
+is running in daemon mode, write the pid of the daemon process to
+the specified file, instead of printing it on standard output.
+
+.TP
 .BR -1 ", " --oneshot
 Check arrays only once.  This will generate
 .B NewArray

             reply	other threads:[~2004-08-25  7:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-25  7:22 Luca Berra [this message]
     [not found] ` <16686.39118.516906.365004@cse.unsw.edu.au>
2004-08-30 13:09   ` small patches to mdadm Luca Berra
2004-09-06  4:47     ` Neil Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040825072235.GB5851@percy.comedia.it \
    --to=bluca@comedia.it \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@cse.unsw.edu.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.