amq.c (131706) | amq.c (174313) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1997-2004 Erez Zadok | 2 * Copyright (c) 1997-2006 Erez Zadok |
3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * | 3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * |
39 * %W% (Berkeley) %G% | |
40 * | 39 * |
41 * $Id: amq.c,v 1.7.2.9 2004/01/06 03:15:16 ezk Exp $ | 40 * File: am-utils/amq/amq.c |
42 * 43 */ 44 | 41 * 42 */ 43 |
45#include <sys/cdefs.h> 46__FBSDID("$FreeBSD: head/contrib/amd/amq/amq.c 131706 2004-07-06 13:16:49Z mbr $"); 47 | |
48/* 49 * Automounter query tool 50 */ 51 | 44/* 45 * Automounter query tool 46 */ 47 |
52#ifndef lint 53char copyright[] = "\ 54@(#)Copyright (c) 1997-2004 Erez Zadok\n\ 55@(#)Copyright (c) 1990 Jan-Simon Pendry\n\ 56@(#)Copyright (c) 1990 Imperial College of Science, Technology & Medicine\n\ 57@(#)Copyright (c) 1990 The Regents of the University of California.\n\ 58@(#)All rights reserved.\n"; 59#if __GNUC__ < 2 60static char rcsid[] = "$Id: amq.c,v 1.7.2.9 2004/01/06 03:15:16 ezk Exp $"; 61static char sccsid[] = "%W% (Berkeley) %G%"; 62#endif /* __GNUC__ < 2 */ 63#endif /* not lint */ 64 | |
65#ifdef HAVE_CONFIG_H 66# include <config.h> 67#endif /* HAVE_CONFIG_H */ 68#include <am_defs.h> 69#include <amq.h> 70 71/* locals */ 72static int flush_flag; --- 40 unchanged lines hidden (view full) --- 113 *dwid = dw; 114 if (tw > *twid) 115 *twid = tw; 116 } 117 break; 118 119 case Full: 120 { | 48#ifdef HAVE_CONFIG_H 49# include <config.h> 50#endif /* HAVE_CONFIG_H */ 51#include <am_defs.h> 52#include <amq.h> 53 54/* locals */ 55static int flush_flag; --- 40 unchanged lines hidden (view full) --- 96 *dwid = dw; 97 if (tw > *twid) 98 *twid = tw; 99 } 100 break; 101 102 case Full: 103 { |
121 struct tm *tp = localtime((time_t *) &mt->mt_mounttime); 122 printf("%-*.*s %-*.*s %-*.*s %s\n\t%-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n", | 104 struct tm *tp = localtime((time_t *) ((voidp) &mt->mt_mounttime)); 105 printf("%-*.*s %-*.*s %-*.*s %s\n\t%-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%04d %02d:%02d:%02d\n", |
123 *dwid, *dwid, 124 *mt->mt_directory ? mt->mt_directory : "/", /* XXX */ 125 *twid, *twid, 126 mt->mt_type, 127 *mwid, *mwid, 128 mt->mt_mountinfo, 129 mt->mt_mountpoint, 130 131 mt->mt_mountuid, 132 mt->mt_getattr, 133 mt->mt_lookup, 134 mt->mt_readdir, 135 mt->mt_readlink, 136 mt->mt_statfs, 137 | 106 *dwid, *dwid, 107 *mt->mt_directory ? mt->mt_directory : "/", /* XXX */ 108 *twid, *twid, 109 mt->mt_type, 110 *mwid, *mwid, 111 mt->mt_mountinfo, 112 mt->mt_mountpoint, 113 114 mt->mt_mountuid, 115 mt->mt_getattr, 116 mt->mt_lookup, 117 mt->mt_readdir, 118 mt->mt_readlink, 119 mt->mt_statfs, 120 |
138 tp->tm_year > 99 ? tp->tm_year - 100 : tp->tm_year, | |
139 tp->tm_mon + 1, tp->tm_mday, | 121 tp->tm_mon + 1, tp->tm_mday, |
122 tp->tm_year < 1900 ? tp->tm_year + 1900 : tp->tm_year, |
|
140 tp->tm_hour, tp->tm_min, tp->tm_sec); 141 } 142 break; 143 144 case Stats: 145 { | 123 tp->tm_hour, tp->tm_min, tp->tm_sec); 124 } 125 break; 126 127 case Stats: 128 { |
146 struct tm *tp = localtime((time_t *) &mt->mt_mounttime); 147 printf("%-*.*s %-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%02d\n", | 129 struct tm *tp = localtime((time_t *) ((voidp) &mt->mt_mounttime)); 130 printf("%-*.*s %-5d %-7d %-6d %-7d %-7d %-6d %02d/%02d/%02d %02d:%02d:%04d\n", |
148 *dwid, *dwid, 149 *mt->mt_directory ? mt->mt_directory : "/", /* XXX */ 150 151 mt->mt_mountuid, 152 mt->mt_getattr, 153 mt->mt_lookup, 154 mt->mt_readdir, 155 mt->mt_readlink, 156 mt->mt_statfs, 157 | 131 *dwid, *dwid, 132 *mt->mt_directory ? mt->mt_directory : "/", /* XXX */ 133 134 mt->mt_mountuid, 135 mt->mt_getattr, 136 mt->mt_lookup, 137 mt->mt_readdir, 138 mt->mt_readlink, 139 mt->mt_statfs, 140 |
158 tp->tm_year > 99 ? tp->tm_year - 100 : tp->tm_year, | |
159 tp->tm_mon + 1, tp->tm_mday, | 141 tp->tm_mon + 1, tp->tm_mday, |
142 tp->tm_year < 1900 ? tp->tm_year + 1900 : tp->tm_year, |
|
160 tp->tm_hour, tp->tm_min, tp->tm_sec); 161 } 162 break; 163 164 case Short: 165 { 166 printf("%-*.*s %-*.*s %-*.*s %s\n", 167 *dwid, *dwid, --- 11 unchanged lines hidden (view full) --- 179 } 180} 181 182 183/* 184 * Display a pwd data 185 */ 186static void | 143 tp->tm_hour, tp->tm_min, tp->tm_sec); 144 } 145 break; 146 147 case Short: 148 { 149 printf("%-*.*s %-*.*s %-*.*s %s\n", 150 *dwid, *dwid, --- 11 unchanged lines hidden (view full) --- 162 } 163} 164 165 166/* 167 * Display a pwd data 168 */ 169static void |
187show_pwd(amq_mount_tree *mt, char *path, int *flag) | 170show_pwd(amq_mount_tree *mt, char *path, size_t l, int *flag) |
188{ 189 int len; 190 191 while (mt) { 192 len = strlen(mt->mt_mountpoint); 193 if (NSTREQ(path, mt->mt_mountpoint, len) && 194 !STREQ(mt->mt_directory, mt->mt_mountpoint)) { | 171{ 172 int len; 173 174 while (mt) { 175 len = strlen(mt->mt_mountpoint); 176 if (NSTREQ(path, mt->mt_mountpoint, len) && 177 !STREQ(mt->mt_directory, mt->mt_mountpoint)) { |
195 char buf[MAXPATHLEN+1]; 196 strcpy(buf, mt->mt_directory); 197 strcat(buf, &path[len]); 198 strcpy(path, buf); | 178 char buf[MAXPATHLEN+1]; /* must be same size as 'path' */ 179 xstrlcpy(buf, mt->mt_directory, sizeof(buf)); 180 xstrlcat(buf, &path[len], sizeof(buf)); 181 xstrlcpy(path, buf, l); |
199 *flag = 1; 200 } | 182 *flag = 1; 183 } |
201 show_pwd(mt->mt_next, path, flag); | 184 show_pwd(mt->mt_next, path, l, flag); |
202 mt = mt->mt_child; 203 } 204} 205 206 207/* 208 * Display a mount tree. 209 */ --- 6 unchanged lines hidden (view full) --- 216 mt = mt->mt_child; 217 } 218} 219 220 221static void 222show_mi(amq_mount_info_list *ml, enum show_opt e, int *mwid, int *dwid, int *twid) 223{ | 185 mt = mt->mt_child; 186 } 187} 188 189 190/* 191 * Display a mount tree. 192 */ --- 6 unchanged lines hidden (view full) --- 199 mt = mt->mt_child; 200 } 201} 202 203 204static void 205show_mi(amq_mount_info_list *ml, enum show_opt e, int *mwid, int *dwid, int *twid) 206{ |
224 int i; | 207 u_int i; |
225 226 switch (e) { 227 228 case Calc: 229 { 230 for (i = 0; i < ml->amq_mount_info_list_len; i++) { 231 amq_mount_info *mi = &ml->amq_mount_info_list_val[i]; 232 int mw = strlen(mi->mi_mountinfo); --- 16 unchanged lines hidden (view full) --- 249 printf("%-*.*s %-*.*s %-*.*s %-3d %s is %s", 250 *mwid, *mwid, mi->mi_mountinfo, 251 *dwid, *dwid, mi->mi_mountpt, 252 *twid, *twid, mi->mi_type, 253 mi->mi_refc, mi->mi_fserver, 254 mi->mi_up > 0 ? "up" : 255 mi->mi_up < 0 ? "starting" : "down"); 256 if (mi->mi_error > 0) { | 208 209 switch (e) { 210 211 case Calc: 212 { 213 for (i = 0; i < ml->amq_mount_info_list_len; i++) { 214 amq_mount_info *mi = &ml->amq_mount_info_list_val[i]; 215 int mw = strlen(mi->mi_mountinfo); --- 16 unchanged lines hidden (view full) --- 232 printf("%-*.*s %-*.*s %-*.*s %-3d %s is %s", 233 *mwid, *mwid, mi->mi_mountinfo, 234 *dwid, *dwid, mi->mi_mountpt, 235 *twid, *twid, mi->mi_type, 236 mi->mi_refc, mi->mi_fserver, 237 mi->mi_up > 0 ? "up" : 238 mi->mi_up < 0 ? "starting" : "down"); 239 if (mi->mi_error > 0) { |
257 if (mi->mi_error < sys_nerr) 258#ifdef HAVE_STRERROR 259 printf(" (%s)", strerror(mi->mi_error)); 260#else /* not HAVE_STRERROR */ 261 printf(" (%s)", sys_errlist[mi->mi_error]); 262#endif /* not HAVE_STRERROR */ 263 else 264 printf(" (Error %d)", mi->mi_error); | 240 printf(" (%s)", strerror(mi->mi_error)); |
265 } else if (mi->mi_error < 0) { 266 fputs(" (in progress)", stdout); 267 } 268 fputc('\n', stdout); 269 } 270 } 271 break; 272 --- 180 unchanged lines hidden (view full) --- 453 /* 454 * Get address of server 455 */ 456 if ((hp = gethostbyname(server)) == 0 && !STREQ(server, localhost)) { 457 fprintf(stderr, "%s: Can't get address of %s\n", 458 am_get_progname(), server); 459 exit(1); 460 } | 241 } else if (mi->mi_error < 0) { 242 fputs(" (in progress)", stdout); 243 } 244 fputc('\n', stdout); 245 } 246 } 247 break; 248 --- 180 unchanged lines hidden (view full) --- 429 /* 430 * Get address of server 431 */ 432 if ((hp = gethostbyname(server)) == 0 && !STREQ(server, localhost)) { 433 fprintf(stderr, "%s: Can't get address of %s\n", 434 am_get_progname(), server); 435 exit(1); 436 } |
461 memset(&server_addr, 0, sizeof server_addr); | 437 memset(&server_addr, 0, sizeof(server_addr)); 438 /* as per POSIX, sin_len need not be set (used internally by kernel) */ |
462 server_addr.sin_family = AF_INET; 463 if (hp) { 464 memmove((voidp) &server_addr.sin_addr, (voidp) hp->h_addr, 465 sizeof(server_addr.sin_addr)); 466 } else { 467 /* fake "localhost" */ 468 server_addr.sin_addr.s_addr = htonl(0x7f000001); 469 } --- 89 unchanged lines hidden (view full) --- 559 /* 560 * getpwd info 561 */ 562 if (getpwd_flag) { 563 char path[MAXPATHLEN+1]; 564 char *wd = getcwd(path, MAXPATHLEN+1); 565 amq_mount_tree_list *mlp = amqproc_export_1((voidp) 0, clnt); 566 amq_mount_tree_p mt; | 439 server_addr.sin_family = AF_INET; 440 if (hp) { 441 memmove((voidp) &server_addr.sin_addr, (voidp) hp->h_addr, 442 sizeof(server_addr.sin_addr)); 443 } else { 444 /* fake "localhost" */ 445 server_addr.sin_addr.s_addr = htonl(0x7f000001); 446 } --- 89 unchanged lines hidden (view full) --- 536 /* 537 * getpwd info 538 */ 539 if (getpwd_flag) { 540 char path[MAXPATHLEN+1]; 541 char *wd = getcwd(path, MAXPATHLEN+1); 542 amq_mount_tree_list *mlp = amqproc_export_1((voidp) 0, clnt); 543 amq_mount_tree_p mt; |
567 int i, flag; | 544 u_int i; 545 int flag; |
568 569 if (!wd) { 570 perror("getcwd"); 571 exit(1); 572 } 573 for (i = 0; mlp && i < mlp->amq_mount_tree_list_len; i++) { 574 mt = mlp->amq_mount_tree_list_val[i]; 575 while (1) { 576 flag = 0; | 546 547 if (!wd) { 548 perror("getcwd"); 549 exit(1); 550 } 551 for (i = 0; mlp && i < mlp->amq_mount_tree_list_len; i++) { 552 mt = mlp->amq_mount_tree_list_val[i]; 553 while (1) { 554 flag = 0; |
577 show_pwd(mt, path, &flag); | 555 show_pwd(mt, path, sizeof(path), &flag); |
578 if (!flag) { 579 printf("%s\n", path); 580 break; 581 } 582 } 583 } 584 exit(0); 585 } --- 97 unchanged lines hidden (view full) --- 683 errs = 1; 684 } 685 686 } else if (!nodefault) { 687 amq_mount_tree_list *mlp = amqproc_export_1((voidp) 0, clnt); 688 if (mlp) { 689 enum show_opt e = Calc; 690 int mwid = 0, dwid = 0, pwid = 0; | 556 if (!flag) { 557 printf("%s\n", path); 558 break; 559 } 560 } 561 } 562 exit(0); 563 } --- 97 unchanged lines hidden (view full) --- 661 errs = 1; 662 } 663 664 } else if (!nodefault) { 665 amq_mount_tree_list *mlp = amqproc_export_1((voidp) 0, clnt); 666 if (mlp) { 667 enum show_opt e = Calc; 668 int mwid = 0, dwid = 0, pwid = 0; |
669 |
|
691 while (e != ShowDone) { | 670 while (e != ShowDone) { |
692 int i; | 671 u_int i; |
693 for (i = 0; i < mlp->amq_mount_tree_list_len; i++) { 694 show_mt(mlp->amq_mount_tree_list_val[i], 695 e, &mwid, &dwid, &pwid); 696 } 697 mwid++; 698 dwid++, pwid++; 699 if (e == Calc) 700 e = Short; --- 13 unchanged lines hidden --- | 672 for (i = 0; i < mlp->amq_mount_tree_list_len; i++) { 673 show_mt(mlp->amq_mount_tree_list_val[i], 674 e, &mwid, &dwid, &pwid); 675 } 676 mwid++; 677 dwid++, pwid++; 678 if (e == Calc) 679 e = Short; --- 13 unchanged lines hidden --- |