From owner-p4-projects@FreeBSD.ORG Tue Oct 23 00:18:25 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 47B1816A468; Tue, 23 Oct 2007 00:18:25 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CD55A16A41A for ; Tue, 23 Oct 2007 00:18:24 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id AC76F13C481 for ; Tue, 23 Oct 2007 00:18:24 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l9N0IOED020655 for ; Tue, 23 Oct 2007 00:18:24 GMT (envelope-from zec@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l9N0IO8l020652 for perforce@freebsd.org; Tue, 23 Oct 2007 00:18:24 GMT (envelope-from zec@FreeBSD.org) Date: Tue, 23 Oct 2007 00:18:24 GMT Message-Id: <200710230018.l9N0IO8l020652@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@FreeBSD.org using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 127942 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2007 00:18:25 -0000 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: