Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Oct 2007 00:18:24 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 127942 for review
Message-ID:  <200710230018.l9N0IO8l020652@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=127942

Change 127942 by zec@zec_tpx32 on 2007/10/23 00:17:35

	Update the vimage utility to support the new naming scheme.
	
	While here, do a few stilistic / cosmetic cleanups.

Affected files ...

.. //depot/projects/vimage/src/usr.sbin/vimage/vimage.c#7 edit

Differences ...

==== //depot/projects/vimage/src/usr.sbin/vimage/vimage.c#7 (text+ko) ====

@@ -122,12 +122,12 @@
 
 	bzero(&vi_req, sizeof(vi_req));
 	if (argc == 1) {
-		vi_req.vi_name[0] = 0;
+		strcpy(vi_req.vi_name, ".");
 		cmd = VI_GET;
 	}
 
 	if (argc == 2 && strcmp(argv[1], "-l") == 0) {
-		vi_req.vi_name[0] = 0;
+		strcpy(vi_req.vi_name, ".");
 		cmd = VI_GETNEXT; /* here this means walk! */
 	}
 
@@ -141,7 +141,7 @@
 			cmd = VI_DESTROY;
 	}
 
-	if (argc>=3) {
+	if (argc >= 3) {
 		strcpy(vi_req.vi_name, argv[2]);
 		if (strcmp(argv[1], "-c") == 0)
 			cmd = VI_CREATE;
@@ -157,13 +157,18 @@
 	case VI_GET:
         	if (ioctl(s, SIOCGPVIMAGE, (caddr_t)&vi_req) < 0)
 			goto abort;
-		if (argc==1)
+		if (argc == 1)
 			printf("%s\n", vi_req.vi_name);
 		else
 			vi_print(&vi_req);
 		exit(0);
 
 	case VI_GETNEXT:
+		vi_req.req_action = VI_GET;
+        	if (ioctl(s, SIOCGPVIMAGE, (caddr_t)&vi_req) < 0)
+			goto abort;
+		vi_print(&vi_req);
+		vi_req.req_action = VI_GETNEXT;
         	while (ioctl(s, SIOCGPVIMAGE, (caddr_t)&vi_req) == 0)
 			vi_print(&vi_req);
 		exit(0);
@@ -190,51 +195,51 @@
 			}
 			if (strcmp(argv[i], "cpumin") == 0) {
 				vi_req.req_action |= VI_SET_CPU_MIN;
-				vi_req.vi_cpu_min = strtod(argv[i+1], NULL)
-							* 10000;
+				vi_req.vi_cpu_min =
+				    strtod(argv[i+1], NULL) * 10000;
 				if (vi_req.vi_cpu_min > 900000) {
 					fprintf(stderr, "error: cpumin must be between 0 and 90\n");
 					exit(1);
 				}
 			}
-			if (strcmp(argv[i], "cpumax")==0) {
+			if (strcmp(argv[i], "cpumax") == 0) {
 				vi_req.req_action |= VI_SET_CPU_MAX;
-				vi_req.vi_cpu_max = strtod(argv[i+1], NULL)
-							* 10000;
-				if (vi_req.vi_cpu_max<10000 ||
-				    vi_req.vi_cpu_max>1000000) {
+				vi_req.vi_cpu_max =
+				    strtod(argv[i+1], NULL) * 10000;
+				if (vi_req.vi_cpu_max < 10000 ||
+				    vi_req.vi_cpu_max > 1000000) {
 					fprintf(stderr, "error: cpumax must be between 1 and 100\n");
 					exit(1);
 				}
 			}
-			if (strcmp(argv[i], "cpuweight")==0) {
+			if (strcmp(argv[i], "cpuweight") == 0) {
 				vi_req.req_action |= VI_SET_CPU_WEIGHT;
 				vi_req.vi_cpu_weight = strtod(argv[i+1], NULL);
-				if (vi_req.vi_cpu_weight<1 ||
-				    vi_req.vi_cpu_weight>10) {
+				if (vi_req.vi_cpu_weight < 1 ||
+				    vi_req.vi_cpu_weight > 10) {
 					fprintf(stderr, "error: cpuweight must be between 1 and 10\n");
 					exit(1);
 				}
 			}
-			if (strcmp(argv[i], "intr")==0) {
+			if (strcmp(argv[i], "intr") == 0) {
 				vi_req.req_action |= VI_SET_INTR_LIMIT;
-				vi_req.vi_intr_limit = strtod(argv[i+1], NULL)
-							* 10000;
-				if (vi_req.vi_intr_limit<10000 ||
-				    vi_req.vi_intr_limit>1000000) {
+				vi_req.vi_intr_limit =
+				    strtod(argv[i+1], NULL) * 10000;
+				if (vi_req.vi_intr_limit < 10000 ||
+				    vi_req.vi_intr_limit > 1000000) {
 					fprintf(stderr, "error: intr limit must be between 1 and 100\n");
 					exit(1);
 				}
 			}
-			if (strcmp(argv[i], "child")==0) {
+			if (strcmp(argv[i], "child") == 0) {
 				vi_req.req_action |= VI_SET_CHILD_LIMIT;
 				vi_req.vi_child_limit = atoi(argv[i+1]);
 			}
-			if (strcmp(argv[i], "proc")==0) {
+			if (strcmp(argv[i], "proc") == 0) {
 				vi_req.req_action |= VI_SET_PROC_LIMIT;
 				vi_req.vi_proc_limit = atoi(argv[i+1]);
 			}
-			if (strcmp(argv[i], "chroot")==0) {
+			if (strcmp(argv[i], "chroot") == 0) {
 				vi_req.req_action |= VI_SET_CHROOT;
 				strncpy(vi_req.vi_chroot, argv[i+1],
 					 sizeof(vi_req.vi_chroot));
@@ -248,21 +253,27 @@
 		strcpy(vi_req.vi_name, argv[1]);
 		if (ioctl(s, SIOCSPVIMAGE, (caddr_t)&vi_req) < 0)
 			goto abort;
+
 		vi_req.req_action = VI_GET;
-		if (ioctl(s, SIOCGPVIMAGE, (caddr_t)&vi_req) < 0)
+		strcpy(vi_req.vi_name, ".");
+		if (ioctl(s, SIOCGPVIMAGE, (caddr_t)&vi_req) < 0) {
+			printf("XXX this should have not happened!\n");
 			goto abort;
+		}
+
 		if (strlen(vi_req.vi_chroot) && (chdir(vi_req.vi_chroot) ||
 		    chroot(vi_req.vi_chroot)))
 			goto abort;
 		close(s);
-		if (argc==2) {
+
+		if (argc == 2) {
 		printf("Switched to vimage %s\n", argv[1]);
-			if ((shell=getenv("SHELL"))==NULL)
-				execlp("/bin/sh",argv[0],NULL);
+			if ((shell=getenv("SHELL")) == NULL)
+				execlp("/bin/sh", argv[0], NULL);
 			else
-				execlp(shell,argv[0],NULL);
+				execlp(shell, argv[0], NULL);
 		} else 
-			execvp(argv[2],&argv[2]);
+			execvp(argv[2], &argv[2]);
 		break;
 
 	case VI_DESTROY:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710230018.l9N0IO8l020652>