summaryrefslogtreecommitdiff
path: root/extras/multipath/main.c
diff options
context:
space:
mode:
authorchristophe.varoqui@free.fr <christophe.varoqui@free.fr>2003-12-07 08:48:23 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:06 -0700
commitd877515791ae4d625d396cdb3a35903cdbf6fde6 (patch)
tree691c3387abe828cf82bcbaace68f0a637bf807b6 /extras/multipath/main.c
parent2bf80b67d1a64f1219bd366cee355e897596b2cf (diff)
[PATCH] more extras/multipath updates
* Adds a /var/run/multipath.run handling to avoid simultaneous runs. * Remove a commented-out "printf"
Diffstat (limited to 'extras/multipath/main.c')
-rw-r--r--extras/multipath/main.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/extras/multipath/main.c b/extras/multipath/main.c
index f3f92e7eba..9bceb265ba 100644
--- a/extras/multipath/main.c
+++ b/extras/multipath/main.c
@@ -660,9 +660,19 @@ usage(char * progname)
exit(1);
}
+static int
+running(char * run) {
+ struct stat buf;
+
+ if(!stat(run, &buf))
+ return 1;
+ return 0;
+}
+
int
main(int argc, char *argv[])
{
+ char * run = "/var/run/multipath.run";
struct multipath * mp;
struct path * all_paths;
struct scsi_dev * all_scsi_ids;
@@ -705,12 +715,26 @@ main(int argc, char *argv[])
}
+ if (running(run)) {
+ if (conf.verbose) {
+ fprintf(stderr, "Already running.\n");
+ fprintf(stderr, "If you know what you do, please ");
+ fprintf(stderr, "remove %s\n", run);
+ }
+ return 1;
+ }
+
+ if(!open(run, O_CREAT))
+ exit(1);
+
/* dynamic allocations */
mp = malloc(conf.max_devs * sizeof(struct multipath));
all_paths = malloc(conf.max_devs * sizeof(struct path));
all_scsi_ids = malloc(conf.max_devs * sizeof(struct scsi_dev));
- if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL)
+ if (mp == NULL || all_paths == NULL || all_scsi_ids == NULL) {
+ unlink(run);
exit(1);
+ }
if (!conf.with_sysfs) {
get_all_scsi_ids(&conf, all_scsi_ids);
@@ -725,11 +749,12 @@ main(int argc, char *argv[])
fprintf(stdout, "\n");
print_all_mp(all_paths, mp, nmp);
fprintf(stdout, "\n");
- //printf("\n");
}
- if (conf.dry_run)
+ if (conf.dry_run) {
+ unlink(run);
exit(0);
+ }
for (k=0; k<=nmp; k++) {
if (map_present(mp[k].wwid)) {
@@ -738,5 +763,6 @@ main(int argc, char *argv[])
add_map(&conf, all_paths, mp, k, DM_DEVICE_CREATE);
}
}
+ unlink(run);
exit(0);
}