2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 #include <afs/param.h>
15 #include <sys/types.h>
16 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43) && !defined(AFS_DARWIN_ENV)
18 /*#ifdef AFS_AIX_ENV*/
26 #include <afs/afs_args.h>
28 #include <afs/afsutil.h>
30 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
31 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
32 int afs_icl_sizeofLong = 2;
34 int afs_icl_sizeofLong = 1;
38 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
39 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
43 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
44 void set_kernel_sizeof_long(void)
49 retval = sysconf(_SC_KERN_POINTERS);
52 afs_icl_sizeofLong = 2;
56 afs_icl_sizeofLong = 1;
60 #endif /* AFS_SGI62_ENV */
61 #endif /* AFS_SGI61_ENV */
63 #define BUFFER_MULTIPLIER 1024
65 /* make it big enough to snapshot everything at once, since
66 * decoding takes so long.
68 #define IBSIZE 100000 /* default size */
71 struct logInfo *nextp;
75 char dumpFileName[256] = "";
76 RegisterIclDumpFileName(name)
79 (void) sprintf(dumpFileName, "icl.%.250s", name);
82 /* define globals to use for bulk info */
83 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *)0;
84 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *)0;
86 struct afs_icl_set *icl_allSets = 0;
90 /* given a type and an address, get the size of the thing
93 static icl_GetSize(type, addr)
101 ICL_SIZEHACK(type, addr);
105 /* Check types in printf string "bufferp", making sure that each
106 * is compatible with the corresponding parameter type described
107 * by typesp. Also watch for prematurely running out of parameters
108 * before the string is gone.
111 static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer)
123 for(tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
126 /* hit end of string. We win as long as we aren't
129 if (inPercent) return 0;
134 inPercent = 1 - inPercent;
138 if (tc >= '0' && tc <= '9') {
139 /* skip digits in % string */
144 /* 'l' is a type modifier. */
148 /* otherwise, we've finally gotten to the type-describing
149 * character. Make sure there's a type descriptor, and then
150 * check the type descriptor.
154 return 0; /* no more type descriptors left */
156 if (typesp[tix] != 1) /* not a string descriptor */
159 *outMsgBuffer = (char)1;
161 if (tc == 'u' || tc == 'x' || tc == 'd'
163 if (typesp[tix] != 0)
164 return 0; /* not an integer descriptor */
168 *outMsgBuffer = (char)2;
171 *outMsgBuffer = (char)3;
174 *outMsgBuffer = (char)4;
178 *outMsgBuffer = (char)5;
182 /* otherwise we're fine, so eat this descriptor */
188 #else /* AFS_SGI61_ENV */
189 static CheckTypes(bufferp, typesp, typeCount)
200 for(tc = *bufferp;; tc = *(++bufferp)) {
202 /* hit end of string. We win as long as we aren't
205 if (inPercent) return 0;
209 inPercent = 1 - inPercent;
213 if (tc >= '0' && tc <= '9') continue; /* skip digits in % string */
214 /* otherwise, we've finally gotten to the type-describing
215 * character. Make sure there's a type descriptor, and then
216 * check the type descriptor.
220 return 0; /* no more type descriptors left */
221 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
223 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
224 && (typesp[tix] != 0))
225 return 0; /* not an integer descriptor */
226 /* otherwise we're fine, so eat this descriptor */
232 #endif /* AFS_SGI61_ENV */
234 /* display a single record.
235 * alp points at the first word in the array to be interpreted
236 * rsize gives the # of words in the array
238 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
239 #define uint64_t long long
241 static DisplayRecord(outFilep, alp, rsize)
243 register afs_int32 *alp;
246 char msgBuffer[1024];
248 char outMsgBuffer[1024];
250 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
251 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
252 #else /* AFS_SGI61_ENV */
253 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
254 #endif /* AFS_SGI61_ENV */
255 int printfTypes[ICL_MAXEXPANSION * 4];
261 int pix; /* index in alp */
262 int pfpix; /* index in printfParms */
263 int pftix; /* index in printfTypes */
265 int printed; /* did we print the string yet? */
268 /* decode parameters */
269 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
275 for(i=0; i<4*ICL_MAXEXPANSION; i++)
277 /* decode each parameter, getting addrs for afs_hyper_t and strings */
278 for(i=0; !done && i<4; i++) {
279 type = (temp >> (18 - i*6)) & 0x3f;
285 case ICL_TYPE_POINTER:
286 printfTypes[pftix++] = 0;
288 printfParms[pfpix] = alp[pix];
289 printfParms[pfpix] &= 0xffffffff;
290 if (afs_64bit_kernel) {
291 printfParms[pfpix] <<= 32;
292 printfParms[pfpix] |= alp[pix+1];
294 #else /* AFS_SGI61_ENV */
296 printfParms[pfpix] = alp[pix+1];
297 printfParms[pfpix] |= (alp[pix] <<= 32);
298 #else /* AFS_ALPHA_ENV */
299 printfParms[pfpix] = alp[pix];
300 #endif /* AFS_ALPHA_ENV */
301 #endif /* AFS_SGI61_ENV */
305 printfTypes[pftix++] = 0;
306 printfParms[pfpix++] = alp[pix];
309 printfTypes[pftix++] = 0;
310 printfParms[pfpix++] = alp[pix];
311 printfTypes[pftix++] = 0;
312 printfParms[pfpix++] = alp[pix+1];
315 printfTypes[pftix++] = 0;
316 printfParms[pfpix++] = alp[pix];
317 printfTypes[pftix++] = 0;
318 printfParms[pfpix++] = alp[pix+1];
319 printfTypes[pftix++] = 0;
320 printfParms[pfpix++] = alp[pix+2];
321 printfTypes[pftix++] = 0;
322 printfParms[pfpix++] = alp[pix+3];
324 case ICL_TYPE_STRING:
325 printfTypes[pftix++] = 1;
327 printfStrings[pfpix++] = (char*) &alp[pix];
328 #else /* AFS_SGI64_ENV */
330 printfStrings[pfpix++] = (char *) &alp[pix];
331 #else /* AFS_SGI61_ENV */
332 printfParms[pfpix++] = (long) &alp[pix];
333 #endif /* AFS_SGI61_ENV */
334 #endif /* AFS_SGI64_ENV */
336 case ICL_TYPE_UNIXDATE:
337 printfParms[pfpix++] = (long) ctime((time_t *)&alp[pix]);
340 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
347 pix += icl_GetSize(type, (char *) &alp[pix]);
350 /* next, try to decode the opcode into a printf string */
351 dce1_error_inq_text(alp[1], msgBuffer, &status);
353 /* if we got a string back, and it is compatible with the
354 * parms we've got, then print it.
359 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
360 /* we have a string to use, but it ends "(dfs / zcm)",
361 * so we remove the extra gunk.
363 j = strlen(outMsgBuffer);
365 outMsgBuffer[j-11] = 0;
369 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000,
370 alp[3] % 1000000, alp[2]);
371 for (i=0; i<j; i++) {
372 if ((int)outMsgBuffer[i] > 5)
373 fputc(outMsgBuffer[i], outFilep);
375 switch (outMsgBuffer[i]) {
379 fprintf(outFilep, "%s", printfStrings[pfpix++]);
381 case 2: /* signed integer */
382 fprintf(outFilep, "%lld", printfParms[pfpix++]);
384 case 3: /* unsigned integer */
385 fprintf(outFilep, "%llu", printfParms[pfpix++]);
387 case 4: /* octal integer */
388 fprintf(outFilep, "%llo", printfParms[pfpix++]);
390 case 5: /* hex integer */
391 fprintf(outFilep, "%llx", printfParms[pfpix++]);
395 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
396 outMsgBuffer[i], pfpix);
397 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
403 fprintf(outFilep, "\n");
406 #else /* AFS_SGI61_ENV */
407 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
408 /* we have a string to use, but it ends "(dfs / zcm)",
409 * so we remove the extra gunk.
411 j = strlen(msgBuffer);
412 if (j > 12) msgBuffer[j-11] = 0;
413 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000,
414 alp[3] % 1000000, alp[2]);
415 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
416 printfParms[2], printfParms[3], printfParms[4],
417 printfParms[5], printfParms[6], printfParms[7],
418 printfParms[8], printfParms[9], printfParms[10],
419 printfParms[11], printfParms[12], printfParms[13],
420 printfParms[14], printfParms[15]);
421 fprintf(outFilep, "\n");
424 #endif /* AFS_SGI61_ENV */
426 fprintf(outFilep, "Type mismatch, using raw print.\n");
427 fprintf(outFilep, "%s", msgBuffer);
431 if (alp[1] == ICL_INFO_TIMESTAMP) {
432 fprintf(outFilep, "time %d.%06d, pid %u: %s\n",
433 alp[3]/1000000, alp[3] % 1000000, alp[2],
434 ctime((time_t *)&alp[4]));
436 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n",
437 alp[1], alp[3]/1000000, alp[3] % 1000000, alp[2]);
438 /* now decode each parameter and print it */
441 for(i=0; !done && i<4; i++) {
442 type = (temp >> (18 - i*6)) & 0x3f;
448 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
452 tempParam = alp[pix];
454 tempParam |= alp[pix+1];
455 fprintf(outFilep, "p%d:%lld ", i, tempParam);
456 #else /* AFS_SGI61_ENV */
457 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
458 #endif /* AFS_SGI61_ENV */
460 case ICL_TYPE_POINTER:
462 tempParam = alp[pix];
464 tempParam |= alp[pix+1];
465 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
466 #else /* AFS_SGI61_ENV */
467 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
468 #endif /* AFS_SGI61_ENV */
471 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix], alp[pix+1]);
474 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
475 alp[pix+1], alp[pix+2], alp[pix+3]);
477 case ICL_TYPE_STRING:
478 fprintf(outFilep, "p%d:%s ", i, (char *) &alp[pix]);
480 case ICL_TYPE_UNIXDATE:
481 fprintf(outFilep, "p%d:%s ", i, ctime((time_t *)&alp[pix]));
484 printf("DisplayRecord: Bad type %d in raw print switch.\n",
492 pix += icl_GetSize(type, (char *) &alp[pix]);
495 fprintf(outFilep, "\n"); /* done with line */
505 #include <nl_types.h>
507 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
509 static nl_catd catopen1();
511 static nl_catd _do1_open();
512 static nl_catd cat_already_open();
513 static int make_sets();
514 static FILE *open1catfile();
515 static void add_open_cat();
516 static void cat_hard_close();
517 extern char *strchr();
519 static int catpid[NL_MAXOPEN];
520 static CATD *catsopen[NL_MAXOPEN];
521 #define PATH_FORMAT "/usr/lib/nls/msg/%L/%N:/etc/nls/msg/%L/%N"
522 #define DEFAULT_LANG "C"
523 #define TOO_MANY_HOLES(num_holes, num_non_holes) \
524 (((num_holes) > 100) && ((num_holes) > (num_non_holes)))
529 /*---- n: the number of bytes to be malloc'ed ----*/
533 t = (char *) malloc(n);
535 printf("Failed to get mem\n");
540 nl_catd catopen1 (cat, dummy)
543 /*---- char *cat: the name of the cat to be opened ----*/
544 /*---- int dummy: dummy variable ----*/
548 nl_catd _do_open(); /*---- routine that actually opens
555 if (catd = cat_already_open(cat)) {
556 catd->_count = catd->_count + 1;
560 catd = (CATD *)rmalloc (sizeof(CATD));
563 catd->_name = (char *)rmalloc(strlen(cat) + 1);
564 if ( catd->_name == NULL )
566 strcpy(catd->_name,cat);
568 catd->_magic = CAT_MAGIC;
570 #ifndef AFS_OSF20_ENV
571 catd->_pid = getpid();
574 if (_do1_open(catd) != CATD_ERR)
585 nl_catd _do1_open(catd)
588 /*---- pointer to the partially set up cat descriptor ----*/
591 int make_sets(); /*---- routine to unpack the sets into
592 fast acccess mode ----*/
593 void add_open_cat(); /*---- routine to keep a list of
596 int i; /*---- Misc counter(s) used for loop */
603 catd->_fd = open1catfile( catd->_name );
607 fread((void *)&magic,(size_t)4,(size_t)1,catd->_fd);
608 if (magic != CAT_MAGIC){
609 printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC, CATD_ERR);
616 /* if ((catd->_mem = shmat((int)fileno(catd->_fd), (char *)0, SHM_MAP | SHM_RDONLY))
617 == (char * )ERR ) { */
619 if (1) { /* disable the shmat, share memory segemnt */
621 /*______________________________________________________________________
622 If the file can not be mapped then simulate mapping for the index
623 table so that make_sets cat set things up. (rmalloc an area big
624 enough for the index table and read the whole thing in)
625 ______________________________________________________________________*/
627 /* reset the file pointer to the beginning of catalog */
628 fseek(catd->_fd,(long)0,0);
630 /* malloc the header, if fails return error */
631 catd->_hd = (struct _header *) rmalloc(sizeof(struct _header));
632 if ( catd->_hd == NULL )
635 /* read in the whole header */
636 fread((void *)catd->_hd,(size_t)sizeof(struct _header),(size_t)1,catd->_fd);
638 /* cs is a dummpy to hold a set temperorily. The purpose of */
639 /* this for loop is to fread the whole catalog so that the */
640 /* file pointer will be moved to the end of the catalog. */
641 for (i = 0 ; i < catd->_hd->_n_sets ; i++) {
642 fread((void *)&cs,(size_t)4,(size_t)1,catd->_fd);
643 fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)),1);
646 /* after the for loop, ftell returns the byte offset of the */
647 /* end of the catalog relative to the begining of the file. */
648 /* i.e. i contains the byte offset of the whole catalog. */
649 i = ftell(catd->_fd);
651 /* malloc _mem as a temp pointer to hold the entire catalog. */
652 catd->_mem = (char *)rmalloc(i);
653 if ( catd->_mem == NULL )
656 /* reset the file pointer to the begining. */
657 fseek(catd->_fd,(long)0,0);
659 /* read in the whole catalog into _mem */
660 fread((void *)catd->_mem,(size_t)i,(size_t)1,catd->_fd);
663 * If there aren't many holes in the set numbers,
664 * fully expand the compacted set array from the
665 * catalog. Then in catgets(), we'll be able to use
666 * the set number to index directly into the expanded
669 * If there are a lot of holes, leave the set array
670 * compacted. In catgets(), we'll search through it
671 * for the requested set.
674 num_holes = catd->_hd->_setmax - catd->_hd->_n_sets;
675 if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) {
676 catd->_sets_expanded = TRUE;
677 catd->_n_sets = catd->_hd->_setmax;
680 catd->_sets_expanded = FALSE;
681 catd->_n_sets = catd->_hd->_n_sets - 1;
684 /* malloc one extra set more than the max. set index */
685 catd->_set = (struct _catset *) rmalloc((catd->_n_sets+1)*
686 sizeof (struct _catset));
687 if ( catd->_set == NULL )
690 /* save the max. set number in catd->_setmax */
691 catd->_setmax = catd->_hd->_setmax;
692 /* call make_set to malloc memory for every message */
693 if(make_sets(catd) == -1)
702 /*______________________________________________________________________
703 Normal mapping has occurred, set a few things up and call make_sets
704 ______________________________________________________________________*/
706 catd->_hd =( struct _header * )( catd->_mem );
707 catd->_setmax = catd->_hd->_setmax;
708 catd->_set = (struct _catset *) rmalloc((catd->_hd->_setmax+1)*
709 sizeof (struct _catset));
710 if ( catd->_set == NULL )
712 if(make_sets(catd) == -1)
720 static void add_open_cat(catd)
722 /*---- catd to be added to the list of catalogs ----*/
725 int i = 0; /*---- Misc counter(s) used for loops ----*/
726 while (i < NL_MAXOPEN && catsopen[i]) {
727 if (!strcmp(catd->_name,catsopen[i]->_name)
728 #ifndef AFS_OSF20_ENV
729 && getpid()==catsopen[i]->_pid)
734 return; /*---- The catalog is already here ----*/
738 if (i < NL_MAXOPEN) {
740 catpid[i] = getpid();
749 * FUNCTION: Expands the compacted version of the catalog index table into
750 * the fast access memory version.
752 * EXECUTION ENVIRONMENT:
754 * Make_set executes under a process.
760 static int make_sets(catd)
763 struct _catset *cset;
764 char *base = catd->_mem;
765 int n_sets = catd->_hd->_n_sets;
766 int i; /*---- Misc counter(s) used for loops ----*/
767 int j; /*---- Misc counter(s) used for loops ----*/
768 int msgmax; /*---- The maximum number of _messages in a set ----*/
769 char *cmpct_set_ptr; /*---- pointer into the index table ----*/
770 struct _catset cs; /*---- used to look at the sets in the table -*/
773 cmpct_set_ptr = base + sizeof(struct _header);
775 for (i = 0 ; i < n_sets ; i++) {
776 /* loop through each compacted set */
778 cs = *(struct _catset *)cmpct_set_ptr;
779 /* set the _catset ptr to the base of the current
782 cs._mp = (struct _msgptr *)(cmpct_set_ptr +
783 2 * sizeof(unsigned short));
784 /* set the ms array ptr to the base of
785 compacted array of _msgptr's */
787 cset = (catd->_sets_expanded) ?
788 &catd->_set[cs._setno] : &catd->_set[i];
791 * If there aren't many holes in the message numbers,
792 * fully expand the compacted message array from the
793 * catalog. Then in catgets(), we'll be able to use
794 * the message number to index directly into the
797 * If there are many holes, leave the message array
798 * compacted. In catgets(), we'll search through it
799 * for the requested message.
802 msgmax = cs._mp[cs._n_msgs - 1]._msgno;
803 num_holes = msgmax - cs._n_msgs;
804 if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) {
805 cset->_msgs_expanded = TRUE;
806 cset->_n_msgs = msgmax;
809 cset->_msgs_expanded = FALSE;
810 cset->_n_msgs = cs._n_msgs - 1;
813 cset->_mp = (struct _msgptr *) rmalloc((1 + cset->_n_msgs) *
814 sizeof(struct _msgptr));
815 if (cset->_mp == NULL)
818 cset->_msgtxt = (char **) rmalloc((1 + cset->_n_msgs) *
820 if (cset->_msgtxt == NULL)
823 if (cset->_msgs_expanded) {
824 for (j = 0 ; j < cs._n_msgs ; j++) {
825 cset->_mp[cs._mp[j]._msgno] = cs._mp[j];
829 for (j = 0 ; j < cs._n_msgs ; j++) {
830 cset->_mp[j] = cs._mp[j];
834 cset->_setno = cs._setno;
835 /* Superfluous but should have the correct data. Increment
836 the base of the set pointer. */
838 cmpct_set_ptr += 2 * sizeof(unsigned short) + cs._n_msgs *
839 sizeof(struct _msgptr);
850 * FUNCTION: Opens a catalog file, looking in the language path first (if
851 * there is no slash) and returns a pointer to the file stream.
853 * EXECUTION ENVIRONMENT:
855 * Opencatfile executes under a process.
857 * RETURNS: Returns a pointer to the file stream, and a NULL pointer on
861 static FILE *open1catfile(file)
864 extern char *getenv();
865 char fl[PATH_MAX]; /*---- place to hold full path ----*/
866 char *nlspath; /*---- pointer to the nlspath val ----*/
867 FILE *fp; /*---- file pointer ----*/
868 char cpth[PATH_MAX]; /*---- current value of nlspath ----*/
870 char *fulllang; /* %L language value */
871 char lang[PATH_MAX]; /* %l language value */
872 char *territory; /* %t language value */
873 char *codeset; /* %c language value */
874 char *ptr; /* for decompose of $LANG */
879 char outptr[PATH_MAX];
882 if (strchr(file,'/')) {
883 if ((fp = fopen(file,"r")))
884 { fcntl(fileno(fp),F_SETFD,1);
885 /* set the close-on-exec flag for
891 if (!(nlspath = getenv("NLSPATH")))
892 nlspath = PATH_FORMAT;
893 if (!(fulllang = getenv("LANG")))
894 fulllang = DEFAULT_LANG;
895 if (fulllang == DEFAULT_LANG)
896 nlspath = PATH_FORMAT; /* if fullang is C, use the
897 the default nlspath: */
900 ** LANG is a composite of three fields:
901 ** language_territory.codeset
902 ** and we're going to break it into those
906 strcpy(lang, fulllang);
911 ptr = strchr( lang, '_' );
915 ptr = strchr(territory, '.');
921 ptr = strchr( lang, '.' );
931 while (*np && *np != ':')
934 if (*np) /*---- iff on a colon then advance --*/
942 while (*ptr != '\0') {
943 while ((*ptr != '\0') && (*ptr != '%')
944 && (nchars < PATH_MAX)) {
945 *(optr++) = *(ptr++);
973 lenstr = strlen(str);
975 if (nchars < PATH_MAX) {
983 if (nchars >= PATH_MAX) {
989 strcpy(cpth, outptr);
991 else { /*---- iff leading | trailing |
992 adjacent colons ... --*/
996 if (valid == 1 && (fp = fopen(cpth,"r")))
997 { fcntl(fileno(fp),F_SETFD,1);
998 /* set the close-on-exec flag for
1003 if (fp = fopen(file,"r"))
1004 { fcntl(fileno(fp),F_SETFD,1);
1005 /* set the close-on-exec flag for
1019 * NAME: cat_already_open
1021 * FUNCTION: Checkes to see if a specific cat has already been opened.
1023 * EXECUTION ENVIRONMENT:
1025 * Cat_already_open executes under a process.
1027 * RETURNS: Returns a pointer to the existing CATD if one exists, and
1028 * a NULL pointer if no CATD exists.
1031 static nl_catd cat_already_open(cat)
1033 /*---- name of the catalog to be opened ----*/
1036 int i; /*---- Misc counter(s) used for loops ----*/
1038 for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) {
1039 #ifndef AFS_OSF20_ENV
1040 if (!strcmp(cat,catsopen[i]->_name) && getpid()==catsopen[i]->_pid) {
1042 if (!strcmp(cat,catsopen[i]->_name)) {
1044 return(catsopen[i]);
1051 int catclose1(catd) /*---- the catd to be closed ----*/
1052 nl_catd catd; /*---- the catd to be closed ----*/
1058 if (catd == CATD_ERR)
1060 for (i=0; i< NL_MAXOPEN && catsopen[i]; i++) {
1061 #ifndef AFS_OSF20_ENV
1062 if (catd == catsopen[i] && getpid()==catsopen[i]->_pid)
1064 if (catd == catsopen[i])
1068 if (i == NL_MAXOPEN || catsopen[i] == NULL)
1070 if (catd->_fd == (FILE *)NULL)
1071 /*---- return if this is an extra open or
1072 a bad catalog discriptor ----*/
1074 if (cat_already_open(catd->_name)) {
1075 if (catd->_count == 1) {
1076 cat_hard_close(catd);
1077 return (0); /*--- the last legal clsoe ---*/
1079 else if (catd->_count > 1) {
1080 catd->_count = catd->_count - 1;
1081 return(0); /*--- a legal close ---*/
1084 return (-1); /*--- an extra illegal close ---*/
1091 static void cat_hard_close(catd)
1093 /*---- the catd to be closed ----*/
1096 int i; /*---- Misc counter(s) used for loops ----*/
1097 int j; /*---- Misc counter ----*/
1099 if (catd == CATD_ERR)
1102 /*______________________________________________________________________
1103 remove any entry for the catalog in the catsopen array
1104 ______________________________________________________________________*/
1106 for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) {
1107 if (catd == catsopen[i]) {
1108 for (; i < NL_MAXOPEN-1; i++) {
1109 catsopen[i] = catsopen[i+1];
1110 catpid[i] = catpid[i+1];
1117 /*______________________________________________________________________
1118 close the cat and free up the memory
1119 ______________________________________________________________________*/
1120 if (catd->_mem == FALSE)
1122 for (i = 0 ; i <= catd->_n_sets ; i++) {
1123 if (catd->_set[i]._mp)
1124 free(catd->_set[i]._mp);
1125 /*---- free the _message pointer arrays ----*/
1127 if (catd->_set[i]._msgtxt) {
1128 for (j = 0 ; j <= catd->_set[i]._n_msgs ; j++) {
1129 if (catd->_set[i]._msgtxt[j]) {
1130 /* free(catd->_set[i]._msgtxt[j]);*/
1133 if (catd->_set[i]._msgtxt)
1134 free(catd->_set[i]._msgtxt);
1140 fclose(catd->_fd); /*---- close the ctatlog ----*/
1142 free(catd->_set); /*---- free the sets ----*/
1144 free(catd->_name); /*---- free the name ----*/
1146 free(catd->_hd); /*---- free the header ----*/
1148 free(catd); /*---- free the catd ----*/
1151 static char *_do1_read_msg(nl_catd catd,int setno,int msgno)
1153 /*---- catd: the catd of the catalog to be read from ----*/
1154 /*---- setno: the set number of the message ----*/
1155 /*---- msgno: the msgno of the message ----*/
1158 nl_catd catd1; /*--- catd for different process ----*/
1161 #ifndef AFS_OSF20_ENV
1162 if (getpid() == catd->_pid)
1166 return (_read1_msg (catd, setno, msgno));
1169 * Since our pid is different from the one in
1170 * catd, catd must have come from a catopen()
1171 * in our parent. We need a catd of our own.
1172 * The first time through here, the call to
1173 * catopen() creates a new catd and we try to
1174 * open its message catalog. After that, the
1175 * catopen() just retrieves the catd.
1177 if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR) &&
1178 ((catd1->_fd == NL_FILE_CLOSED &&
1179 _do1_open(catd1) != CATD_ERR) ||
1180 (catd1->_fd != NL_FILE_UNUSED)))
1181 return (_read1_msg(catd1,setno,msgno));
1188 struct _catset *_cat1_get_catset();
1189 static struct _msgptr *_cat1_get_msgptr();
1190 static char *_read1_msg(nl_catd catd,int setno,int msgno)
1193 struct _catset *set; /*--- ptr to set's _catset structure ---*/
1194 struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/
1195 char **msgtxt; /*--- temporary pointer to the message text
1198 set = _cat1_get_catset(catd, setno);
1200 msg = _cat1_get_msgptr(set, msgno);
1202 msgtxt = &set->_msgtxt[msg - set->_mp];
1203 if (1/*!*msgtxt*/) {
1204 *msgtxt = (char *) malloc(msg->_msglen + 1);
1208 fseek(catd->_fd, (long) msg->_offset, 0);
1209 if (fread((void *) *msgtxt,
1210 (size_t) (msg->_msglen + 1),
1211 (size_t) 1, catd->_fd) != 1)
1222 * NAME: compare_sets
1224 * FUNCTION: Compare function used by bsearch() in _cat_get_catset().
1227 * key - pointer to set number we're searching for
1228 * element - pointer to current _catset structure
1230 * RETURNS: Returns -1, 0, or 1, depending on whether the set number
1231 * is less than, equal to, or greater than the set number of
1232 * the _catset structure.
1237 compare_sets(const void *key, const void *element)
1239 int *setno = (int *) key;
1240 struct _catset *set = (struct _catset *) element;
1242 if (*setno < set->_setno)
1244 if (*setno > set->_setno)
1252 * NAME: _cat_get_catset
1254 * FUNCTION: Find a set in the catd->_set array. Assumes that the
1255 * sets in the array are sorted by increasing set number.
1258 * catd - catalog descripter obtained from catopen()
1259 * setno - message catalogue set number
1261 * RETURNS: Returns a pointer to the set on success.
1262 * On any error, returns NULL.
1266 struct _catset *_cat1_get_catset(nl_catd catd, int setno)
1268 struct _catset *set;
1270 if ((catd == (nl_catd) NULL) || (catd == CATD_ERR))
1271 return (struct _catset *) NULL;
1273 if (catd->_sets_expanded) {
1274 if ((setno < 0) || (setno > catd->_n_sets))
1275 return (struct _catset *) NULL;
1277 set = &catd->_set[setno];
1280 * Catch empty elements in the array. They aren't
1284 if (set->_mp == (struct _msgptr *) NULL)
1285 return (struct _catset *) NULL;
1288 set = (struct _catset *) bsearch((void *) &setno,
1289 catd->_set, catd->_n_sets + 1,
1290 sizeof(struct _catset),
1294 * Since the sets are compacted, there aren't any
1295 * empty elements in the array to check for.
1304 * NAME: compare_msgs
1306 * FUNCTION: Compare function used by bsearch() in _cat_get_msgptr().
1309 * key - pointer to message number we're searching for
1310 * element - pointer to current _msgptr structure
1312 * RETURNS: Returns -1, 0, or 1, depending on whether the message
1313 * number is less than, equal to, or greater than the message
1314 * number of the _msgptr structure.
1319 compare_msgs(const void *key, const void *element)
1321 int *msgno = (int *) key;
1322 struct _msgptr *msg = (struct _msgptr *) element;
1324 if (*msgno < msg->_msgno)
1326 if (*msgno > msg->_msgno)
1333 * NAME: _cat1_get_msgptr
1335 * FUNCTION: Find a message in a set's set->_mp array. Assumes that
1336 * the messages in the array are sorted by increasing
1340 * set - ptr to _catset structure
1341 * msgno - message catalogue message number
1343 * RETURNS: Returns a pointer to the message on success.
1344 * On any error, returns NULL.
1347 static struct _msgptr *_cat1_get_msgptr(struct _catset *set, int msgno)
1349 struct _msgptr *msg;
1351 if (set == (struct _catset *) NULL)
1352 return (struct _msgptr *) NULL;
1354 if (set->_mp == (struct _msgptr *) NULL) /* empty set */
1355 return (struct _msgptr *) NULL;
1357 if (set->_msgs_expanded) {
1358 if ((msgno < 0) || (msgno > set->_n_msgs))
1359 return (struct _msgptr *) NULL;
1361 msg = &set->_mp[msgno];
1364 * Catch empty elements in the array. They aren't
1369 return (struct _msgptr *) NULL;
1372 msg = (struct _msgptr *) bsearch((void *) &msgno,
1373 set->_mp, set->_n_msgs + 1,
1374 sizeof(struct _msgptr),
1378 * Since the messages are compacted, there aren't any
1379 * empty elements in the array to check for.
1386 char *catgets1(nl_catd catd,int setno,int msgno,char *def)
1387 /*---- catd: the catd to get the message from ----*/
1388 /*---- setno: the set number of the message ----*/
1389 /*---- msgno: the message number of the message ----*/
1390 /*---- def: the default string to be returned ----*/
1394 char *_do_read_msg();
1398 if (catd == NULL || catd == CATD_ERR ||
1399 catd->_magic != CAT_MAGIC || catd->_fd == NL_FILE_UNUSED) {
1402 if (catd->_fd == NL_FILE_CLOSED) {
1403 catd = _do1_open(catd);
1404 if (catd == CATD_ERR)
1408 if (catd->_mem) { /*---- for mapped files ----*/
1409 if (setno <= catd->_hd->_setmax) {
1410 if (msgno < catd->_set[setno]._n_msgs) {
1411 if (catd->_set[setno]._mp[msgno]._offset) {
1413 catd->_set[setno]._mp[msgno]._offset);
1419 else { /*---- for unmapped files ----*/
1420 m = _do1_read_msg(catd,setno,msgno);
1430 #define FACILITY_CODE_MASK 0xF0000000
1431 #define FACILITY_CODE_SHIFT 28
1433 #define COMPONENT_CODE_MASK 0x0FFFF000
1434 #define COMPONENT_CODE_SHIFT 12
1436 #define STATUS_CODE_MASK 0x00000FFF
1437 #define STATUS_CODE_SHIFT 0
1439 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
1442 * The system-dependant location for the catalog files is defined in sysconf.h
1443 * RPC_DEFAULT_NLSPATH should be defined in sysconf.h. Otherwise we use
1444 * /usr/afs/etc/C/%s.cat
1447 #ifndef RPC_NLS_FORMAT
1448 #define RPC_NLS_FORMAT "%s.cat"
1451 dce1_error_inq_text (status_to_convert, error_text, status)
1452 afs_uint32 status_to_convert;
1453 unsigned char *error_text;
1457 unsigned short facility_code;
1458 unsigned short component_code;
1459 unsigned short status_code;
1460 unsigned short i, failed=0;
1462 char component_name[4];
1463 char *facility_name;
1464 char filename_prefix[7];
1465 char nls_filename[11];
1466 char alt_filename[80];
1469 static char *facility_names[] = {
1475 * set up output status for future error returns
1482 * check for ok input status
1484 if (status_to_convert == 0)
1490 strcpy ((char *)error_text, "successful completion");
1495 * extract the component, facility and status codes
1497 facility_code = (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
1498 component_code = (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
1499 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
1502 * see if this is a recognized facility
1504 if (facility_code == 0 || facility_code > sizeof (facility_names) / sizeof (char *))
1506 sprintf ((char *) error_text, "status %08x (unknown facility)", status_to_convert);
1509 facility_name = facility_names[facility_code - 1];
1511 * Convert component name from RAD-50 component code. (Mapping is:
1512 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
1514 component_name[3] = 0;
1515 component_name[2] = component_code % 40;
1516 component_code /= 40;
1517 component_name[1] = component_code % 40;
1518 component_name[0] = component_code / 40;
1519 for (i = 0; i < 3; i++)
1521 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
1523 sprintf (filename_prefix, "%3s%3s", facility_name, component_name);
1524 sprintf (nls_filename, RPC_NLS_FORMAT, filename_prefix);
1527 * Open the message file
1529 #if defined(AFS_OSF_ENV)
1530 #if defined(AFS_OSF20_ENV)
1531 catd = (nl_catd) catopen (nls_filename, 0);
1533 catd = (nl_catd) catopen1 (nls_filename, 0);
1536 J = (int) catopen (nls_filename, 0);
1539 if (catd == (nl_catd) -1)
1542 * If we did not succeed in opening message file using NLSPATH,
1543 * try to open the message file in a well-known default area
1546 #ifndef RPC_DEFAULT_NLSPATH
1547 sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH, filename_prefix);
1549 sprintf (alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix);
1552 #if defined(AFS_OSF_ENV)
1553 #if defined(AFS_OSF20_ENV)
1554 catd = (nl_catd) catopen (alt_filename, 0);
1556 catd = (nl_catd) catopen1 (alt_filename, 0);
1559 J = (int) catopen (alt_filename, 0);
1562 if (catd == (nl_catd) -1)
1564 sprintf ((char *) error_text, "status %08x (%s / %s)",
1565 status_to_convert, facility_name, component_name);
1570 * try to get the specified message from the file
1572 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1573 message = (char *) catgets1 (catd, 1, status_code, NO_MESSAGE);
1575 message = (char *) catgets (catd, 1, status_code, NO_MESSAGE);
1578 * if everything went well, return the resulting message
1580 if (strcmp (message, NO_MESSAGE) != 0)
1582 sprintf ((char *) error_text, "%s (%s / %s)",
1583 message, facility_name, component_name);
1595 sprintf ((char *) error_text, "status %08x (%s / %s)",
1596 status_to_convert, facility_name, component_name);
1598 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1607 icl_DumpKernel(outFilep, setname)
1611 afs_int32 bufferSize = 0;
1614 afs_int32 code, retVal = 0;
1619 afs_int32 dummy, dummy2;
1620 struct logInfo *lip;
1622 /* first, enumerate the logs we're interested in */
1626 /* dump logs for a particular set */
1627 for(i=0; i < ICL_LOGSPERSET; i++) {
1628 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET,
1629 (long) setname, i, (long) tname, sizeof(tname));
1631 if (errno == EBADF) {
1633 continue; /* missing slot, nothing to worry about */
1637 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
1638 (long) tname, (long) &dummy, (long) &dummy2, 0);
1642 if (dummy > bufferSize) /* find biggest log */
1644 lip = (struct logInfo *) malloc(sizeof(struct logInfo));
1645 bzero((char *)lip, sizeof(*lip));
1646 lip->nextp = allInfo;
1648 lip->name = (char *) malloc(strlen(tname)+1);
1649 strcpy(lip->name, tname);
1656 for(i=0;i<1000;i++) {
1657 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS,
1658 i, (long) tname, sizeof(tname), (long) &dummy);
1660 if (dummy > bufferSize) /* find biggest log */
1662 lip = (struct logInfo *) malloc(sizeof(struct logInfo));
1663 bzero((char *)lip, sizeof(*lip));
1664 lip->nextp = allInfo;
1666 lip->name = (char *) malloc(strlen(tname)+1);
1667 strcpy(lip->name, tname);
1671 if (bufferSize == 0) return -1;
1672 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1673 if (!bufferp) return -1;
1675 fprintf(outFilep, "Found %d logs.\n", i);
1677 /* now print out the contents of each log */
1678 for(lip = allInfo; lip; lip=lip->nextp) {
1679 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
1680 /* read out everything first; gets a more consistent
1683 nwords = 0; /* total words copied out */
1685 /* display all the entries in the log */
1686 if (bufferSize - nwords <= 0) break; /* filled whole buffer */
1687 code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT,
1688 (long) lip->name, (long) (bufferp+nwords),
1689 bufferSize - nwords, (long) &i);
1691 /* otherwise we've got an error */
1692 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
1695 /* otherwise, we have flags in the high order byte, and
1696 * a length (in words) in the remainder.
1698 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
1699 fprintf(outFilep, "Log wrapped; data missing.\n");
1707 } /* for loop over all cookies */
1709 /* otherwise we should display all of the log entries here.
1710 * Note that a record may end in the middle, in which case
1711 * we should start over with the cookie value of the start
1714 for(ix = 0; ix<nwords;) {
1715 /* start of a record */
1716 rlength = (bufferp[ix] >> 24) & 0xff;
1718 fprintf(outFilep, "Internal error: 0 length record\n");
1722 /* ensure that entire record fits */
1723 if (ix+rlength > nwords) {
1724 /* doesn't fit, adjust cookie and break */
1727 /* print the record */
1728 DisplayRecord(outFilep, &bufferp[ix], rlength);
1731 /* obsolete: read entire buffer first */
1732 i += rlength; /* update cookie value, too */
1734 } /* for loop displaying buffer */
1735 } /* for loop over all logs */
1742 /* clear out log 'name' */
1748 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0);
1752 /* clear out set 'name' */
1758 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long) name, 0, 0, 0);
1762 /* clear out all logs */
1767 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0);
1771 /* list out all available sets to outFileP */
1772 int icl_ListSets(outFileP)
1780 for(i=0;i<1000;i++) {
1781 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS,
1782 i, (long) tname, sizeof(tname), (long) &states);
1784 (void) fprintf(outFileP, "%s %s%s%s\n", tname,
1785 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
1786 (states & ICL_SETF_FREED) ? " (dormant)" : "",
1787 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
1793 /* list out all available logs to outFileP */
1794 int icl_ListLogs(outFileP, int32flg)
1804 for(i=0;i<1000;i++) {
1805 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS,
1806 i, (long) tname, sizeof(tname), (long) &logSize);
1810 /* get more information on the log */
1811 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname,
1812 (long) &logSize, (long) &allocated, 0);
1815 (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024,
1816 allocated ? "allocated" : "unallocated");
1819 (void) fprintf(outFileP, "%s\n", tname);
1825 /* list out all available logs to outFileP */
1826 int icl_ListLogsBySet(outFileP, setname, int32flg)
1837 for(i=0; i < ICL_LOGSPERSET; i++) {
1838 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET,
1839 (long) setname, i, (long) tname, sizeof(tname));
1841 if (errno == EBADF) {
1843 continue; /* missing */
1849 /* get more information on the log */
1850 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname,
1851 (long) &logSize, (long) &allocated, 0);
1854 (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024,
1855 allocated ? "allocated" : "unallocated");
1858 (void) fprintf(outFileP, "%s\n", tname);
1864 /* activate/deactivate/free specified set */
1865 int icl_ChangeSetState(name, op)
1871 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long) name, op, 0, 0);
1875 /* activate/deactivate/free all sets */
1876 int icl_ChangeAllSetState(op)
1881 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0);
1885 /* set size if log */
1886 int icl_ChangeLogSize(name, logSize)
1892 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0, 0);
1896 /* get logsize of specified log */
1897 int icl_GetLogsize(logname, logSizeP, allocatedP)
1899 afs_int32 *logSizeP;
1903 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) logname,
1904 (long) logSizeP, (long) allocatedP, 0);
1908 /* get state of specified set */
1909 int icl_GetSetState(setname, stateP)
1914 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long) setname,
1915 (long) stateP, 0, 0);
1919 icl_TailKernel(outFilep, logname, waitTime)
1924 afs_int32 bufferSize = 0;
1925 afs_int32 newBufferSize;
1928 afs_int32 code, retVal = 0;
1933 struct logInfo *lip;
1935 /* get information about the specified log */
1936 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
1937 (long) logname, (long) &bufferSize, (long) &allocated, 0);
1940 if (errno == ENOENT)
1941 (void) fprintf(stderr, "'%s' not found\n", logname);
1943 (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n",
1950 (void) fprintf(stderr, "'%s' not allocated\n", logname);
1954 if (bufferSize == 0) return -1;
1955 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1958 (void) fprintf(stderr, "cannot allocate %d words for buffer\n",
1963 /* start "infinite" loop */
1966 /* read out all that's currently there */
1967 nwords = 0; /* total words copied out */
1968 i = 0; /* initialize cookie */
1970 /* display all the entries in the log */
1971 if (bufferSize - nwords <= 0)
1972 break; /* filled whole buffer, clear when done */
1973 code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR,
1974 (long) logname, (long) (bufferp+nwords),
1975 bufferSize - nwords, (long) &i);
1977 /* otherwise we've got an error */
1978 fprintf(stderr, "returned error %d dumping log.\n", errno);
1982 /* otherwise, we have flags in the high order byte, and
1983 * a length (in words) in the remainder.
1992 } /* for loop over all cookies */
1994 /* otherwise we should display all of the log entries here.
1995 * Note that a record may end in the middle, in which case
1996 * we should start over with the cookie value of the start
1999 for(ix = 0; ix<nwords;) {
2000 /* start of a record */
2001 rlength = (bufferp[ix] >> 24) & 0xff;
2002 /* ensure that entire record fits */
2003 if (ix+rlength > nwords) {
2004 /* doesn't fit, adjust cookie and break */
2006 fprintf(stderr, "BOGUS: 0 length record\n");
2012 /* print the record */
2013 DisplayRecord(outFilep, &bufferp[ix], rlength);
2015 } /* for loop displaying buffer */
2020 /* see if things have changed */
2021 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
2022 (long) logname, (long) &newBufferSize,
2023 (long) &allocated, 0);
2026 if (errno == ENOENT)
2027 (void) fprintf(stderr, "'%s' not found\n", logname);
2029 (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n",
2037 (void) fprintf(stderr, "'%s' no int32er allocated\n", logname);
2042 if (bufferSize == 0)
2044 (void) fprintf(stderr, "buffer size has become 0\n");
2048 if (bufferSize != newBufferSize)
2050 /* have to reallocate a buffer */
2051 bufferSize = newBufferSize;
2053 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
2056 (void) fprintf(stderr, "cannot allocate %d words for buffer\n",
2062 } /* infinite loop */
2069 #if !defined(AFS_SGI_ENV)
2070 afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
2071 long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6;
2074 #ifdef AFS_LINUX20_ENV
2075 #if defined AFS_LINUX_64BIT_KERNEL
2077 /* don't want to sign extend it to 64bit, so using ulong */
2078 eparm[0] = (unsigned long)parm3;
2079 eparm[1] = (unsigned long)parm4;
2080 eparm[2] = (unsigned long)parm5;
2081 eparm[3] = (unsigned long)parm6;
2089 /* Linux can only handle 5 arguments in the actual syscall. */
2090 if (call == AFSCALL_ICL) {
2091 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
2094 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
2096 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
2097 /* on sparc this function returns none value, so do it myself */
2098 __asm__ __volatile__ ("
2105 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2106 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
2108 #if defined(AFS_SGI_ENV)
2109 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
2111 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
2115 #endif /* AFS_LINUX20_ENV */
2122 /* init function, called once, under icl_lock */
2128 /* setup signal handler, in user space */
2134 icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2136 struct afs_icl_log *baseLogp;
2137 struct afs_icl_log *fatalLogp;
2138 struct afs_icl_set **outSetpp;
2140 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags*/0, outSetpp);
2143 /* create a set, given pointers to base and fatal logs, if any.
2144 * Logs are unlocked, but referenced, and *outSetpp is returned
2145 * referenced. Function bumps reference count on logs, since it
2146 * addds references from the new icl_set. When the set is destroyed,
2147 * those references will be released.
2149 icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2151 struct afs_icl_log *baseLogp;
2152 struct afs_icl_log *fatalLogp;
2154 struct afs_icl_set **outSetpp;
2156 register struct afs_icl_set *setp;
2158 afs_int32 states = ICL_DEFAULT_SET_STATES;
2160 if (!icl_inited) icl_Init();
2162 for (setp = icl_allSets; setp; setp = setp->nextp) {
2163 if (strcmp(setp->name, name) == 0) {
2166 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2168 setp->states |= ICL_SETF_PERSISTENT;
2174 /* determine initial state */
2175 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2176 states = ICL_SETF_ACTIVE;
2177 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2178 states = ICL_SETF_FREED;
2179 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2180 states |= ICL_SETF_PERSISTENT;
2182 setp = (struct afs_icl_set *) osi_Alloc(sizeof(struct afs_icl_set));
2183 bzero((caddr_t)setp, sizeof(*setp));
2185 if (states & ICL_SETF_FREED)
2186 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2187 setp->states = states;
2189 setp->name = (char *)osi_Alloc(strlen(name)+1);
2190 strcpy(setp->name, name);
2191 setp->nevents = ICL_DEFAULTEVENTS;
2192 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
2193 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2194 setp->eventFlags[i] = 0xff; /* default to enabled */
2196 /* update this global info under the icl_lock */
2197 setp->nextp = icl_allSets;
2200 /* set's basic lock is still held, so we can finish init */
2202 setp->logs[0] = baseLogp;
2203 icl_LogHold(baseLogp);
2204 if (!(setp->states & ICL_SETF_FREED))
2205 icl_LogUse(baseLogp); /* log is actually being used */
2208 setp->logs[1] = fatalLogp;
2209 icl_LogHold(fatalLogp);
2210 if (!(setp->states & ICL_SETF_FREED))
2211 icl_LogUse(fatalLogp); /* log is actually being used */
2218 /* function to change event enabling information for a particular set */
2219 icl_SetEnable(setp, eventID, setValue)
2220 struct afs_icl_set *setp;
2226 if (!ICL_EVENTOK(setp, eventID)) {
2229 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2231 *tp |= ICL_EVENTMASK(eventID);
2233 *tp &= ~(ICL_EVENTMASK(eventID));
2237 /* return indication of whether a particular event ID is enabled
2238 * for tracing. If *getValuep is set to 0, the event is disabled,
2239 * otherwise it is enabled. All events start out enabled by default.
2241 icl_GetEnable(setp, eventID, getValuep)
2242 struct afs_icl_set *setp;
2246 if (!ICL_EVENTOK(setp, eventID)) {
2249 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2256 /* hold and release event sets */
2258 register struct afs_icl_set *setp;
2264 /* free a set. Called with icl_lock locked */
2266 register struct afs_icl_set *setp;
2268 register struct afs_icl_set **lpp, *tp;
2270 register struct afs_icl_log *tlp;
2272 for(lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2274 /* found the dude we want to remove */
2276 osi_Free(setp->name, 1+strlen(setp->name));
2277 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
2278 for(i=0; i < ICL_LOGSPERSET; i++) {
2279 if (tlp = setp->logs[i])
2282 osi_Free(setp, sizeof(struct afs_icl_set));
2283 break; /* won't find it twice */
2289 /* do the release, watching for deleted entries */
2291 register struct afs_icl_set *setp;
2293 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2294 icl_ZapSet(setp); /* destroys setp's lock! */
2299 /* free a set entry, dropping its reference count */
2301 register struct afs_icl_set *setp;
2303 setp->states |= ICL_SETF_DELETED;
2308 /* find a set by name, returning it held */
2309 struct afs_icl_set *icl_FindSet(name)
2312 register struct afs_icl_set *tp;
2314 for(tp = icl_allSets; tp; tp=tp->nextp) {
2315 if (strcmp(tp->name, name) == 0) {
2316 /* this is the dude we want */
2324 /* zero out all the logs in the set */
2326 struct afs_icl_set *setp;
2331 struct afs_icl_log *logp;
2333 for(i = 0; i < ICL_LOGSPERSET; i++) {
2334 logp = setp->logs[i];
2337 tcode = icl_ZeroLog(logp);
2338 if (tcode != 0) code = tcode; /* save the last bad one */
2345 icl_EnumerateSets(aproc, arock)
2349 register struct afs_icl_set *tp, *np;
2350 register afs_int32 code;
2353 for(tp = icl_allSets; tp; tp=np) {
2354 tp->refCount++; /* hold this guy */
2355 code = (*aproc)(tp->name, arock, tp);
2356 np = tp->nextp; /* tp may disappear next, but not np */
2357 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2364 icl_AddLogToSet(setp, newlogp)
2365 struct afs_icl_set *setp;
2366 struct afs_icl_log *newlogp;
2370 struct afs_icl_log *logp;
2372 for(i = 0; i < ICL_LOGSPERSET; i++) {
2373 if (!setp->logs[i]) {
2374 setp->logs[i] = newlogp;
2376 icl_LogHold(newlogp);
2377 if (!(setp->states & ICL_SETF_FREED)) {
2378 /* bump up the number of sets using the log */
2379 icl_LogUse(newlogp);
2387 icl_SetSetStat(setp, op)
2388 struct afs_icl_set *setp;
2393 struct afs_icl_log *logp;
2396 case ICL_OP_SS_ACTIVATE: /* activate a log */
2398 * If we are not already active, see if we have released
2399 * our demand that the log be allocated (FREED set). If
2400 * we have, reassert our desire.
2402 if (!(setp->states & ICL_SETF_ACTIVE)) {
2403 if (setp->states & ICL_SETF_FREED) {
2404 /* have to reassert desire for logs */
2405 for(i = 0; i < ICL_LOGSPERSET; i++) {
2406 logp = setp->logs[i];
2413 setp->states &= ~ICL_SETF_FREED;
2415 setp->states |= ICL_SETF_ACTIVE;
2420 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2421 /* this doesn't require anything beyond clearing the ACTIVE flag */
2422 setp->states &= ~ICL_SETF_ACTIVE;
2426 case ICL_OP_SS_FREE: /* deassert design for log */
2428 * if we are already in this state, do nothing; otherwise
2429 * deassert desire for log
2431 if (setp->states & ICL_SETF_ACTIVE)
2434 if (!(setp->states & ICL_SETF_FREED)) {
2435 for(i = 0; i < ICL_LOGSPERSET; i++) {
2436 logp = setp->logs[i];
2439 icl_LogFreeUse(logp);
2443 setp->states |= ICL_SETF_FREED;
2456 struct afs_icl_log *afs_icl_allLogs = 0;
2458 /* hold and release logs */
2460 register struct afs_icl_log *logp;
2466 /* hold and release logs, called with lock already held */
2468 register struct afs_icl_log *logp;
2474 /* keep track of how many sets believe the log itself is allocated */
2476 register struct afs_icl_log *logp;
2478 if (logp->setCount == 0) {
2479 /* this is the first set actually using the log -- allocate it */
2480 if (logp->logSize == 0) {
2481 /* we weren't passed in a hint and it wasn't set */
2482 logp->logSize = ICL_DEFAULT_LOGSIZE;
2484 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
2490 /* decrement the number of real users of the log, free if possible */
2491 icl_LogFreeUse(logp)
2492 register struct afs_icl_log *logp;
2494 if (--logp->setCount == 0) {
2495 /* no more users -- free it (but keep log structure around)*/
2496 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2497 logp->firstUsed = logp->firstFree = 0;
2498 logp->logElements = 0;
2499 logp->datap = (afs_int32 *)0;
2504 /* set the size of the log to 'logSize' */
2505 icl_LogSetSize(logp, logSize)
2506 register struct afs_icl_log *logp;
2510 /* nothing to worry about since it's not allocated */
2511 logp->logSize = logSize;
2515 logp->firstUsed = logp->firstFree = 0;
2516 logp->logElements = 0;
2518 /* free and allocate a new one */
2519 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2520 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
2521 logp->logSize = logSize;
2527 /* free a log. Called with icl_lock locked. */
2529 register struct afs_icl_log *logp;
2531 register struct afs_icl_log **lpp, *tp;
2533 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2535 /* found the dude we want to remove */
2537 osi_Free(logp->name, 1+strlen(logp->name));
2538 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
2539 osi_Free(logp, sizeof(struct icl_log));
2540 break; /* won't find it twice */
2546 /* do the release, watching for deleted entries */
2548 register struct afs_icl_log *logp;
2550 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2551 icl_ZapLog(logp); /* destroys logp's lock! */
2556 /* do the release, watching for deleted entries, log already held */
2558 register struct afs_icl_log *logp;
2560 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2561 icl_ZapLog(logp); /* destroys logp's lock! */
2566 /* zero out the log */
2568 register struct afs_icl_log *logp;
2570 logp->firstUsed = logp->firstFree = 0;
2571 logp->logElements = 0;
2575 /* free a log entry, and drop its reference count */
2577 register struct afs_icl_log *logp;
2579 logp->states |= ICL_LOGF_DELETED;
2585 icl_EnumerateLogs(aproc, arock)
2589 register struct afs_icl_log *tp;
2590 register afs_int32 code;
2593 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2594 tp->refCount++; /* hold this guy */
2595 code = (*aproc)(tp->name, arock, tp);
2596 if (--tp->refCount == 0)
2604 afs_icl_bulkSetinfo_t *GetBulkSetInfo()
2606 unsigned int infoSize;
2608 infoSize = sizeof(afs_icl_bulkSetinfo_t) +
2609 (ICL_RPC_MAX_SETS-1) * sizeof(afs_icl_setinfo_t);
2612 setInfo = (afs_icl_bulkSetinfo_t *)malloc(infoSize);
2615 (void) fprintf(stderr, "Could not allocate the memory for bulk set info structure\n");
2619 bzero((char *)setInfo, infoSize);
2624 afs_icl_bulkLoginfo_t *GetBulkLogInfo()
2625 { unsigned int infoSize;
2627 infoSize = sizeof(afs_icl_bulkLoginfo_t) +
2628 (ICL_RPC_MAX_LOGS-1) * sizeof(afs_icl_loginfo_t);
2631 logInfo = (afs_icl_bulkLoginfo_t *)malloc(infoSize);
2634 (void) fprintf(stderr, "Could not allocate the memory for bulk log info structure\n");
2639 bzero((char *)logInfo, infoSize);
2644 static DoDump(as, arock)
2645 register struct cmd_syndesc *as;
2650 afs_int32 waitTime = 10 /* seconds */;
2654 FILE *outfp = stdout;
2656 struct cmd_item * itemp;
2658 if (geteuid() != 0) {
2659 printf("fstrace must be run as root\n");
2663 if (as->parms[3].items) {
2664 if (!as->parms[1].items)
2666 (void) fprintf(stderr, "-sleep can only be used with -follow\n");
2669 waitTime = strtol(as->parms[3].items->data,
2673 if (as->parms[2].items)
2675 /* try to open the specified output file */
2676 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL)
2678 (void) fprintf(stderr, "Cannot open file '%s' for writing\n",
2679 as->parms[2].items->data);
2683 #ifdef AFS_SGI64_ENV
2684 startTime = time((time_t *) 0);
2686 startTime = time(0);
2688 (void) fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
2691 if (as->parms[0].items)
2693 for (itemp = as->parms[0].items; itemp; itemp = itemp->next)
2695 tcode = icl_DumpKernel(outfp, itemp->data);
2698 (void) fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
2699 itemp->data, errno);
2703 } else if (as->parms[1].items) {
2704 logname = as->parms[1].items->data;
2705 code = icl_TailKernel(outfp, logname, waitTime);
2707 (void) fprintf(stderr, "Error tailing kernel log '%s' (errno = %d)\n",
2711 code = icl_DumpKernel(outfp, NULL);
2713 (void) fprintf(outfp, "\nAFS Trace Dump - %s\n",
2714 code ? "FAILED" : "Completed");
2716 if (outfp != stdout)
2717 (void) fclose(outfp);
2722 static void SetUpDump()
2724 struct cmd_syndesc *dumpSyntax;
2726 dumpSyntax = cmd_CreateSyntax("dump", DoDump, (char *)NULL, "dump AFS trace logs");
2727 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2728 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL, "log_name");
2729 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL, "output_filename");
2730 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds_between_reads");
2733 static DoShowLog(as, arock)
2734 register struct cmd_syndesc *as;
2737 afs_int32 retVal = 0;
2742 struct cmd_item * itemp;
2744 if (geteuid() != 0) {
2745 printf("fstrace must be run as root\n");
2748 if (as->parms[2].items) int32flg = 1;
2750 if (as->parms[0].items) {
2751 /* enumerate logs for the specified sets */
2752 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2753 (void) fprintf(stdout, "Logs for set '%s':\n", itemp->data);
2754 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
2756 (void) fprintf(stderr, "Error in enumerating set %s (errno = %d)\n",
2757 itemp->data, errno);
2762 else if (as->parms[1].items) {
2763 /* print out log information */
2764 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
2765 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
2767 (void) fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
2768 logSize/1024, allocated ? "allocated" : "unallocated");
2770 (void) fprintf(stderr, "Could not find log '%s' (errno = %d)\n",
2771 itemp->data, errno);
2778 (void) fprintf(stdout, "Available logs:\n");
2779 code = icl_ListLogs(stdout, int32flg);
2781 (void) fprintf(stderr, "Error in listing logs (errno = %d)\n", errno);
2789 static void SetUpShowLog()
2791 struct cmd_syndesc *showSyntax;
2793 showSyntax = cmd_CreateSyntax("lslog", DoShowLog, (char *)NULL,"list available logs");
2794 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2795 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name");
2796 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL,"");
2799 static DoShowSet(as, arock)
2800 register struct cmd_syndesc *as;
2803 afs_int32 retVal = 0;
2806 struct cmd_item * itemp;
2808 if (geteuid() != 0) {
2809 printf("fstrace must be run as root\n");
2812 if (as->parms[0].items) {
2813 /* print information on the specified sets */
2814 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2815 code = icl_GetSetState(itemp->data, &state);
2817 (void) fprintf(stderr, "Error getting status on set %s (errno = %d)\n",
2818 itemp->data, errno);
2822 (void) fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
2823 (state & ICL_SETF_ACTIVE) ? "active" : "inactive",
2824 (state & ICL_SETF_FREED) ? " (dormant)" : "",
2825 (state & ICL_SETF_PERSISTENT) ? " persistent" : "");
2830 (void) fprintf(stdout, "Available sets:\n");
2831 code = icl_ListSets(stdout);
2833 (void) fprintf(stderr, "Error in listing sets (errno = %d)\n", errno);
2841 static void SetUpShowSet()
2843 struct cmd_syndesc *showSyntax;
2845 showSyntax = cmd_CreateSyntax("lsset", DoShowSet, (char *)NULL, "list available event sets");
2846 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2849 static DoClear(as, arock)
2850 register struct cmd_syndesc *as;
2853 afs_int32 retVal = 0;
2855 struct cmd_item * itemp;
2857 if (geteuid() != 0) {
2858 printf("fstrace must be run as root\n");
2861 if (as->parms[0].items) {
2862 /* clear logs for the specified sets */
2863 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2864 code = icl_ClearSet(itemp->data);
2866 (void) fprintf(stderr, "Error in clearing set %s (errno = %d)\n",
2867 itemp->data, errno);
2871 } else if (as->parms[1].items) {
2872 /* clear specified log */
2873 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2874 code = icl_ClearLog(itemp->data);
2876 (void) fprintf(stderr, "Error in clearing log %s (errno = %d)\n",
2877 itemp->data, errno);
2883 /* clear all logs */
2884 code = icl_ClearAll();
2886 (void) fprintf(stderr, "Error in clearing logs (errno = %d)\n", errno);
2894 static void SetUpClear()
2896 struct cmd_syndesc *clearSyntax;
2898 clearSyntax = cmd_CreateSyntax("clear", DoClear, (char *)NULL, "clear logs by logname or by event set");
2899 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2900 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
2903 static DoSet(as, arock)
2904 register struct cmd_syndesc *as;
2907 afs_int32 retVal = 0;
2912 struct cmd_item * itemp;
2914 if (geteuid() != 0) {
2915 printf("fstrace must be run as root\n");
2918 if (as->parms[1].items) {
2919 op = ICL_OP_SS_ACTIVATE;
2920 operation = "active";
2921 } else if (as->parms[2].items) {
2922 op = ICL_OP_SS_DEACTIVATE;
2923 operation = "inactive";
2924 } else if (as->parms[3].items) {
2925 op = ICL_OP_SS_DEACTIVATE;
2926 operation = "inactive";
2929 /* assume active" */
2930 op = ICL_OP_SS_ACTIVATE;
2931 operation = "active";
2934 if (as->parms[0].items) {
2935 /* activate specified sets */
2936 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2937 code = icl_ChangeSetState(itemp->data, op);
2939 (void) fprintf(stderr, "cannot set state of %s to %s (errno = %d)\n",
2940 itemp->data, operation, errno);
2944 /* try to make it dormant as well */
2945 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2947 (void) fprintf(stderr, "cannot set state of %s to dormant (errno = %d)\n",
2948 itemp->data, errno);
2956 code = icl_ChangeAllSetState(op);
2958 (void) fprintf(stderr, "cannot set the state of all sets to %s (errno = %d)\n",
2963 /* try to make it dormant as well */
2964 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2966 (void) fprintf(stderr, "cannot set the state of all sets to dormant (errno = %d)\n", errno);
2975 static void SetUpSet()
2977 struct cmd_syndesc *setSyntax;
2979 setSyntax = cmd_CreateSyntax("setset", DoSet, (char *)NULL,"set state of event sets");
2980 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2981 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL,"");
2982 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
2983 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL,"");
2986 static DoResize(as, arock)
2987 register struct cmd_syndesc *as;
2990 afs_int32 retVal = 0;
2992 afs_int32 bufferSize;
2993 struct cmd_item * itemp;
2995 if (geteuid() != 0) {
2996 printf("fstrace must be run as root\n");
2999 /* get buffer size */
3000 bufferSize = atoi(as->parms[1].items->data);
3001 bufferSize *= BUFFER_MULTIPLIER;
3002 if (bufferSize == 0)
3003 bufferSize = ICL_DEFAULT_LOGSIZE;
3005 /* set the size of the specified logs */
3006 if (itemp = as->parms[0].items) {
3007 for (; itemp; itemp = itemp->next) {
3008 code = icl_ChangeLogSize(itemp->data, bufferSize);
3010 (void) fprintf(stderr, "Error in changing log %s buffer size (errno = %d)\n",
3011 itemp->data, errno);
3016 /* Use the only current support log, "cmfx" */
3017 code = icl_ChangeLogSize("cmfx", bufferSize);
3019 (void) fprintf(stderr, "Error in changing log cmfx buffer size (errno = %d)\n", errno);
3027 static void SetUpResize()
3029 struct cmd_syndesc *setsizeSyntax;
3031 setsizeSyntax = cmd_CreateSyntax("setlog", DoResize, (char *)NULL, "set the size of a log");
3032 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name");
3033 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED, "1-kilobyte_units");
3036 #include "AFS_component_version_number.c"
3042 setlocale(LC_ALL, "");
3043 #ifdef AFS_SGI62_ENV
3044 set_kernel_sizeof_long();
3047 /* set up user interface then dispatch */
3055 return(cmd_Dispatch(argc, argv));
3058 #include "AFS_component_version_number.c"
3061 printf("fstrace is NOT supported for this OS\n");