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 <afsconfig.h>
14 #include <afs/param.h>
19 #include <sys/types.h>
20 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43) && !defined(AFS_DARWIN_ENV)
22 /*#ifdef AFS_AIX_ENV*/
30 #include <afs/afs_args.h>
32 #include <afs/afsutil.h>
34 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV)
35 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
36 int afs_icl_sizeofLong = 2;
38 int afs_icl_sizeofLong = 1;
42 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
43 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
47 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
48 void set_kernel_sizeof_long(void)
53 retval = sysconf(_SC_KERN_POINTERS);
56 afs_icl_sizeofLong = 2;
60 afs_icl_sizeofLong = 1;
64 #endif /* AFS_SGI62_ENV */
65 #endif /* AFS_SGI61_ENV */
67 #define BUFFER_MULTIPLIER 1024
69 /* make it big enough to snapshot everything at once, since
70 * decoding takes so long.
72 #define IBSIZE 100000 /* default size */
75 struct logInfo *nextp;
79 char dumpFileName[256] = "";
80 RegisterIclDumpFileName(name)
83 (void) sprintf(dumpFileName, "icl.%.250s", name);
86 /* define globals to use for bulk info */
87 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *)0;
88 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *)0;
90 struct afs_icl_set *icl_allSets = 0;
94 /* given a type and an address, get the size of the thing
97 static icl_GetSize(type, addr)
105 ICL_SIZEHACK(type, addr);
109 /* Check types in printf string "bufferp", making sure that each
110 * is compatible with the corresponding parameter type described
111 * by typesp. Also watch for prematurely running out of parameters
112 * before the string is gone.
115 static int CheckTypes(bufferp, typesp, typeCount, outMsgBuffer)
127 for(tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
130 /* hit end of string. We win as long as we aren't
133 if (inPercent) return 0;
138 inPercent = 1 - inPercent;
142 if (tc >= '0' && tc <= '9') {
143 /* skip digits in % string */
148 /* 'l' is a type modifier. */
152 /* otherwise, we've finally gotten to the type-describing
153 * character. Make sure there's a type descriptor, and then
154 * check the type descriptor.
158 return 0; /* no more type descriptors left */
160 if (typesp[tix] != 1) /* not a string descriptor */
163 *outMsgBuffer = (char)1;
165 if (tc == 'u' || tc == 'x' || tc == 'd'
167 if (typesp[tix] != 0)
168 return 0; /* not an integer descriptor */
172 *outMsgBuffer = (char)2;
175 *outMsgBuffer = (char)3;
178 *outMsgBuffer = (char)4;
182 *outMsgBuffer = (char)5;
186 /* otherwise we're fine, so eat this descriptor */
192 #else /* AFS_SGI61_ENV */
193 static CheckTypes(bufferp, typesp, typeCount)
204 for(tc = *bufferp;; tc = *(++bufferp)) {
206 /* hit end of string. We win as long as we aren't
209 if (inPercent) return 0;
213 inPercent = 1 - inPercent;
217 if (tc >= '0' && tc <= '9') continue; /* skip digits in % string */
218 /* otherwise, we've finally gotten to the type-describing
219 * character. Make sure there's a type descriptor, and then
220 * check the type descriptor.
224 return 0; /* no more type descriptors left */
225 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
227 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
228 && (typesp[tix] != 0))
229 return 0; /* not an integer descriptor */
230 /* otherwise we're fine, so eat this descriptor */
236 #endif /* AFS_SGI61_ENV */
238 /* display a single record.
239 * alp points at the first word in the array to be interpreted
240 * rsize gives the # of words in the array
242 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
243 #define uint64_t long long
245 static DisplayRecord(outFilep, alp, rsize)
247 register afs_int32 *alp;
250 char msgBuffer[1024];
252 char outMsgBuffer[1024];
254 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
255 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
256 #else /* AFS_SGI61_ENV */
257 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
258 #endif /* AFS_SGI61_ENV */
259 int printfTypes[ICL_MAXEXPANSION * 4];
265 int pix; /* index in alp */
266 int pfpix; /* index in printfParms */
267 int pftix; /* index in printfTypes */
269 int printed; /* did we print the string yet? */
272 /* decode parameters */
273 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
279 for(i=0; i<4*ICL_MAXEXPANSION; i++)
281 /* decode each parameter, getting addrs for afs_hyper_t and strings */
282 for(i=0; !done && i<4; i++) {
283 type = (temp >> (18 - i*6)) & 0x3f;
289 case ICL_TYPE_POINTER:
290 printfTypes[pftix++] = 0;
292 printfParms[pfpix] = alp[pix];
293 printfParms[pfpix] &= 0xffffffff;
294 if (afs_64bit_kernel) {
295 printfParms[pfpix] <<= 32;
296 printfParms[pfpix] |= alp[pix+1];
298 #else /* AFS_SGI61_ENV */
300 printfParms[pfpix] = alp[pix+1];
301 printfParms[pfpix] |= (alp[pix] <<= 32);
302 #else /* AFS_ALPHA_ENV */
303 printfParms[pfpix] = alp[pix];
304 #endif /* AFS_ALPHA_ENV */
305 #endif /* AFS_SGI61_ENV */
309 printfTypes[pftix++] = 0;
310 printfParms[pfpix++] = alp[pix];
313 printfTypes[pftix++] = 0;
314 printfParms[pfpix++] = alp[pix];
315 printfTypes[pftix++] = 0;
316 printfParms[pfpix++] = alp[pix+1];
319 printfTypes[pftix++] = 0;
320 printfParms[pfpix++] = alp[pix];
321 printfTypes[pftix++] = 0;
322 printfParms[pfpix++] = alp[pix+1];
323 printfTypes[pftix++] = 0;
324 printfParms[pfpix++] = alp[pix+2];
325 printfTypes[pftix++] = 0;
326 printfParms[pfpix++] = alp[pix+3];
328 case ICL_TYPE_STRING:
329 printfTypes[pftix++] = 1;
331 printfStrings[pfpix++] = (char*) &alp[pix];
332 #else /* AFS_SGI64_ENV */
334 printfStrings[pfpix++] = (char *) &alp[pix];
335 #else /* AFS_SGI61_ENV */
336 printfParms[pfpix++] = (long) &alp[pix];
337 #endif /* AFS_SGI61_ENV */
338 #endif /* AFS_SGI64_ENV */
340 case ICL_TYPE_UNIXDATE:
341 printfParms[pfpix++] = (long) ctime((time_t *)&alp[pix]);
344 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
351 pix += icl_GetSize(type, (char *) &alp[pix]);
354 /* next, try to decode the opcode into a printf string */
355 dce1_error_inq_text(alp[1], msgBuffer, &status);
357 /* if we got a string back, and it is compatible with the
358 * parms we've got, then print it.
363 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
364 /* we have a string to use, but it ends "(dfs / zcm)",
365 * so we remove the extra gunk.
367 j = strlen(outMsgBuffer);
369 outMsgBuffer[j-11] = 0;
373 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000,
374 alp[3] % 1000000, alp[2]);
375 for (i=0; i<j; i++) {
376 if ((int)outMsgBuffer[i] > 5)
377 fputc(outMsgBuffer[i], outFilep);
379 switch (outMsgBuffer[i]) {
383 fprintf(outFilep, "%s", printfStrings[pfpix++]);
385 case 2: /* signed integer */
386 fprintf(outFilep, "%lld", printfParms[pfpix++]);
388 case 3: /* unsigned integer */
389 fprintf(outFilep, "%llu", printfParms[pfpix++]);
391 case 4: /* octal integer */
392 fprintf(outFilep, "%llo", printfParms[pfpix++]);
394 case 5: /* hex integer */
395 fprintf(outFilep, "%llx", printfParms[pfpix++]);
399 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
400 outMsgBuffer[i], pfpix);
401 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
407 fprintf(outFilep, "\n");
410 #else /* AFS_SGI61_ENV */
411 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
412 /* we have a string to use, but it ends "(dfs / zcm)",
413 * so we remove the extra gunk.
415 j = strlen(msgBuffer);
416 if (j > 12) msgBuffer[j-11] = 0;
417 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3]/1000000,
418 alp[3] % 1000000, alp[2]);
419 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
420 printfParms[2], printfParms[3], printfParms[4],
421 printfParms[5], printfParms[6], printfParms[7],
422 printfParms[8], printfParms[9], printfParms[10],
423 printfParms[11], printfParms[12], printfParms[13],
424 printfParms[14], printfParms[15]);
425 fprintf(outFilep, "\n");
428 #endif /* AFS_SGI61_ENV */
430 fprintf(outFilep, "Type mismatch, using raw print.\n");
431 fprintf(outFilep, "%s", msgBuffer);
435 if (alp[1] == ICL_INFO_TIMESTAMP) {
436 fprintf(outFilep, "time %d.%06d, pid %u: %s\n",
437 alp[3]/1000000, alp[3] % 1000000, alp[2],
438 ctime((time_t *)&alp[4]));
440 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n",
441 alp[1], alp[3]/1000000, alp[3] % 1000000, alp[2]);
442 /* now decode each parameter and print it */
445 for(i=0; !done && i<4; i++) {
446 type = (temp >> (18 - i*6)) & 0x3f;
452 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
456 tempParam = alp[pix];
458 tempParam |= alp[pix+1];
459 fprintf(outFilep, "p%d:%lld ", i, tempParam);
460 #else /* AFS_SGI61_ENV */
461 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
462 #endif /* AFS_SGI61_ENV */
464 case ICL_TYPE_POINTER:
466 tempParam = alp[pix];
468 tempParam |= alp[pix+1];
469 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
470 #else /* AFS_SGI61_ENV */
471 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
472 #endif /* AFS_SGI61_ENV */
475 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix], alp[pix+1]);
478 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
479 alp[pix+1], alp[pix+2], alp[pix+3]);
481 case ICL_TYPE_STRING:
482 fprintf(outFilep, "p%d:%s ", i, (char *) &alp[pix]);
484 case ICL_TYPE_UNIXDATE:
485 fprintf(outFilep, "p%d:%s ", i, ctime((time_t *)&alp[pix]));
488 printf("DisplayRecord: Bad type %d in raw print switch.\n",
496 pix += icl_GetSize(type, (char *) &alp[pix]);
499 fprintf(outFilep, "\n"); /* done with line */
509 #include <nl_types.h>
511 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
513 static nl_catd catopen1();
515 static nl_catd _do1_open();
516 static nl_catd cat_already_open();
517 static int make_sets();
518 static FILE *open1catfile();
519 static void add_open_cat();
520 static void cat_hard_close();
521 extern char *strchr();
523 static int catpid[NL_MAXOPEN];
524 static CATD *catsopen[NL_MAXOPEN];
525 #define PATH_FORMAT "/usr/lib/nls/msg/%L/%N:/etc/nls/msg/%L/%N"
526 #define DEFAULT_LANG "C"
527 #define TOO_MANY_HOLES(num_holes, num_non_holes) \
528 (((num_holes) > 100) && ((num_holes) > (num_non_holes)))
533 /*---- n: the number of bytes to be malloc'ed ----*/
537 t = (char *) malloc(n);
539 printf("Failed to get mem\n");
544 nl_catd catopen1 (cat, dummy)
547 /*---- char *cat: the name of the cat to be opened ----*/
548 /*---- int dummy: dummy variable ----*/
552 nl_catd _do_open(); /*---- routine that actually opens
559 if (catd = cat_already_open(cat)) {
560 catd->_count = catd->_count + 1;
564 catd = (CATD *)rmalloc (sizeof(CATD));
567 catd->_name = (char *)rmalloc(strlen(cat) + 1);
568 if ( catd->_name == NULL )
570 strcpy(catd->_name,cat);
572 catd->_magic = CAT_MAGIC;
574 #ifndef AFS_OSF20_ENV
575 catd->_pid = getpid();
578 if (_do1_open(catd) != CATD_ERR)
589 nl_catd _do1_open(catd)
592 /*---- pointer to the partially set up cat descriptor ----*/
595 int make_sets(); /*---- routine to unpack the sets into
596 fast acccess mode ----*/
597 void add_open_cat(); /*---- routine to keep a list of
600 int i; /*---- Misc counter(s) used for loop */
607 catd->_fd = open1catfile( catd->_name );
611 fread((void *)&magic,(size_t)4,(size_t)1,catd->_fd);
612 if (magic != CAT_MAGIC){
613 printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC, CATD_ERR);
620 /* if ((catd->_mem = shmat((int)fileno(catd->_fd), (char *)0, SHM_MAP | SHM_RDONLY))
621 == (char * )ERR ) { */
623 if (1) { /* disable the shmat, share memory segemnt */
625 /*______________________________________________________________________
626 If the file can not be mapped then simulate mapping for the index
627 table so that make_sets cat set things up. (rmalloc an area big
628 enough for the index table and read the whole thing in)
629 ______________________________________________________________________*/
631 /* reset the file pointer to the beginning of catalog */
632 fseek(catd->_fd,(long)0,0);
634 /* malloc the header, if fails return error */
635 catd->_hd = (struct _header *) rmalloc(sizeof(struct _header));
636 if ( catd->_hd == NULL )
639 /* read in the whole header */
640 fread((void *)catd->_hd,(size_t)sizeof(struct _header),(size_t)1,catd->_fd);
642 /* cs is a dummpy to hold a set temperorily. The purpose of */
643 /* this for loop is to fread the whole catalog so that the */
644 /* file pointer will be moved to the end of the catalog. */
645 for (i = 0 ; i < catd->_hd->_n_sets ; i++) {
646 fread((void *)&cs,(size_t)4,(size_t)1,catd->_fd);
647 fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)),1);
650 /* after the for loop, ftell returns the byte offset of the */
651 /* end of the catalog relative to the begining of the file. */
652 /* i.e. i contains the byte offset of the whole catalog. */
653 i = ftell(catd->_fd);
655 /* malloc _mem as a temp pointer to hold the entire catalog. */
656 catd->_mem = (char *)rmalloc(i);
657 if ( catd->_mem == NULL )
660 /* reset the file pointer to the begining. */
661 fseek(catd->_fd,(long)0,0);
663 /* read in the whole catalog into _mem */
664 fread((void *)catd->_mem,(size_t)i,(size_t)1,catd->_fd);
667 * If there aren't many holes in the set numbers,
668 * fully expand the compacted set array from the
669 * catalog. Then in catgets(), we'll be able to use
670 * the set number to index directly into the expanded
673 * If there are a lot of holes, leave the set array
674 * compacted. In catgets(), we'll search through it
675 * for the requested set.
678 num_holes = catd->_hd->_setmax - catd->_hd->_n_sets;
679 if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) {
680 catd->_sets_expanded = TRUE;
681 catd->_n_sets = catd->_hd->_setmax;
684 catd->_sets_expanded = FALSE;
685 catd->_n_sets = catd->_hd->_n_sets - 1;
688 /* malloc one extra set more than the max. set index */
689 catd->_set = (struct _catset *) rmalloc((catd->_n_sets+1)*
690 sizeof (struct _catset));
691 if ( catd->_set == NULL )
694 /* save the max. set number in catd->_setmax */
695 catd->_setmax = catd->_hd->_setmax;
696 /* call make_set to malloc memory for every message */
697 if(make_sets(catd) == -1)
706 /*______________________________________________________________________
707 Normal mapping has occurred, set a few things up and call make_sets
708 ______________________________________________________________________*/
710 catd->_hd =( struct _header * )( catd->_mem );
711 catd->_setmax = catd->_hd->_setmax;
712 catd->_set = (struct _catset *) rmalloc((catd->_hd->_setmax+1)*
713 sizeof (struct _catset));
714 if ( catd->_set == NULL )
716 if(make_sets(catd) == -1)
724 static void add_open_cat(catd)
726 /*---- catd to be added to the list of catalogs ----*/
729 int i = 0; /*---- Misc counter(s) used for loops ----*/
730 while (i < NL_MAXOPEN && catsopen[i]) {
731 if (!strcmp(catd->_name,catsopen[i]->_name)
732 #ifndef AFS_OSF20_ENV
733 && getpid()==catsopen[i]->_pid)
738 return; /*---- The catalog is already here ----*/
742 if (i < NL_MAXOPEN) {
744 catpid[i] = getpid();
753 * FUNCTION: Expands the compacted version of the catalog index table into
754 * the fast access memory version.
756 * EXECUTION ENVIRONMENT:
758 * Make_set executes under a process.
764 static int make_sets(catd)
767 struct _catset *cset;
768 char *base = catd->_mem;
769 int n_sets = catd->_hd->_n_sets;
770 int i; /*---- Misc counter(s) used for loops ----*/
771 int j; /*---- Misc counter(s) used for loops ----*/
772 int msgmax; /*---- The maximum number of _messages in a set ----*/
773 char *cmpct_set_ptr; /*---- pointer into the index table ----*/
774 struct _catset cs; /*---- used to look at the sets in the table -*/
777 cmpct_set_ptr = base + sizeof(struct _header);
779 for (i = 0 ; i < n_sets ; i++) {
780 /* loop through each compacted set */
782 cs = *(struct _catset *)cmpct_set_ptr;
783 /* set the _catset ptr to the base of the current
786 cs._mp = (struct _msgptr *)(cmpct_set_ptr +
787 2 * sizeof(unsigned short));
788 /* set the ms array ptr to the base of
789 compacted array of _msgptr's */
791 cset = (catd->_sets_expanded) ?
792 &catd->_set[cs._setno] : &catd->_set[i];
795 * If there aren't many holes in the message numbers,
796 * fully expand the compacted message array from the
797 * catalog. Then in catgets(), we'll be able to use
798 * the message number to index directly into the
801 * If there are many holes, leave the message array
802 * compacted. In catgets(), we'll search through it
803 * for the requested message.
806 msgmax = cs._mp[cs._n_msgs - 1]._msgno;
807 num_holes = msgmax - cs._n_msgs;
808 if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) {
809 cset->_msgs_expanded = TRUE;
810 cset->_n_msgs = msgmax;
813 cset->_msgs_expanded = FALSE;
814 cset->_n_msgs = cs._n_msgs - 1;
817 cset->_mp = (struct _msgptr *) rmalloc((1 + cset->_n_msgs) *
818 sizeof(struct _msgptr));
819 if (cset->_mp == NULL)
822 cset->_msgtxt = (char **) rmalloc((1 + cset->_n_msgs) *
824 if (cset->_msgtxt == NULL)
827 if (cset->_msgs_expanded) {
828 for (j = 0 ; j < cs._n_msgs ; j++) {
829 cset->_mp[cs._mp[j]._msgno] = cs._mp[j];
833 for (j = 0 ; j < cs._n_msgs ; j++) {
834 cset->_mp[j] = cs._mp[j];
838 cset->_setno = cs._setno;
839 /* Superfluous but should have the correct data. Increment
840 the base of the set pointer. */
842 cmpct_set_ptr += 2 * sizeof(unsigned short) + cs._n_msgs *
843 sizeof(struct _msgptr);
854 * FUNCTION: Opens a catalog file, looking in the language path first (if
855 * there is no slash) and returns a pointer to the file stream.
857 * EXECUTION ENVIRONMENT:
859 * Opencatfile executes under a process.
861 * RETURNS: Returns a pointer to the file stream, and a NULL pointer on
865 static FILE *open1catfile(file)
868 extern char *getenv();
869 char fl[PATH_MAX]; /*---- place to hold full path ----*/
870 char *nlspath; /*---- pointer to the nlspath val ----*/
871 FILE *fp; /*---- file pointer ----*/
872 char cpth[PATH_MAX]; /*---- current value of nlspath ----*/
874 char *fulllang; /* %L language value */
875 char lang[PATH_MAX]; /* %l language value */
876 char *territory; /* %t language value */
877 char *codeset; /* %c language value */
878 char *ptr; /* for decompose of $LANG */
883 char outptr[PATH_MAX];
886 if (strchr(file,'/')) {
887 if ((fp = fopen(file,"r")))
888 { fcntl(fileno(fp),F_SETFD,1);
889 /* set the close-on-exec flag for
895 if (!(nlspath = getenv("NLSPATH")))
896 nlspath = PATH_FORMAT;
897 if (!(fulllang = getenv("LANG")))
898 fulllang = DEFAULT_LANG;
899 if (fulllang == DEFAULT_LANG)
900 nlspath = PATH_FORMAT; /* if fullang is C, use the
901 the default nlspath: */
904 ** LANG is a composite of three fields:
905 ** language_territory.codeset
906 ** and we're going to break it into those
910 strcpy(lang, fulllang);
915 ptr = strchr( lang, '_' );
919 ptr = strchr(territory, '.');
925 ptr = strchr( lang, '.' );
935 while (*np && *np != ':')
938 if (*np) /*---- iff on a colon then advance --*/
946 while (*ptr != '\0') {
947 while ((*ptr != '\0') && (*ptr != '%')
948 && (nchars < PATH_MAX)) {
949 *(optr++) = *(ptr++);
977 lenstr = strlen(str);
979 if (nchars < PATH_MAX) {
987 if (nchars >= PATH_MAX) {
993 strcpy(cpth, outptr);
995 else { /*---- iff leading | trailing |
996 adjacent colons ... --*/
1000 if (valid == 1 && (fp = fopen(cpth,"r")))
1001 { fcntl(fileno(fp),F_SETFD,1);
1002 /* set the close-on-exec flag for
1007 if (fp = fopen(file,"r"))
1008 { fcntl(fileno(fp),F_SETFD,1);
1009 /* set the close-on-exec flag for
1023 * NAME: cat_already_open
1025 * FUNCTION: Checkes to see if a specific cat has already been opened.
1027 * EXECUTION ENVIRONMENT:
1029 * Cat_already_open executes under a process.
1031 * RETURNS: Returns a pointer to the existing CATD if one exists, and
1032 * a NULL pointer if no CATD exists.
1035 static nl_catd cat_already_open(cat)
1037 /*---- name of the catalog to be opened ----*/
1040 int i; /*---- Misc counter(s) used for loops ----*/
1042 for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) {
1043 #ifndef AFS_OSF20_ENV
1044 if (!strcmp(cat,catsopen[i]->_name) && getpid()==catsopen[i]->_pid) {
1046 if (!strcmp(cat,catsopen[i]->_name)) {
1048 return(catsopen[i]);
1055 int catclose1(catd) /*---- the catd to be closed ----*/
1056 nl_catd catd; /*---- the catd to be closed ----*/
1062 if (catd == CATD_ERR)
1064 for (i=0; i< NL_MAXOPEN && catsopen[i]; i++) {
1065 #ifndef AFS_OSF20_ENV
1066 if (catd == catsopen[i] && getpid()==catsopen[i]->_pid)
1068 if (catd == catsopen[i])
1072 if (i == NL_MAXOPEN || catsopen[i] == NULL)
1074 if (catd->_fd == (FILE *)NULL)
1075 /*---- return if this is an extra open or
1076 a bad catalog discriptor ----*/
1078 if (cat_already_open(catd->_name)) {
1079 if (catd->_count == 1) {
1080 cat_hard_close(catd);
1081 return (0); /*--- the last legal clsoe ---*/
1083 else if (catd->_count > 1) {
1084 catd->_count = catd->_count - 1;
1085 return(0); /*--- a legal close ---*/
1088 return (-1); /*--- an extra illegal close ---*/
1095 static void cat_hard_close(catd)
1097 /*---- the catd to be closed ----*/
1100 int i; /*---- Misc counter(s) used for loops ----*/
1101 int j; /*---- Misc counter ----*/
1103 if (catd == CATD_ERR)
1106 /*______________________________________________________________________
1107 remove any entry for the catalog in the catsopen array
1108 ______________________________________________________________________*/
1110 for (i = 0 ; i < NL_MAXOPEN && catsopen[i] ; i++) {
1111 if (catd == catsopen[i]) {
1112 for (; i < NL_MAXOPEN-1; i++) {
1113 catsopen[i] = catsopen[i+1];
1114 catpid[i] = catpid[i+1];
1121 /*______________________________________________________________________
1122 close the cat and free up the memory
1123 ______________________________________________________________________*/
1124 if (catd->_mem == FALSE)
1126 for (i = 0 ; i <= catd->_n_sets ; i++) {
1127 if (catd->_set[i]._mp)
1128 free(catd->_set[i]._mp);
1129 /*---- free the _message pointer arrays ----*/
1131 if (catd->_set[i]._msgtxt) {
1132 for (j = 0 ; j <= catd->_set[i]._n_msgs ; j++) {
1133 if (catd->_set[i]._msgtxt[j]) {
1134 /* free(catd->_set[i]._msgtxt[j]);*/
1137 if (catd->_set[i]._msgtxt)
1138 free(catd->_set[i]._msgtxt);
1144 fclose(catd->_fd); /*---- close the ctatlog ----*/
1146 free(catd->_set); /*---- free the sets ----*/
1148 free(catd->_name); /*---- free the name ----*/
1150 free(catd->_hd); /*---- free the header ----*/
1152 free(catd); /*---- free the catd ----*/
1155 static char *_do1_read_msg(nl_catd catd,int setno,int msgno)
1157 /*---- catd: the catd of the catalog to be read from ----*/
1158 /*---- setno: the set number of the message ----*/
1159 /*---- msgno: the msgno of the message ----*/
1162 nl_catd catd1; /*--- catd for different process ----*/
1165 #ifndef AFS_OSF20_ENV
1166 if (getpid() == catd->_pid)
1170 return (_read1_msg (catd, setno, msgno));
1173 * Since our pid is different from the one in
1174 * catd, catd must have come from a catopen()
1175 * in our parent. We need a catd of our own.
1176 * The first time through here, the call to
1177 * catopen() creates a new catd and we try to
1178 * open its message catalog. After that, the
1179 * catopen() just retrieves the catd.
1181 if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR) &&
1182 ((catd1->_fd == NL_FILE_CLOSED &&
1183 _do1_open(catd1) != CATD_ERR) ||
1184 (catd1->_fd != NL_FILE_UNUSED)))
1185 return (_read1_msg(catd1,setno,msgno));
1192 struct _catset *_cat1_get_catset();
1193 static struct _msgptr *_cat1_get_msgptr();
1194 static char *_read1_msg(nl_catd catd,int setno,int msgno)
1197 struct _catset *set; /*--- ptr to set's _catset structure ---*/
1198 struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/
1199 char **msgtxt; /*--- temporary pointer to the message text
1202 set = _cat1_get_catset(catd, setno);
1204 msg = _cat1_get_msgptr(set, msgno);
1206 msgtxt = &set->_msgtxt[msg - set->_mp];
1207 if (1/*!*msgtxt*/) {
1208 *msgtxt = (char *) malloc(msg->_msglen + 1);
1212 fseek(catd->_fd, (long) msg->_offset, 0);
1213 if (fread((void *) *msgtxt,
1214 (size_t) (msg->_msglen + 1),
1215 (size_t) 1, catd->_fd) != 1)
1226 * NAME: compare_sets
1228 * FUNCTION: Compare function used by bsearch() in _cat_get_catset().
1231 * key - pointer to set number we're searching for
1232 * element - pointer to current _catset structure
1234 * RETURNS: Returns -1, 0, or 1, depending on whether the set number
1235 * is less than, equal to, or greater than the set number of
1236 * the _catset structure.
1241 compare_sets(const void *key, const void *element)
1243 int *setno = (int *) key;
1244 struct _catset *set = (struct _catset *) element;
1246 if (*setno < set->_setno)
1248 if (*setno > set->_setno)
1256 * NAME: _cat_get_catset
1258 * FUNCTION: Find a set in the catd->_set array. Assumes that the
1259 * sets in the array are sorted by increasing set number.
1262 * catd - catalog descripter obtained from catopen()
1263 * setno - message catalogue set number
1265 * RETURNS: Returns a pointer to the set on success.
1266 * On any error, returns NULL.
1270 struct _catset *_cat1_get_catset(nl_catd catd, int setno)
1272 struct _catset *set;
1274 if ((catd == (nl_catd) NULL) || (catd == CATD_ERR))
1275 return (struct _catset *) NULL;
1277 if (catd->_sets_expanded) {
1278 if ((setno < 0) || (setno > catd->_n_sets))
1279 return (struct _catset *) NULL;
1281 set = &catd->_set[setno];
1284 * Catch empty elements in the array. They aren't
1288 if (set->_mp == (struct _msgptr *) NULL)
1289 return (struct _catset *) NULL;
1292 set = (struct _catset *) bsearch((void *) &setno,
1293 catd->_set, catd->_n_sets + 1,
1294 sizeof(struct _catset),
1298 * Since the sets are compacted, there aren't any
1299 * empty elements in the array to check for.
1308 * NAME: compare_msgs
1310 * FUNCTION: Compare function used by bsearch() in _cat_get_msgptr().
1313 * key - pointer to message number we're searching for
1314 * element - pointer to current _msgptr structure
1316 * RETURNS: Returns -1, 0, or 1, depending on whether the message
1317 * number is less than, equal to, or greater than the message
1318 * number of the _msgptr structure.
1323 compare_msgs(const void *key, const void *element)
1325 int *msgno = (int *) key;
1326 struct _msgptr *msg = (struct _msgptr *) element;
1328 if (*msgno < msg->_msgno)
1330 if (*msgno > msg->_msgno)
1337 * NAME: _cat1_get_msgptr
1339 * FUNCTION: Find a message in a set's set->_mp array. Assumes that
1340 * the messages in the array are sorted by increasing
1344 * set - ptr to _catset structure
1345 * msgno - message catalogue message number
1347 * RETURNS: Returns a pointer to the message on success.
1348 * On any error, returns NULL.
1351 static struct _msgptr *_cat1_get_msgptr(struct _catset *set, int msgno)
1353 struct _msgptr *msg;
1355 if (set == (struct _catset *) NULL)
1356 return (struct _msgptr *) NULL;
1358 if (set->_mp == (struct _msgptr *) NULL) /* empty set */
1359 return (struct _msgptr *) NULL;
1361 if (set->_msgs_expanded) {
1362 if ((msgno < 0) || (msgno > set->_n_msgs))
1363 return (struct _msgptr *) NULL;
1365 msg = &set->_mp[msgno];
1368 * Catch empty elements in the array. They aren't
1373 return (struct _msgptr *) NULL;
1376 msg = (struct _msgptr *) bsearch((void *) &msgno,
1377 set->_mp, set->_n_msgs + 1,
1378 sizeof(struct _msgptr),
1382 * Since the messages are compacted, there aren't any
1383 * empty elements in the array to check for.
1390 char *catgets1(nl_catd catd,int setno,int msgno,char *def)
1391 /*---- catd: the catd to get the message from ----*/
1392 /*---- setno: the set number of the message ----*/
1393 /*---- msgno: the message number of the message ----*/
1394 /*---- def: the default string to be returned ----*/
1398 char *_do_read_msg();
1402 if (catd == NULL || catd == CATD_ERR ||
1403 catd->_magic != CAT_MAGIC || catd->_fd == NL_FILE_UNUSED) {
1406 if (catd->_fd == NL_FILE_CLOSED) {
1407 catd = _do1_open(catd);
1408 if (catd == CATD_ERR)
1412 if (catd->_mem) { /*---- for mapped files ----*/
1413 if (setno <= catd->_hd->_setmax) {
1414 if (msgno < catd->_set[setno]._n_msgs) {
1415 if (catd->_set[setno]._mp[msgno]._offset) {
1417 catd->_set[setno]._mp[msgno]._offset);
1423 else { /*---- for unmapped files ----*/
1424 m = _do1_read_msg(catd,setno,msgno);
1434 #define FACILITY_CODE_MASK 0xF0000000
1435 #define FACILITY_CODE_SHIFT 28
1437 #define COMPONENT_CODE_MASK 0x0FFFF000
1438 #define COMPONENT_CODE_SHIFT 12
1440 #define STATUS_CODE_MASK 0x00000FFF
1441 #define STATUS_CODE_SHIFT 0
1443 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
1446 * The system-dependant location for the catalog files is defined in sysconf.h
1447 * RPC_DEFAULT_NLSPATH should be defined in sysconf.h. Otherwise we use
1448 * /usr/afs/etc/C/%s.cat
1451 #ifndef RPC_NLS_FORMAT
1452 #define RPC_NLS_FORMAT "%s.cat"
1455 dce1_error_inq_text (status_to_convert, error_text, status)
1456 afs_uint32 status_to_convert;
1457 unsigned char *error_text;
1461 unsigned short facility_code;
1462 unsigned short component_code;
1463 unsigned short status_code;
1464 unsigned short i, failed=0;
1466 char component_name[4];
1467 char *facility_name;
1468 char filename_prefix[7];
1469 char nls_filename[11];
1470 char alt_filename[80];
1473 static char *facility_names[] = {
1479 * set up output status for future error returns
1486 * check for ok input status
1488 if (status_to_convert == 0)
1494 strcpy ((char *)error_text, "successful completion");
1499 * extract the component, facility and status codes
1501 facility_code = (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
1502 component_code = (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
1503 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
1506 * see if this is a recognized facility
1508 if (facility_code == 0 || facility_code > sizeof (facility_names) / sizeof (char *))
1510 sprintf ((char *) error_text, "status %08x (unknown facility)", status_to_convert);
1513 facility_name = facility_names[facility_code - 1];
1515 * Convert component name from RAD-50 component code. (Mapping is:
1516 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
1518 component_name[3] = 0;
1519 component_name[2] = component_code % 40;
1520 component_code /= 40;
1521 component_name[1] = component_code % 40;
1522 component_name[0] = component_code / 40;
1523 for (i = 0; i < 3; i++)
1525 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
1527 sprintf (filename_prefix, "%3s%3s", facility_name, component_name);
1528 sprintf (nls_filename, RPC_NLS_FORMAT, filename_prefix);
1531 * Open the message file
1533 #if defined(AFS_OSF_ENV)
1534 #if defined(AFS_OSF20_ENV)
1535 catd = (nl_catd) catopen (nls_filename, 0);
1537 catd = (nl_catd) catopen1 (nls_filename, 0);
1540 J = (int) catopen (nls_filename, 0);
1543 if (catd == (nl_catd) -1)
1546 * If we did not succeed in opening message file using NLSPATH,
1547 * try to open the message file in a well-known default area
1550 #ifndef RPC_DEFAULT_NLSPATH
1551 sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH, filename_prefix);
1553 sprintf (alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix);
1556 #if defined(AFS_OSF_ENV)
1557 #if defined(AFS_OSF20_ENV)
1558 catd = (nl_catd) catopen (alt_filename, 0);
1560 catd = (nl_catd) catopen1 (alt_filename, 0);
1563 J = (int) catopen (alt_filename, 0);
1566 if (catd == (nl_catd) -1)
1568 sprintf ((char *) error_text, "status %08x (%s / %s)",
1569 status_to_convert, facility_name, component_name);
1574 * try to get the specified message from the file
1576 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1577 message = (char *) catgets1 (catd, 1, status_code, NO_MESSAGE);
1579 message = (char *) catgets (catd, 1, status_code, NO_MESSAGE);
1582 * if everything went well, return the resulting message
1584 if (strcmp (message, NO_MESSAGE) != 0)
1586 sprintf ((char *) error_text, "%s (%s / %s)",
1587 message, facility_name, component_name);
1599 sprintf ((char *) error_text, "status %08x (%s / %s)",
1600 status_to_convert, facility_name, component_name);
1602 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1611 icl_DumpKernel(outFilep, setname)
1615 afs_int32 bufferSize = 0;
1618 afs_int32 code, retVal = 0;
1623 afs_int32 dummy, dummy2;
1624 struct logInfo *lip;
1626 /* first, enumerate the logs we're interested in */
1630 /* dump logs for a particular set */
1631 for(i=0; i < ICL_LOGSPERSET; i++) {
1632 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET,
1633 (long) setname, i, (long) tname, sizeof(tname));
1635 if (errno == EBADF) {
1637 continue; /* missing slot, nothing to worry about */
1641 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
1642 (long) tname, (long) &dummy, (long) &dummy2, 0);
1646 if (dummy > bufferSize) /* find biggest log */
1648 lip = (struct logInfo *) malloc(sizeof(struct logInfo));
1649 memset((char *)lip, 0, sizeof(*lip));
1650 lip->nextp = allInfo;
1652 lip->name = (char *) malloc(strlen(tname)+1);
1653 strcpy(lip->name, tname);
1660 for(i=0;i<1000;i++) {
1661 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS,
1662 i, (long) tname, sizeof(tname), (long) &dummy);
1664 if (dummy > bufferSize) /* find biggest log */
1666 lip = (struct logInfo *) malloc(sizeof(struct logInfo));
1667 memset((char *)lip, 0, sizeof(*lip));
1668 lip->nextp = allInfo;
1670 lip->name = (char *) malloc(strlen(tname)+1);
1671 strcpy(lip->name, tname);
1675 if (bufferSize == 0) return -1;
1676 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1677 if (!bufferp) return -1;
1679 fprintf(outFilep, "Found %d logs.\n", i);
1681 /* now print out the contents of each log */
1682 for(lip = allInfo; lip; lip=lip->nextp) {
1683 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
1684 /* read out everything first; gets a more consistent
1687 nwords = 0; /* total words copied out */
1689 /* display all the entries in the log */
1690 if (bufferSize - nwords <= 0) break; /* filled whole buffer */
1691 code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT,
1692 (long) lip->name, (long) (bufferp+nwords),
1693 bufferSize - nwords, (long) &i);
1695 /* otherwise we've got an error */
1696 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
1699 /* otherwise, we have flags in the high order byte, and
1700 * a length (in words) in the remainder.
1702 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
1703 fprintf(outFilep, "Log wrapped; data missing.\n");
1711 } /* for loop over all cookies */
1713 /* otherwise we should display all of the log entries here.
1714 * Note that a record may end in the middle, in which case
1715 * we should start over with the cookie value of the start
1718 for(ix = 0; ix<nwords;) {
1719 /* start of a record */
1720 rlength = (bufferp[ix] >> 24) & 0xff;
1722 fprintf(outFilep, "Internal error: 0 length record\n");
1726 /* ensure that entire record fits */
1727 if (ix+rlength > nwords) {
1728 /* doesn't fit, adjust cookie and break */
1731 /* print the record */
1732 DisplayRecord(outFilep, &bufferp[ix], rlength);
1735 /* obsolete: read entire buffer first */
1736 i += rlength; /* update cookie value, too */
1738 } /* for loop displaying buffer */
1739 } /* for loop over all logs */
1746 /* clear out log 'name' */
1752 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0);
1756 /* clear out set 'name' */
1762 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long) name, 0, 0, 0);
1766 /* clear out all logs */
1771 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0);
1775 /* list out all available sets to outFileP */
1776 int icl_ListSets(outFileP)
1784 for(i=0;i<1000;i++) {
1785 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS,
1786 i, (long) tname, sizeof(tname), (long) &states);
1788 (void) fprintf(outFileP, "%s %s%s%s\n", tname,
1789 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
1790 (states & ICL_SETF_FREED) ? " (dormant)" : "",
1791 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
1797 /* list out all available logs to outFileP */
1798 int icl_ListLogs(outFileP, int32flg)
1808 for(i=0;i<1000;i++) {
1809 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS,
1810 i, (long) tname, sizeof(tname), (long) &logSize);
1814 /* get more information on the log */
1815 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname,
1816 (long) &logSize, (long) &allocated, 0);
1819 (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024,
1820 allocated ? "allocated" : "unallocated");
1823 (void) fprintf(outFileP, "%s\n", tname);
1829 /* list out all available logs to outFileP */
1830 int icl_ListLogsBySet(outFileP, setname, int32flg)
1841 for(i=0; i < ICL_LOGSPERSET; i++) {
1842 code = afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET,
1843 (long) setname, i, (long) tname, sizeof(tname));
1845 if (errno == EBADF) {
1847 continue; /* missing */
1853 /* get more information on the log */
1854 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) tname,
1855 (long) &logSize, (long) &allocated, 0);
1858 (void) fprintf(outFileP, "%s : %d kbytes (%s)\n", tname, logSize/1024,
1859 allocated ? "allocated" : "unallocated");
1862 (void) fprintf(outFileP, "%s\n", tname);
1868 /* activate/deactivate/free specified set */
1869 int icl_ChangeSetState(name, op)
1875 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long) name, op, 0, 0);
1879 /* activate/deactivate/free all sets */
1880 int icl_ChangeAllSetState(op)
1885 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0);
1889 /* set size if log */
1890 int icl_ChangeLogSize(name, logSize)
1896 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0, 0);
1900 /* get logsize of specified log */
1901 int icl_GetLogsize(logname, logSizeP, allocatedP)
1903 afs_int32 *logSizeP;
1907 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long) logname,
1908 (long) logSizeP, (long) allocatedP, 0);
1912 /* get state of specified set */
1913 int icl_GetSetState(setname, stateP)
1918 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long) setname,
1919 (long) stateP, 0, 0);
1923 icl_TailKernel(outFilep, logname, waitTime)
1928 afs_int32 bufferSize = 0;
1929 afs_int32 newBufferSize;
1932 afs_int32 code, retVal = 0;
1937 struct logInfo *lip;
1939 /* get information about the specified log */
1940 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
1941 (long) logname, (long) &bufferSize, (long) &allocated, 0);
1944 if (errno == ENOENT)
1945 (void) fprintf(stderr, "'%s' not found\n", logname);
1947 (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n",
1954 (void) fprintf(stderr, "'%s' not allocated\n", logname);
1958 if (bufferSize == 0) return -1;
1959 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1962 (void) fprintf(stderr, "cannot allocate %d words for buffer\n",
1967 /* start "infinite" loop */
1970 /* read out all that's currently there */
1971 nwords = 0; /* total words copied out */
1972 i = 0; /* initialize cookie */
1974 /* display all the entries in the log */
1975 if (bufferSize - nwords <= 0)
1976 break; /* filled whole buffer, clear when done */
1977 code = afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR,
1978 (long) logname, (long) (bufferp+nwords),
1979 bufferSize - nwords, (long) &i);
1981 /* otherwise we've got an error */
1982 fprintf(stderr, "returned error %d dumping log.\n", errno);
1986 /* otherwise, we have flags in the high order byte, and
1987 * a length (in words) in the remainder.
1996 } /* for loop over all cookies */
1998 /* otherwise we should display all of the log entries here.
1999 * Note that a record may end in the middle, in which case
2000 * we should start over with the cookie value of the start
2003 for(ix = 0; ix<nwords;) {
2004 /* start of a record */
2005 rlength = (bufferp[ix] >> 24) & 0xff;
2006 /* ensure that entire record fits */
2007 if (ix+rlength > nwords) {
2008 /* doesn't fit, adjust cookie and break */
2010 fprintf(stderr, "BOGUS: 0 length record\n");
2016 /* print the record */
2017 DisplayRecord(outFilep, &bufferp[ix], rlength);
2019 } /* for loop displaying buffer */
2024 /* see if things have changed */
2025 code = afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO,
2026 (long) logname, (long) &newBufferSize,
2027 (long) &allocated, 0);
2030 if (errno == ENOENT)
2031 (void) fprintf(stderr, "'%s' not found\n", logname);
2033 (void) fprintf(stderr, "cannot get information on log '%s' (errno = %d)\n",
2041 (void) fprintf(stderr, "'%s' no int32er allocated\n", logname);
2046 if (bufferSize == 0)
2048 (void) fprintf(stderr, "buffer size has become 0\n");
2052 if (bufferSize != newBufferSize)
2054 /* have to reallocate a buffer */
2055 bufferSize = newBufferSize;
2057 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
2060 (void) fprintf(stderr, "cannot allocate %d words for buffer\n",
2066 } /* infinite loop */
2073 #if !defined(AFS_SGI_ENV)
2074 afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
2075 long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6;
2078 #ifdef AFS_LINUX20_ENV
2079 #if defined AFS_LINUX_64BIT_KERNEL
2081 /* don't want to sign extend it to 64bit, so using ulong */
2082 eparm[0] = (unsigned long)parm3;
2083 eparm[1] = (unsigned long)parm4;
2084 eparm[2] = (unsigned long)parm5;
2085 eparm[3] = (unsigned long)parm6;
2093 /* Linux can only handle 5 arguments in the actual syscall. */
2094 if (call == AFSCALL_ICL) {
2095 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
2098 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
2100 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
2101 /* on sparc this function returns none value, so do it myself */
2102 __asm__ __volatile__ ("
2109 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2110 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
2112 #if defined(AFS_SGI_ENV)
2113 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
2115 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
2119 #endif /* AFS_LINUX20_ENV */
2126 /* init function, called once, under icl_lock */
2132 /* setup signal handler, in user space */
2138 icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2140 struct afs_icl_log *baseLogp;
2141 struct afs_icl_log *fatalLogp;
2142 struct afs_icl_set **outSetpp;
2144 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags*/0, outSetpp);
2147 /* create a set, given pointers to base and fatal logs, if any.
2148 * Logs are unlocked, but referenced, and *outSetpp is returned
2149 * referenced. Function bumps reference count on logs, since it
2150 * addds references from the new icl_set. When the set is destroyed,
2151 * those references will be released.
2153 icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2155 struct afs_icl_log *baseLogp;
2156 struct afs_icl_log *fatalLogp;
2158 struct afs_icl_set **outSetpp;
2160 register struct afs_icl_set *setp;
2162 afs_int32 states = ICL_DEFAULT_SET_STATES;
2164 if (!icl_inited) icl_Init();
2166 for (setp = icl_allSets; setp; setp = setp->nextp) {
2167 if (strcmp(setp->name, name) == 0) {
2170 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2172 setp->states |= ICL_SETF_PERSISTENT;
2178 /* determine initial state */
2179 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2180 states = ICL_SETF_ACTIVE;
2181 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2182 states = ICL_SETF_FREED;
2183 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2184 states |= ICL_SETF_PERSISTENT;
2186 setp = (struct afs_icl_set *) osi_Alloc(sizeof(struct afs_icl_set));
2187 memset((caddr_t)setp, 0, sizeof(*setp));
2189 if (states & ICL_SETF_FREED)
2190 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2191 setp->states = states;
2193 setp->name = (char *)osi_Alloc(strlen(name)+1);
2194 strcpy(setp->name, name);
2195 setp->nevents = ICL_DEFAULTEVENTS;
2196 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
2197 for(i=0; i<ICL_DEFAULTEVENTS; i++)
2198 setp->eventFlags[i] = 0xff; /* default to enabled */
2200 /* update this global info under the icl_lock */
2201 setp->nextp = icl_allSets;
2204 /* set's basic lock is still held, so we can finish init */
2206 setp->logs[0] = baseLogp;
2207 icl_LogHold(baseLogp);
2208 if (!(setp->states & ICL_SETF_FREED))
2209 icl_LogUse(baseLogp); /* log is actually being used */
2212 setp->logs[1] = fatalLogp;
2213 icl_LogHold(fatalLogp);
2214 if (!(setp->states & ICL_SETF_FREED))
2215 icl_LogUse(fatalLogp); /* log is actually being used */
2222 /* function to change event enabling information for a particular set */
2223 icl_SetEnable(setp, eventID, setValue)
2224 struct afs_icl_set *setp;
2230 if (!ICL_EVENTOK(setp, eventID)) {
2233 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2235 *tp |= ICL_EVENTMASK(eventID);
2237 *tp &= ~(ICL_EVENTMASK(eventID));
2241 /* return indication of whether a particular event ID is enabled
2242 * for tracing. If *getValuep is set to 0, the event is disabled,
2243 * otherwise it is enabled. All events start out enabled by default.
2245 icl_GetEnable(setp, eventID, getValuep)
2246 struct afs_icl_set *setp;
2250 if (!ICL_EVENTOK(setp, eventID)) {
2253 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2260 /* hold and release event sets */
2262 register struct afs_icl_set *setp;
2268 /* free a set. Called with icl_lock locked */
2270 register struct afs_icl_set *setp;
2272 register struct afs_icl_set **lpp, *tp;
2274 register struct afs_icl_log *tlp;
2276 for(lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2278 /* found the dude we want to remove */
2280 osi_Free(setp->name, 1+strlen(setp->name));
2281 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
2282 for(i=0; i < ICL_LOGSPERSET; i++) {
2283 if (tlp = setp->logs[i])
2286 osi_Free(setp, sizeof(struct afs_icl_set));
2287 break; /* won't find it twice */
2293 /* do the release, watching for deleted entries */
2295 register struct afs_icl_set *setp;
2297 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2298 icl_ZapSet(setp); /* destroys setp's lock! */
2303 /* free a set entry, dropping its reference count */
2305 register struct afs_icl_set *setp;
2307 setp->states |= ICL_SETF_DELETED;
2312 /* find a set by name, returning it held */
2313 struct afs_icl_set *icl_FindSet(name)
2316 register struct afs_icl_set *tp;
2318 for(tp = icl_allSets; tp; tp=tp->nextp) {
2319 if (strcmp(tp->name, name) == 0) {
2320 /* this is the dude we want */
2328 /* zero out all the logs in the set */
2330 struct afs_icl_set *setp;
2335 struct afs_icl_log *logp;
2337 for(i = 0; i < ICL_LOGSPERSET; i++) {
2338 logp = setp->logs[i];
2341 tcode = icl_ZeroLog(logp);
2342 if (tcode != 0) code = tcode; /* save the last bad one */
2349 icl_EnumerateSets(aproc, arock)
2353 register struct afs_icl_set *tp, *np;
2354 register afs_int32 code;
2357 for(tp = icl_allSets; tp; tp=np) {
2358 tp->refCount++; /* hold this guy */
2359 code = (*aproc)(tp->name, arock, tp);
2360 np = tp->nextp; /* tp may disappear next, but not np */
2361 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2368 icl_AddLogToSet(setp, newlogp)
2369 struct afs_icl_set *setp;
2370 struct afs_icl_log *newlogp;
2374 struct afs_icl_log *logp;
2376 for(i = 0; i < ICL_LOGSPERSET; i++) {
2377 if (!setp->logs[i]) {
2378 setp->logs[i] = newlogp;
2380 icl_LogHold(newlogp);
2381 if (!(setp->states & ICL_SETF_FREED)) {
2382 /* bump up the number of sets using the log */
2383 icl_LogUse(newlogp);
2391 icl_SetSetStat(setp, op)
2392 struct afs_icl_set *setp;
2397 struct afs_icl_log *logp;
2400 case ICL_OP_SS_ACTIVATE: /* activate a log */
2402 * If we are not already active, see if we have released
2403 * our demand that the log be allocated (FREED set). If
2404 * we have, reassert our desire.
2406 if (!(setp->states & ICL_SETF_ACTIVE)) {
2407 if (setp->states & ICL_SETF_FREED) {
2408 /* have to reassert desire for logs */
2409 for(i = 0; i < ICL_LOGSPERSET; i++) {
2410 logp = setp->logs[i];
2417 setp->states &= ~ICL_SETF_FREED;
2419 setp->states |= ICL_SETF_ACTIVE;
2424 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2425 /* this doesn't require anything beyond clearing the ACTIVE flag */
2426 setp->states &= ~ICL_SETF_ACTIVE;
2430 case ICL_OP_SS_FREE: /* deassert design for log */
2432 * if we are already in this state, do nothing; otherwise
2433 * deassert desire for log
2435 if (setp->states & ICL_SETF_ACTIVE)
2438 if (!(setp->states & ICL_SETF_FREED)) {
2439 for(i = 0; i < ICL_LOGSPERSET; i++) {
2440 logp = setp->logs[i];
2443 icl_LogFreeUse(logp);
2447 setp->states |= ICL_SETF_FREED;
2460 struct afs_icl_log *afs_icl_allLogs = 0;
2462 /* hold and release logs */
2464 register struct afs_icl_log *logp;
2470 /* hold and release logs, called with lock already held */
2472 register struct afs_icl_log *logp;
2478 /* keep track of how many sets believe the log itself is allocated */
2480 register struct afs_icl_log *logp;
2482 if (logp->setCount == 0) {
2483 /* this is the first set actually using the log -- allocate it */
2484 if (logp->logSize == 0) {
2485 /* we weren't passed in a hint and it wasn't set */
2486 logp->logSize = ICL_DEFAULT_LOGSIZE;
2488 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
2494 /* decrement the number of real users of the log, free if possible */
2495 icl_LogFreeUse(logp)
2496 register struct afs_icl_log *logp;
2498 if (--logp->setCount == 0) {
2499 /* no more users -- free it (but keep log structure around)*/
2500 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2501 logp->firstUsed = logp->firstFree = 0;
2502 logp->logElements = 0;
2503 logp->datap = (afs_int32 *)0;
2508 /* set the size of the log to 'logSize' */
2509 icl_LogSetSize(logp, logSize)
2510 register struct afs_icl_log *logp;
2514 /* nothing to worry about since it's not allocated */
2515 logp->logSize = logSize;
2519 logp->firstUsed = logp->firstFree = 0;
2520 logp->logElements = 0;
2522 /* free and allocate a new one */
2523 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2524 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
2525 logp->logSize = logSize;
2531 /* free a log. Called with icl_lock locked. */
2533 register struct afs_icl_log *logp;
2535 register struct afs_icl_log **lpp, *tp;
2537 for(lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2539 /* found the dude we want to remove */
2541 osi_Free(logp->name, 1+strlen(logp->name));
2542 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
2543 osi_Free(logp, sizeof(struct icl_log));
2544 break; /* won't find it twice */
2550 /* do the release, watching for deleted entries */
2552 register struct afs_icl_log *logp;
2554 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2555 icl_ZapLog(logp); /* destroys logp's lock! */
2560 /* do the release, watching for deleted entries, log already held */
2562 register struct afs_icl_log *logp;
2564 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2565 icl_ZapLog(logp); /* destroys logp's lock! */
2570 /* zero out the log */
2572 register struct afs_icl_log *logp;
2574 logp->firstUsed = logp->firstFree = 0;
2575 logp->logElements = 0;
2579 /* free a log entry, and drop its reference count */
2581 register struct afs_icl_log *logp;
2583 logp->states |= ICL_LOGF_DELETED;
2589 icl_EnumerateLogs(aproc, arock)
2593 register struct afs_icl_log *tp;
2594 register afs_int32 code;
2597 for(tp = afs_icl_allLogs; tp; tp=tp->nextp) {
2598 tp->refCount++; /* hold this guy */
2599 code = (*aproc)(tp->name, arock, tp);
2600 if (--tp->refCount == 0)
2608 afs_icl_bulkSetinfo_t *GetBulkSetInfo()
2610 unsigned int infoSize;
2612 infoSize = sizeof(afs_icl_bulkSetinfo_t) +
2613 (ICL_RPC_MAX_SETS-1) * sizeof(afs_icl_setinfo_t);
2616 setInfo = (afs_icl_bulkSetinfo_t *)malloc(infoSize);
2619 (void) fprintf(stderr, "Could not allocate the memory for bulk set info structure\n");
2623 memset((char *)setInfo, 0, infoSize);
2628 afs_icl_bulkLoginfo_t *GetBulkLogInfo()
2629 { unsigned int infoSize;
2631 infoSize = sizeof(afs_icl_bulkLoginfo_t) +
2632 (ICL_RPC_MAX_LOGS-1) * sizeof(afs_icl_loginfo_t);
2635 logInfo = (afs_icl_bulkLoginfo_t *)malloc(infoSize);
2638 (void) fprintf(stderr, "Could not allocate the memory for bulk log info structure\n");
2643 memset((char *)logInfo, 0, infoSize);
2648 static DoDump(as, arock)
2649 register struct cmd_syndesc *as;
2654 afs_int32 waitTime = 10 /* seconds */;
2658 FILE *outfp = stdout;
2660 struct cmd_item * itemp;
2662 if (geteuid() != 0) {
2663 printf("fstrace must be run as root\n");
2667 if (as->parms[3].items) {
2668 if (!as->parms[1].items)
2670 (void) fprintf(stderr, "-sleep can only be used with -follow\n");
2673 waitTime = strtol(as->parms[3].items->data,
2677 if (as->parms[2].items)
2679 /* try to open the specified output file */
2680 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL)
2682 (void) fprintf(stderr, "Cannot open file '%s' for writing\n",
2683 as->parms[2].items->data);
2687 #ifdef AFS_SGI64_ENV
2688 startTime = time((time_t *) 0);
2690 startTime = time(0);
2692 (void) fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
2695 if (as->parms[0].items)
2697 for (itemp = as->parms[0].items; itemp; itemp = itemp->next)
2699 tcode = icl_DumpKernel(outfp, itemp->data);
2702 (void) fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
2703 itemp->data, errno);
2707 } else if (as->parms[1].items) {
2708 logname = as->parms[1].items->data;
2709 code = icl_TailKernel(outfp, logname, waitTime);
2711 (void) fprintf(stderr, "Error tailing kernel log '%s' (errno = %d)\n",
2715 code = icl_DumpKernel(outfp, NULL);
2717 (void) fprintf(outfp, "\nAFS Trace Dump - %s\n",
2718 code ? "FAILED" : "Completed");
2720 if (outfp != stdout)
2721 (void) fclose(outfp);
2726 static void SetUpDump()
2728 struct cmd_syndesc *dumpSyntax;
2730 dumpSyntax = cmd_CreateSyntax("dump", DoDump, (char *)NULL, "dump AFS trace logs");
2731 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2732 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL, "log_name");
2733 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL, "output_filename");
2734 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL, "seconds_between_reads");
2737 static DoShowLog(as, arock)
2738 register struct cmd_syndesc *as;
2741 afs_int32 retVal = 0;
2746 struct cmd_item * itemp;
2748 if (geteuid() != 0) {
2749 printf("fstrace must be run as root\n");
2752 if (as->parms[2].items) int32flg = 1;
2754 if (as->parms[0].items) {
2755 /* enumerate logs for the specified sets */
2756 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2757 (void) fprintf(stdout, "Logs for set '%s':\n", itemp->data);
2758 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
2760 (void) fprintf(stderr, "Error in enumerating set %s (errno = %d)\n",
2761 itemp->data, errno);
2766 else if (as->parms[1].items) {
2767 /* print out log information */
2768 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
2769 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
2771 (void) fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
2772 logSize/1024, allocated ? "allocated" : "unallocated");
2774 (void) fprintf(stderr, "Could not find log '%s' (errno = %d)\n",
2775 itemp->data, errno);
2782 (void) fprintf(stdout, "Available logs:\n");
2783 code = icl_ListLogs(stdout, int32flg);
2785 (void) fprintf(stderr, "Error in listing logs (errno = %d)\n", errno);
2793 static void SetUpShowLog()
2795 struct cmd_syndesc *showSyntax;
2797 showSyntax = cmd_CreateSyntax("lslog", DoShowLog, (char *)NULL,"list available logs");
2798 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2799 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name");
2800 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL,"");
2803 static DoShowSet(as, arock)
2804 register struct cmd_syndesc *as;
2807 afs_int32 retVal = 0;
2810 struct cmd_item * itemp;
2812 if (geteuid() != 0) {
2813 printf("fstrace must be run as root\n");
2816 if (as->parms[0].items) {
2817 /* print information on the specified sets */
2818 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2819 code = icl_GetSetState(itemp->data, &state);
2821 (void) fprintf(stderr, "Error getting status on set %s (errno = %d)\n",
2822 itemp->data, errno);
2826 (void) fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
2827 (state & ICL_SETF_ACTIVE) ? "active" : "inactive",
2828 (state & ICL_SETF_FREED) ? " (dormant)" : "",
2829 (state & ICL_SETF_PERSISTENT) ? " persistent" : "");
2834 (void) fprintf(stdout, "Available sets:\n");
2835 code = icl_ListSets(stdout);
2837 (void) fprintf(stderr, "Error in listing sets (errno = %d)\n", errno);
2845 static void SetUpShowSet()
2847 struct cmd_syndesc *showSyntax;
2849 showSyntax = cmd_CreateSyntax("lsset", DoShowSet, (char *)NULL, "list available event sets");
2850 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2853 static DoClear(as, arock)
2854 register struct cmd_syndesc *as;
2857 afs_int32 retVal = 0;
2859 struct cmd_item * itemp;
2861 if (geteuid() != 0) {
2862 printf("fstrace must be run as root\n");
2865 if (as->parms[0].items) {
2866 /* clear logs for the specified sets */
2867 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2868 code = icl_ClearSet(itemp->data);
2870 (void) fprintf(stderr, "Error in clearing set %s (errno = %d)\n",
2871 itemp->data, errno);
2875 } else if (as->parms[1].items) {
2876 /* clear specified log */
2877 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2878 code = icl_ClearLog(itemp->data);
2880 (void) fprintf(stderr, "Error in clearing log %s (errno = %d)\n",
2881 itemp->data, errno);
2887 /* clear all logs */
2888 code = icl_ClearAll();
2890 (void) fprintf(stderr, "Error in clearing logs (errno = %d)\n", errno);
2898 static void SetUpClear()
2900 struct cmd_syndesc *clearSyntax;
2902 clearSyntax = cmd_CreateSyntax("clear", DoClear, (char *)NULL, "clear logs by logname or by event set");
2903 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2904 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
2907 static DoSet(as, arock)
2908 register struct cmd_syndesc *as;
2911 afs_int32 retVal = 0;
2916 struct cmd_item * itemp;
2918 if (geteuid() != 0) {
2919 printf("fstrace must be run as root\n");
2922 if (as->parms[1].items) {
2923 op = ICL_OP_SS_ACTIVATE;
2924 operation = "active";
2925 } else if (as->parms[2].items) {
2926 op = ICL_OP_SS_DEACTIVATE;
2927 operation = "inactive";
2928 } else if (as->parms[3].items) {
2929 op = ICL_OP_SS_DEACTIVATE;
2930 operation = "inactive";
2933 /* assume active" */
2934 op = ICL_OP_SS_ACTIVATE;
2935 operation = "active";
2938 if (as->parms[0].items) {
2939 /* activate specified sets */
2940 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2941 code = icl_ChangeSetState(itemp->data, op);
2943 (void) fprintf(stderr, "cannot set state of %s to %s (errno = %d)\n",
2944 itemp->data, operation, errno);
2948 /* try to make it dormant as well */
2949 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2951 (void) fprintf(stderr, "cannot set state of %s to dormant (errno = %d)\n",
2952 itemp->data, errno);
2960 code = icl_ChangeAllSetState(op);
2962 (void) fprintf(stderr, "cannot set the state of all sets to %s (errno = %d)\n",
2967 /* try to make it dormant as well */
2968 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2970 (void) fprintf(stderr, "cannot set the state of all sets to dormant (errno = %d)\n", errno);
2979 static void SetUpSet()
2981 struct cmd_syndesc *setSyntax;
2983 setSyntax = cmd_CreateSyntax("setset", DoSet, (char *)NULL,"set state of event sets");
2984 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL,"set_name");
2985 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL,"");
2986 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
2987 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL,"");
2990 static DoResize(as, arock)
2991 register struct cmd_syndesc *as;
2994 afs_int32 retVal = 0;
2996 afs_int32 bufferSize;
2997 struct cmd_item * itemp;
2999 if (geteuid() != 0) {
3000 printf("fstrace must be run as root\n");
3003 /* get buffer size */
3004 bufferSize = atoi(as->parms[1].items->data);
3005 bufferSize *= BUFFER_MULTIPLIER;
3006 if (bufferSize == 0)
3007 bufferSize = ICL_DEFAULT_LOGSIZE;
3009 /* set the size of the specified logs */
3010 if (itemp = as->parms[0].items) {
3011 for (; itemp; itemp = itemp->next) {
3012 code = icl_ChangeLogSize(itemp->data, bufferSize);
3014 (void) fprintf(stderr, "Error in changing log %s buffer size (errno = %d)\n",
3015 itemp->data, errno);
3020 /* Use the only current support log, "cmfx" */
3021 code = icl_ChangeLogSize("cmfx", bufferSize);
3023 (void) fprintf(stderr, "Error in changing log cmfx buffer size (errno = %d)\n", errno);
3031 static void SetUpResize()
3033 struct cmd_syndesc *setsizeSyntax;
3035 setsizeSyntax = cmd_CreateSyntax("setlog", DoResize, (char *)NULL, "set the size of a log");
3036 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,"log_name");
3037 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED, "1-kilobyte_units");
3040 #include "AFS_component_version_number.c"
3046 setlocale(LC_ALL, "");
3047 #ifdef AFS_SGI62_ENV
3048 set_kernel_sizeof_long();
3051 /* set up user interface then dispatch */
3059 return(cmd_Dispatch(argc, argv));
3062 #include "AFS_component_version_number.c"
3065 printf("fstrace is NOT supported for this OS\n");