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>
20 #include <sys/types.h>
21 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43)
23 /*#ifdef AFS_AIX_ENV*/
40 #include <afs/afs_args.h>
42 #include <afs/afsutil.h>
44 #if defined(AFS_ALPHA_ENV) || defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
45 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
46 int afs_icl_sizeofLong = 2;
48 int afs_icl_sizeofLong = 1;
51 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
52 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
53 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
57 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
59 set_kernel_sizeof_long(void)
64 retval = sysconf(_SC_KERN_POINTERS);
67 afs_icl_sizeofLong = 2;
70 afs_icl_sizeofLong = 1;
74 #endif /* AFS_SGI62_ENV */
75 #endif /* AFS_SGI61_ENV */
77 #define BUFFER_MULTIPLIER 1024
79 /* make it big enough to snapshot everything at once, since
80 * decoding takes so long.
82 #define IBSIZE 100000 /* default size */
85 struct logInfo *nextp;
89 char dumpFileName[256] = "";
90 RegisterIclDumpFileName(name)
93 (void)sprintf(dumpFileName, "icl.%.250s", name);
96 /* define globals to use for bulk info */
97 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0;
98 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0;
100 struct afs_icl_set *icl_allSets = 0;
104 /* given a type and an address, get the size of the thing
108 icl_GetSize(type, addr)
116 ICL_SIZEHACK(type, addr);
120 /* Check types in printf string "bufferp", making sure that each
121 * is compatible with the corresponding parameter type described
122 * by typesp. Also watch for prematurely running out of parameters
123 * before the string is gone.
125 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
127 CheckTypes(bufferp, typesp, typeCount, outMsgBuffer)
139 for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
142 /* hit end of string. We win as long as we aren't
151 inPercent = 1 - inPercent;
155 if (tc >= '0' && tc <= '9') {
156 /* skip digits in % string */
161 /* 'l' is a type modifier. */
165 /* otherwise, we've finally gotten to the type-describing
166 * character. Make sure there's a type descriptor, and then
167 * check the type descriptor.
171 return 0; /* no more type descriptors left */
173 if (typesp[tix] != 1) /* not a string descriptor */
176 *outMsgBuffer = (char)1;
178 if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') {
179 if (typesp[tix] != 0)
180 return 0; /* not an integer descriptor */
184 *outMsgBuffer = (char)2;
187 *outMsgBuffer = (char)3;
190 *outMsgBuffer = (char)4;
194 *outMsgBuffer = (char)5;
198 /* otherwise we're fine, so eat this descriptor */
204 #else /* AFS_SGI61_ENV */
206 CheckTypes(bufferp, typesp, typeCount)
217 for (tc = *bufferp;; tc = *(++bufferp)) {
219 /* hit end of string. We win as long as we aren't
228 inPercent = 1 - inPercent;
232 if (tc >= '0' && tc <= '9')
233 continue; /* skip digits in % string */
234 /* otherwise, we've finally gotten to the type-describing
235 * character. Make sure there's a type descriptor, and then
236 * check the type descriptor.
240 return 0; /* no more type descriptors left */
241 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
243 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
244 && (typesp[tix] != 0))
245 return 0; /* not an integer descriptor */
246 /* otherwise we're fine, so eat this descriptor */
252 #endif /* AFS_SGI61_ENV */
254 /* display a single record.
255 * alp points at the first word in the array to be interpreted
256 * rsize gives the # of words in the array
258 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
259 #define uint64_t long long
262 DisplayRecord(outFilep, alp, rsize)
264 register afs_int32 *alp;
267 char msgBuffer[1024];
268 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
269 char outMsgBuffer[1024];
271 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
272 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
273 #else /* AFS_SGI61_ENV */
274 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
275 #endif /* AFS_SGI61_ENV */
276 int printfTypes[ICL_MAXEXPANSION * 4];
282 int pix; /* index in alp */
283 int pfpix; /* index in printfParms */
284 int pftix; /* index in printfTypes */
286 int printed; /* did we print the string yet? */
289 /* decode parameters */
290 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
296 for (i = 0; i < 4 * ICL_MAXEXPANSION; i++)
298 /* decode each parameter, getting addrs for afs_hyper_t and strings */
299 for (i = 0; !done && i < 4; i++) {
300 type = (temp >> (18 - i * 6)) & 0x3f;
306 case ICL_TYPE_POINTER:
307 printfTypes[pftix++] = 0;
308 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
309 printfParms[pfpix] = alp[pix];
310 printfParms[pfpix] &= 0xffffffff;
311 if (afs_64bit_kernel) {
312 printfParms[pfpix] <<= 32;
313 printfParms[pfpix] |= alp[pix + 1];
315 #else /* AFS_SGI61_ENV */
317 printfParms[pfpix] = alp[pix + 1];
318 printfParms[pfpix] |= (alp[pix] <<= 32);
319 #else /* AFS_ALPHA_ENV */
320 printfParms[pfpix] = alp[pix];
321 #endif /* AFS_ALPHA_ENV */
322 #endif /* AFS_SGI61_ENV */
326 printfTypes[pftix++] = 0;
327 printfParms[pfpix++] = alp[pix];
331 printfTypes[pftix++] = 0;
332 printfParms[pfpix++] = alp[pix];
333 printfTypes[pftix++] = 0;
334 printfParms[pfpix++] = alp[pix + 1];
337 printfTypes[pftix++] = 0;
338 printfParms[pfpix++] = alp[pix];
339 printfTypes[pftix++] = 0;
340 printfParms[pfpix++] = alp[pix + 1];
341 printfTypes[pftix++] = 0;
342 printfParms[pfpix++] = alp[pix + 2];
343 printfTypes[pftix++] = 0;
344 printfParms[pfpix++] = alp[pix + 3];
346 case ICL_TYPE_STRING:
347 printfTypes[pftix++] = 1;
349 printfStrings[pfpix++] = (char *)&alp[pix];
350 #else /* AFS_SGI64_ENV */
351 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
352 printfStrings[pfpix++] = (char *)&alp[pix];
353 #else /* AFS_SGI61_ENV */
354 printfParms[pfpix++] = (long)&alp[pix];
355 #endif /* AFS_SGI61_ENV */
356 #endif /* AFS_SGI64_ENV */
358 case ICL_TYPE_UNIXDATE:
359 printfParms[pfpix++] = (long)ctime((time_t *) & alp[pix]);
362 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
369 pix += icl_GetSize(type, (char *)&alp[pix]);
372 /* next, try to decode the opcode into a printf string */
373 dce1_error_inq_text(alp[1], msgBuffer, &status);
375 /* if we got a string back, and it is compatible with the
376 * parms we've got, then print it.
380 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
381 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
382 /* we have a string to use, but it ends "(dfs / zcm)",
383 * so we remove the extra gunk.
385 j = strlen(outMsgBuffer);
387 outMsgBuffer[j - 11] = 0;
391 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
392 alp[3] % 1000000, alp[2]);
393 for (i = 0; i < j; i++) {
394 if ((int)outMsgBuffer[i] > 5)
395 fputc(outMsgBuffer[i], outFilep);
397 switch (outMsgBuffer[i]) {
401 fprintf(outFilep, "%s", printfStrings[pfpix++]);
403 case 2: /* signed integer */
404 fprintf(outFilep, "%lld", printfParms[pfpix++]);
406 case 3: /* unsigned integer */
407 fprintf(outFilep, "%llu", printfParms[pfpix++]);
409 case 4: /* octal integer */
410 fprintf(outFilep, "%llo", printfParms[pfpix++]);
412 case 5: /* hex integer */
413 fprintf(outFilep, "%llx", printfParms[pfpix++]);
417 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
418 outMsgBuffer[i], pfpix);
419 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
425 fprintf(outFilep, "\n");
428 #else /* AFS_SGI61_ENV */
429 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
430 /* we have a string to use, but it ends "(dfs / zcm)",
431 * so we remove the extra gunk.
433 j = strlen(msgBuffer);
435 msgBuffer[j - 11] = 0;
436 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
437 alp[3] % 1000000, alp[2]);
438 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
439 printfParms[2], printfParms[3], printfParms[4],
440 printfParms[5], printfParms[6], printfParms[7],
441 printfParms[8], printfParms[9], printfParms[10],
442 printfParms[11], printfParms[12], printfParms[13],
443 printfParms[14], printfParms[15]);
444 fprintf(outFilep, "\n");
447 #endif /* AFS_SGI61_ENV */
449 fprintf(outFilep, "Type mismatch, using raw print.\n");
450 fprintf(outFilep, "%s", msgBuffer);
454 if (alp[1] == ICL_INFO_TIMESTAMP) {
455 fprintf(outFilep, "time %d.%06d, pid %u: %s\n", alp[3] / 1000000,
456 alp[3] % 1000000, alp[2], ctime((time_t *) & alp[4]));
458 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", alp[1],
459 alp[3] / 1000000, alp[3] % 1000000, alp[2]);
460 /* now decode each parameter and print it */
463 for (i = 0; !done && i < 4; i++) {
464 type = (temp >> (18 - i * 6)) & 0x3f;
470 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
474 tempParam = alp[pix];
476 tempParam |= alp[pix + 1];
477 fprintf(outFilep, "p%d:%lld ", i, tempParam);
478 #else /* AFS_SGI61_ENV */
479 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
480 #endif /* AFS_SGI61_ENV */
482 case ICL_TYPE_POINTER:
484 tempParam = alp[pix];
486 tempParam |= alp[pix + 1];
487 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
488 #else /* AFS_SGI61_ENV */
489 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
490 #endif /* AFS_SGI61_ENV */
494 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix],
498 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
499 alp[pix + 1], alp[pix + 2], alp[pix + 3]);
501 case ICL_TYPE_STRING:
502 fprintf(outFilep, "p%d:%s ", i, (char *)&alp[pix]);
504 case ICL_TYPE_UNIXDATE:
505 fprintf(outFilep, "p%d:%s ", i,
506 ctime((time_t *) & alp[pix]));
510 ("DisplayRecord: Bad type %d in raw print switch.\n",
518 pix += icl_GetSize(type, (char *)&alp[pix]);
521 fprintf(outFilep, "\n"); /* done with line */
531 #include <nl_types.h>
533 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
535 static nl_catd catopen1();
537 static nl_catd _do1_open();
538 static nl_catd cat_already_open();
539 static int make_sets();
540 static FILE *open1catfile();
541 static void add_open_cat();
542 static void cat_hard_close();
543 extern char *strchr();
545 static int catpid[NL_MAXOPEN];
546 static CATD *catsopen[NL_MAXOPEN];
547 #define PATH_FORMAT "/usr/lib/nls/msg/%L/%N:/etc/nls/msg/%L/%N"
548 #define DEFAULT_LANG "C"
549 #define TOO_MANY_HOLES(num_holes, num_non_holes) \
550 (((num_holes) > 100) && ((num_holes) > (num_non_holes)))
556 /*---- n: the number of bytes to be malloc'ed ----*/
560 t = (char *)malloc(n);
562 printf("Failed to get mem\n");
572 /*---- char *cat: the name of the cat to be opened ----*/
573 /*---- int dummy: dummy variable ----*/
577 nl_catd _do_open(); /*---- routine that actually opens
584 if (catd = cat_already_open(cat)) {
585 catd->_count = catd->_count + 1;
589 catd = (CATD *) rmalloc(sizeof(CATD));
592 catd->_name = (char *)rmalloc(strlen(cat) + 1);
593 if (catd->_name == NULL)
595 strcpy(catd->_name, cat);
597 catd->_magic = CAT_MAGIC;
599 #ifndef AFS_OSF20_ENV
600 catd->_pid = getpid();
603 if (_do1_open(catd) != CATD_ERR)
618 /*---- pointer to the partially set up cat descriptor ----*/
621 int make_sets(); /*---- routine to unpack the sets into
622 fast acccess mode ----*/
623 void add_open_cat(); /*---- routine to keep a list of
626 int i; /*---- Misc counter(s) used for loop */
633 catd->_fd = open1catfile(catd->_name);
637 fread((void *)&magic, (size_t) 4, (size_t) 1, catd->_fd);
638 if (magic != CAT_MAGIC) {
639 printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC,
647 /* if ((catd->_mem = shmat((int)fileno(catd->_fd), NULL, SHM_MAP | SHM_RDONLY))
648 == (char * )ERR ) { */
650 if (1) { /* disable the shmat, share memory segemnt */
652 /*______________________________________________________________________
653 If the file can not be mapped then simulate mapping for the index
654 table so that make_sets cat set things up. (rmalloc an area big
655 enough for the index table and read the whole thing in)
656 ______________________________________________________________________*/
658 /* reset the file pointer to the beginning of catalog */
659 fseek(catd->_fd, (long)0, 0);
661 /* malloc the header, if fails return error */
662 catd->_hd = (struct _header *)rmalloc(sizeof(struct _header));
663 if (catd->_hd == NULL)
666 /* read in the whole header */
667 fread((void *)catd->_hd, (size_t) sizeof(struct _header), (size_t) 1,
670 /* cs is a dummpy to hold a set temperorily. The purpose of */
671 /* this for loop is to fread the whole catalog so that the */
672 /* file pointer will be moved to the end of the catalog. */
673 for (i = 0; i < catd->_hd->_n_sets; i++) {
674 fread((void *)&cs, (size_t) 4, (size_t) 1, catd->_fd);
675 fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)), 1);
678 /* after the for loop, ftell returns the byte offset of the */
679 /* end of the catalog relative to the begining of the file. */
680 /* i.e. i contains the byte offset of the whole catalog. */
681 i = ftell(catd->_fd);
683 /* malloc _mem as a temp pointer to hold the entire catalog. */
684 catd->_mem = (char *)rmalloc(i);
685 if (catd->_mem == NULL)
688 /* reset the file pointer to the begining. */
689 fseek(catd->_fd, (long)0, 0);
691 /* read in the whole catalog into _mem */
692 fread((void *)catd->_mem, (size_t) i, (size_t) 1, catd->_fd);
695 * If there aren't many holes in the set numbers,
696 * fully expand the compacted set array from the
697 * catalog. Then in catgets(), we'll be able to use
698 * the set number to index directly into the expanded
701 * If there are a lot of holes, leave the set array
702 * compacted. In catgets(), we'll search through it
703 * for the requested set.
706 num_holes = catd->_hd->_setmax - catd->_hd->_n_sets;
707 if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) {
708 catd->_sets_expanded = TRUE;
709 catd->_n_sets = catd->_hd->_setmax;
711 catd->_sets_expanded = FALSE;
712 catd->_n_sets = catd->_hd->_n_sets - 1;
715 /* malloc one extra set more than the max. set index */
717 (struct _catset *)rmalloc((catd->_n_sets + 1) *
718 sizeof(struct _catset));
719 if (catd->_set == NULL)
722 /* save the max. set number in catd->_setmax */
723 catd->_setmax = catd->_hd->_setmax;
724 /* call make_set to malloc memory for every message */
725 if (make_sets(catd) == -1)
733 /*______________________________________________________________________
734 Normal mapping has occurred, set a few things up and call make_sets
735 ______________________________________________________________________*/
737 catd->_hd = (struct _header *)(catd->_mem);
738 catd->_setmax = catd->_hd->_setmax;
740 (struct _catset *)rmalloc((catd->_hd->_setmax + 1) *
741 sizeof(struct _catset));
742 if (catd->_set == NULL)
744 if (make_sets(catd) == -1)
755 /*---- catd to be added to the list of catalogs ----*/
758 int i = 0; /*---- Misc counter(s) used for loops ----*/
759 while (i < NL_MAXOPEN && catsopen[i]) {
760 if (!strcmp(catd->_name, catsopen[i]->_name)
761 #ifndef AFS_OSF20_ENV
762 && getpid() == catsopen[i]->_pid)
766 return; /*---- The catalog is already here ----*/
770 if (i < NL_MAXOPEN) {
772 catpid[i] = getpid();
781 * FUNCTION: Expands the compacted version of the catalog index table into
782 * the fast access memory version.
784 * EXECUTION ENVIRONMENT:
786 * Make_set executes under a process.
796 struct _catset *cset;
797 char *base = catd->_mem;
798 int n_sets = catd->_hd->_n_sets;
799 int i; /*---- Misc counter(s) used for loops ----*/
800 int j; /*---- Misc counter(s) used for loops ----*/
801 int msgmax; /*---- The maximum number of _messages in a set ----*/
802 char *cmpct_set_ptr; /*---- pointer into the index table ----*/
803 struct _catset cs; /*---- used to look at the sets in the table -*/
806 cmpct_set_ptr = base + sizeof(struct _header);
808 for (i = 0; i < n_sets; i++) {
809 /* loop through each compacted set */
811 cs = *(struct _catset *)cmpct_set_ptr;
812 /* set the _catset ptr to the base of the current
816 (struct _msgptr *)(cmpct_set_ptr + 2 * sizeof(unsigned short));
817 /* set the ms array ptr to the base of
818 * compacted array of _msgptr's */
821 (catd->_sets_expanded) ? &catd->_set[cs._setno] : &catd->_set[i];
824 * If there aren't many holes in the message numbers,
825 * fully expand the compacted message array from the
826 * catalog. Then in catgets(), we'll be able to use
827 * the message number to index directly into the
830 * If there are many holes, leave the message array
831 * compacted. In catgets(), we'll search through it
832 * for the requested message.
835 msgmax = cs._mp[cs._n_msgs - 1]._msgno;
836 num_holes = msgmax - cs._n_msgs;
837 if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) {
838 cset->_msgs_expanded = TRUE;
839 cset->_n_msgs = msgmax;
841 cset->_msgs_expanded = FALSE;
842 cset->_n_msgs = cs._n_msgs - 1;
846 (struct _msgptr *)rmalloc((1 + cset->_n_msgs) *
847 sizeof(struct _msgptr));
848 if (cset->_mp == NULL)
852 (char **)rmalloc((1 + cset->_n_msgs) * sizeof(char *));
853 if (cset->_msgtxt == NULL)
856 if (cset->_msgs_expanded) {
857 for (j = 0; j < cs._n_msgs; j++) {
858 cset->_mp[cs._mp[j]._msgno] = cs._mp[j];
861 for (j = 0; j < cs._n_msgs; j++) {
862 cset->_mp[j] = cs._mp[j];
866 cset->_setno = cs._setno;
867 /* Superfluous but should have the correct data. Increment
868 * the base of the set pointer. */
871 2 * sizeof(unsigned short) + cs._n_msgs * sizeof(struct _msgptr);
882 * FUNCTION: Opens a catalog file, looking in the language path first (if
883 * there is no slash) and returns a pointer to the file stream.
885 * EXECUTION ENVIRONMENT:
887 * Opencatfile executes under a process.
889 * RETURNS: Returns a pointer to the file stream, and a NULL pointer on
897 extern char *getenv();
898 char fl[PATH_MAX]; /*---- place to hold full path ----*/
899 char *nlspath; /*---- pointer to the nlspath val ----*/
900 FILE *fp; /*---- file pointer ----*/
901 char cpth[PATH_MAX]; /*---- current value of nlspath ----*/
903 char *fulllang; /* %L language value */
904 char lang[PATH_MAX]; /* %l language value */
905 char *territory; /* %t language value */
906 char *codeset; /* %c language value */
907 char *ptr; /* for decompose of $LANG */
912 char outptr[PATH_MAX];
915 if (strchr(file, '/')) {
916 if ((fp = fopen(file, "r"))) {
917 fcntl(fileno(fp), F_SETFD, 1);
918 /* set the close-on-exec flag for
923 if (!(nlspath = getenv("NLSPATH")))
924 nlspath = PATH_FORMAT;
925 if (!(fulllang = getenv("LANG")))
926 fulllang = DEFAULT_LANG;
927 if (fulllang == DEFAULT_LANG)
928 nlspath = PATH_FORMAT; /* if fullang is C, use the
929 * the default nlspath: */
932 ** LANG is a composite of three fields:
933 ** language_territory.codeset
934 ** and we're going to break it into those
938 strcpy(lang, fulllang);
943 ptr = strchr(lang, '_');
947 ptr = strchr(territory, '.');
953 ptr = strchr(lang, '.');
963 while (*np && *np != ':')
966 if (*np) /*---- iff on a colon then advance --*/
974 while (*ptr != '\0') {
975 while ((*ptr != '\0') && (*ptr != '%')
976 && (nchars < PATH_MAX)) {
977 *(optr++) = *(ptr++);
1005 lenstr = strlen(str);
1007 if (nchars < PATH_MAX) {
1015 if (nchars >= PATH_MAX) {
1021 strcpy(cpth, outptr);
1022 } else { /*---- iff leading | trailing |
1023 adjacent colons ... --*/
1027 if (valid == 1 && (fp = fopen(cpth, "r"))) {
1028 fcntl(fileno(fp), F_SETFD, 1);
1029 /* set the close-on-exec flag for
1034 if (fp = fopen(file, "r")) {
1035 fcntl(fileno(fp), F_SETFD, 1);
1036 /* set the close-on-exec flag for
1050 * NAME: cat_already_open
1052 * FUNCTION: Checkes to see if a specific cat has already been opened.
1054 * EXECUTION ENVIRONMENT:
1056 * Cat_already_open executes under a process.
1058 * RETURNS: Returns a pointer to the existing CATD if one exists, and
1059 * a NULL pointer if no CATD exists.
1063 cat_already_open(cat)
1065 /*---- name of the catalog to be opened ----*/
1068 int i; /*---- Misc counter(s) used for loops ----*/
1070 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1071 #ifndef AFS_OSF20_ENV
1072 if (!strcmp(cat, catsopen[i]->_name) && getpid() == catsopen[i]->_pid) {
1074 if (!strcmp(cat, catsopen[i]->_name)) {
1076 return (catsopen[i]);
1084 catclose1(catd) /*---- the catd to be closed ----*/
1085 nl_catd catd; /*---- the catd to be closed ----*/
1091 if (catd == CATD_ERR)
1093 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1094 #ifndef AFS_OSF20_ENV
1095 if (catd == catsopen[i] && getpid() == catsopen[i]->_pid)
1097 if (catd == catsopen[i])
1101 if (i == NL_MAXOPEN || catsopen[i] == NULL)
1103 if (catd->_fd == (FILE *) NULL)
1104 /*---- return if this is an extra open or
1105 a bad catalog discriptor ----*/
1107 if (cat_already_open(catd->_name)) {
1108 if (catd->_count == 1) {
1109 cat_hard_close(catd);
1110 return (0); /*--- the last legal clsoe ---*/
1111 } else if (catd->_count > 1) {
1112 catd->_count = catd->_count - 1;
1113 return (0); /*--- a legal close ---*/
1115 return (-1); /*--- an extra illegal close ---*/
1122 cat_hard_close(catd)
1124 /*---- the catd to be closed ----*/
1127 int i; /*---- Misc counter(s) used for loops ----*/
1128 int j; /*---- Misc counter ----*/
1130 if (catd == CATD_ERR)
1133 /*______________________________________________________________________
1134 remove any entry for the catalog in the catsopen array
1135 ______________________________________________________________________*/
1137 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1138 if (catd == catsopen[i]) {
1139 for (; i < NL_MAXOPEN - 1; i++) {
1140 catsopen[i] = catsopen[i + 1];
1141 catpid[i] = catpid[i + 1];
1148 /*______________________________________________________________________
1149 close the cat and free up the memory
1150 ______________________________________________________________________*/
1151 if (catd->_mem == FALSE) {
1152 for (i = 0; i <= catd->_n_sets; i++) {
1153 if (catd->_set[i]._mp)
1154 free(catd->_set[i]._mp);
1155 /*---- free the _message pointer arrays ----*/
1157 if (catd->_set[i]._msgtxt) {
1158 for (j = 0; j <= catd->_set[i]._n_msgs; j++) {
1159 if (catd->_set[i]._msgtxt[j]) {
1160 /* free(catd->_set[i]._msgtxt[j]);*/
1163 if (catd->_set[i]._msgtxt)
1164 free(catd->_set[i]._msgtxt);
1170 fclose(catd->_fd); /*---- close the ctatlog ----*/
1172 free(catd->_set); /*---- free the sets ----*/
1174 free(catd->_name); /*---- free the name ----*/
1176 free(catd->_hd); /*---- free the header ----*/
1178 free(catd); /*---- free the catd ----*/
1182 _do1_read_msg(nl_catd catd, int setno, int msgno)
1184 /*---- catd: the catd of the catalog to be read from ----*/
1185 /*---- setno: the set number of the message ----*/
1186 /*---- msgno: the msgno of the message ----*/
1188 nl_catd catd1; /*--- catd for different process ----*/
1191 #ifndef AFS_OSF20_ENV
1192 if (getpid() == catd->_pid)
1196 return (_read1_msg(catd, setno, msgno));
1199 * Since our pid is different from the one in
1200 * catd, catd must have come from a catopen()
1201 * in our parent. We need a catd of our own.
1202 * The first time through here, the call to
1203 * catopen() creates a new catd and we try to
1204 * open its message catalog. After that, the
1205 * catopen() just retrieves the catd.
1207 if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR)
1208 && ((catd1->_fd == NL_FILE_CLOSED && _do1_open(catd1) != CATD_ERR)
1209 || (catd1->_fd != NL_FILE_UNUSED)))
1210 return (_read1_msg(catd1, setno, msgno));
1217 struct _catset *_cat1_get_catset();
1218 static struct _msgptr *_cat1_get_msgptr();
1220 _read1_msg(nl_catd catd, int setno, int msgno)
1222 struct _catset *set; /*--- ptr to set's _catset structure ---*/
1223 struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/
1224 char **msgtxt; /*--- temporary pointer to the message text
1227 set = _cat1_get_catset(catd, setno);
1229 msg = _cat1_get_msgptr(set, msgno);
1231 msgtxt = &set->_msgtxt[msg - set->_mp];
1232 if (1 /*!*msgtxt */ ) {
1233 *msgtxt = (char *)malloc(msg->_msglen + 1);
1237 fseek(catd->_fd, (long)msg->_offset, 0);
1239 ((void *)*msgtxt, (size_t) (msg->_msglen + 1), (size_t) 1,
1251 * NAME: compare_sets
1253 * FUNCTION: Compare function used by bsearch() in _cat_get_catset().
1256 * key - pointer to set number we're searching for
1257 * element - pointer to current _catset structure
1259 * RETURNS: Returns -1, 0, or 1, depending on whether the set number
1260 * is less than, equal to, or greater than the set number of
1261 * the _catset structure.
1266 compare_sets(const void *key, const void *element)
1268 int *setno = (int *)key;
1269 struct _catset *set = (struct _catset *)element;
1271 if (*setno < set->_setno)
1273 if (*setno > set->_setno)
1281 * NAME: _cat_get_catset
1283 * FUNCTION: Find a set in the catd->_set array. Assumes that the
1284 * sets in the array are sorted by increasing set number.
1287 * catd - catalog descripter obtained from catopen()
1288 * setno - message catalogue set number
1290 * RETURNS: Returns a pointer to the set on success.
1291 * On any error, returns NULL.
1296 _cat1_get_catset(nl_catd catd, int setno)
1298 struct _catset *set;
1300 if ((catd == (nl_catd) NULL) || (catd == CATD_ERR))
1301 return (struct _catset *)NULL;
1303 if (catd->_sets_expanded) {
1304 if ((setno < 0) || (setno > catd->_n_sets))
1305 return (struct _catset *)NULL;
1307 set = &catd->_set[setno];
1310 * Catch empty elements in the array. They aren't
1314 if (set->_mp == (struct _msgptr *)NULL)
1315 return (struct _catset *)NULL;
1318 (struct _catset *)bsearch((void *)&setno, catd->_set,
1320 sizeof(struct _catset), compare_sets);
1323 * Since the sets are compacted, there aren't any
1324 * empty elements in the array to check for.
1333 * NAME: compare_msgs
1335 * FUNCTION: Compare function used by bsearch() in _cat_get_msgptr().
1338 * key - pointer to message number we're searching for
1339 * element - pointer to current _msgptr structure
1341 * RETURNS: Returns -1, 0, or 1, depending on whether the message
1342 * number is less than, equal to, or greater than the message
1343 * number of the _msgptr structure.
1348 compare_msgs(const void *key, const void *element)
1350 int *msgno = (int *)key;
1351 struct _msgptr *msg = (struct _msgptr *)element;
1353 if (*msgno < msg->_msgno)
1355 if (*msgno > msg->_msgno)
1362 * NAME: _cat1_get_msgptr
1364 * FUNCTION: Find a message in a set's set->_mp array. Assumes that
1365 * the messages in the array are sorted by increasing
1369 * set - ptr to _catset structure
1370 * msgno - message catalogue message number
1372 * RETURNS: Returns a pointer to the message on success.
1373 * On any error, returns NULL.
1376 static struct _msgptr *
1377 _cat1_get_msgptr(struct _catset *set, int msgno)
1379 struct _msgptr *msg;
1381 if (set == (struct _catset *)NULL)
1382 return (struct _msgptr *)NULL;
1384 if (set->_mp == (struct _msgptr *)NULL) /* empty set */
1385 return (struct _msgptr *)NULL;
1387 if (set->_msgs_expanded) {
1388 if ((msgno < 0) || (msgno > set->_n_msgs))
1389 return (struct _msgptr *)NULL;
1391 msg = &set->_mp[msgno];
1394 * Catch empty elements in the array. They aren't
1399 return (struct _msgptr *)NULL;
1402 (struct _msgptr *)bsearch((void *)&msgno, set->_mp,
1404 sizeof(struct _msgptr), compare_msgs);
1407 * Since the messages are compacted, there aren't any
1408 * empty elements in the array to check for.
1416 catgets1(nl_catd catd, int setno, int msgno, char *def)
1417 /*---- catd: the catd to get the message from ----*/
1418 /*---- setno: the set number of the message ----*/
1419 /*---- msgno: the message number of the message ----*/
1420 /*---- def: the default string to be returned ----*/
1423 char *_do_read_msg();
1427 if (catd == NULL || catd == CATD_ERR || catd->_magic != CAT_MAGIC
1428 || catd->_fd == NL_FILE_UNUSED) {
1431 if (catd->_fd == NL_FILE_CLOSED) {
1432 catd = _do1_open(catd);
1433 if (catd == CATD_ERR)
1437 if (catd->_mem) { /*---- for mapped files ----*/
1438 if (setno <= catd->_hd->_setmax) {
1439 if (msgno < catd->_set[setno]._n_msgs) {
1440 if (catd->_set[setno]._mp[msgno]._offset) {
1441 return (catd->_mem +
1442 catd->_set[setno]._mp[msgno]._offset);
1447 } else { /*---- for unmapped files ----*/
1448 m = _do1_read_msg(catd, setno, msgno);
1458 #define FACILITY_CODE_MASK 0xF0000000
1459 #define FACILITY_CODE_SHIFT 28
1461 #define COMPONENT_CODE_MASK 0x0FFFF000
1462 #define COMPONENT_CODE_SHIFT 12
1464 #define STATUS_CODE_MASK 0x00000FFF
1465 #define STATUS_CODE_SHIFT 0
1467 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
1470 * The system-dependant location for the catalog files is defined in sysconf.h
1471 * RPC_DEFAULT_NLSPATH should be defined in sysconf.h. Otherwise we use
1472 * /usr/afs/etc/C/%s.cat
1475 #ifndef RPC_NLS_FORMAT
1476 #define RPC_NLS_FORMAT "%s.cat"
1479 dce1_error_inq_text(status_to_convert, error_text, status)
1480 afs_uint32 status_to_convert;
1481 unsigned char *error_text;
1485 unsigned short facility_code;
1486 unsigned short component_code;
1487 unsigned short status_code;
1488 unsigned short i, failed = 0;
1490 char component_name[4];
1491 char *facility_name;
1492 char filename_prefix[7];
1493 char nls_filename[11];
1494 char alt_filename[80];
1497 static char *facility_names[] = {
1503 * set up output status for future error returns
1505 if (status != NULL) {
1509 * check for ok input status
1511 if (status_to_convert == 0) {
1512 if (status != NULL) {
1515 strcpy((char *)error_text, "successful completion");
1520 * extract the component, facility and status codes
1523 (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
1525 (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
1526 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
1529 * see if this is a recognized facility
1531 if (facility_code == 0
1532 || facility_code > sizeof(facility_names) / sizeof(char *)) {
1533 sprintf((char *)error_text, "status %08x (unknown facility)",
1537 facility_name = facility_names[facility_code - 1];
1539 * Convert component name from RAD-50 component code. (Mapping is:
1540 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
1542 component_name[3] = 0;
1543 component_name[2] = component_code % 40;
1544 component_code /= 40;
1545 component_name[1] = component_code % 40;
1546 component_name[0] = component_code / 40;
1547 for (i = 0; i < 3; i++) {
1548 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
1550 sprintf(filename_prefix, "%3s%3s", facility_name, component_name);
1551 sprintf(nls_filename, RPC_NLS_FORMAT, filename_prefix);
1554 * Open the message file
1556 #if defined(AFS_OSF_ENV)
1557 #if defined(AFS_OSF20_ENV)
1558 catd = (nl_catd) catopen(nls_filename, 0);
1560 catd = (nl_catd) catopen1(nls_filename, 0);
1563 J = (int)catopen(nls_filename, 0);
1566 if (catd == (nl_catd) - 1) {
1568 * If we did not succeed in opening message file using NLSPATH,
1569 * try to open the message file in a well-known default area
1572 #ifndef RPC_DEFAULT_NLSPATH
1573 sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH,
1576 sprintf(alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix);
1579 #if defined(AFS_OSF_ENV)
1580 #if defined(AFS_OSF20_ENV)
1581 catd = (nl_catd) catopen(alt_filename, 0);
1583 catd = (nl_catd) catopen1(alt_filename, 0);
1586 J = (int)catopen(alt_filename, 0);
1589 if (catd == (nl_catd) - 1) {
1590 sprintf((char *)error_text, "status %08x (%s / %s)",
1591 status_to_convert, facility_name, component_name);
1596 * try to get the specified message from the file
1598 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1599 message = (char *)catgets1(catd, 1, status_code, NO_MESSAGE);
1601 message = (char *)catgets(catd, 1, status_code, NO_MESSAGE);
1604 * if everything went well, return the resulting message
1606 if (strcmp(message, NO_MESSAGE) != 0) {
1607 sprintf((char *)error_text, "%s (%s / %s)", message, facility_name,
1609 if (status != NULL) {
1615 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1622 sprintf((char *)error_text, "status %08x (%s / %s)",
1623 status_to_convert, facility_name, component_name);
1625 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1634 icl_DumpKernel(outFilep, setname)
1638 afs_int32 bufferSize = 0;
1641 afs_int32 code, retVal = 0;
1646 afs_int32 dummy, dummy2;
1647 struct logInfo *lip;
1649 /* first, enumerate the logs we're interested in */
1652 /* dump logs for a particular set */
1653 for (i = 0; i < ICL_LOGSPERSET; i++) {
1655 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname,
1656 i, (long)tname, sizeof(tname));
1658 if (errno == EBADF) {
1660 continue; /* missing slot, nothing to worry about */
1665 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1666 (long)&dummy, (long)&dummy2, 0);
1670 if (dummy > bufferSize) /* find biggest log */
1672 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
1673 memset((char *)lip, 0, sizeof(*lip));
1674 lip->nextp = allInfo;
1676 lip->name = (char *)malloc(strlen(tname) + 1);
1677 strcpy(lip->name, tname);
1682 for (i = 0; i < 1000; i++) {
1684 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
1685 sizeof(tname), (long)&dummy);
1688 if (dummy > bufferSize) /* find biggest log */
1690 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
1691 memset((char *)lip, 0, sizeof(*lip));
1692 lip->nextp = allInfo;
1694 lip->name = (char *)malloc(strlen(tname) + 1);
1695 strcpy(lip->name, tname);
1699 if (bufferSize == 0)
1701 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1705 fprintf(outFilep, "Found %d logs.\n", i);
1707 /* now print out the contents of each log */
1708 for (lip = allInfo; lip; lip = lip->nextp) {
1709 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
1710 /* read out everything first; gets a more consistent
1713 nwords = 0; /* total words copied out */
1715 /* display all the entries in the log */
1716 if (bufferSize - nwords <= 0)
1717 break; /* filled whole buffer */
1719 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name,
1720 (long)(bufferp + nwords), bufferSize - nwords,
1723 /* otherwise we've got an error */
1724 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
1727 /* otherwise, we have flags in the high order byte, and
1728 * a length (in words) in the remainder.
1730 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
1731 fprintf(outFilep, "Log wrapped; data missing.\n");
1739 } /* for loop over all cookies */
1741 /* otherwise we should display all of the log entries here.
1742 * Note that a record may end in the middle, in which case
1743 * we should start over with the cookie value of the start
1746 for (ix = 0; ix < nwords;) {
1747 /* start of a record */
1748 rlength = (bufferp[ix] >> 24) & 0xff;
1750 fprintf(outFilep, "Internal error: 0 length record\n");
1754 /* ensure that entire record fits */
1755 if (ix + rlength > nwords) {
1756 /* doesn't fit, adjust cookie and break */
1759 /* print the record */
1760 DisplayRecord(outFilep, &bufferp[ix], rlength);
1763 /* obsolete: read entire buffer first */
1764 i += rlength; /* update cookie value, too */
1766 } /* for loop displaying buffer */
1767 } /* for loop over all logs */
1774 /* clear out log 'name' */
1780 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0);
1784 /* clear out set 'name' */
1790 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0);
1794 /* clear out all logs */
1799 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0);
1803 /* list out all available sets to outFileP */
1805 icl_ListSets(outFileP)
1813 for (i = 0; i < 1000; i++) {
1815 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname,
1816 sizeof(tname), (long)&states);
1819 (void)fprintf(outFileP, "%s %s%s%s\n", tname,
1820 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
1821 (states & ICL_SETF_FREED) ? " (dormant)" : "",
1822 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
1828 /* list out all available logs to outFileP */
1830 icl_ListLogs(outFileP, int32flg)
1840 for (i = 0; i < 1000; i++) {
1842 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
1843 sizeof(tname), (long)&logSize);
1847 /* get more information on the log */
1849 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1850 (long)&logSize, (long)&allocated, 0);
1853 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
1855 allocated ? "allocated" : "unallocated");
1857 (void)fprintf(outFileP, "%s\n", tname);
1863 /* list out all available logs to outFileP */
1865 icl_ListLogsBySet(outFileP, setname, int32flg)
1876 for (i = 0; i < ICL_LOGSPERSET; i++) {
1878 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i,
1879 (long)tname, sizeof(tname));
1881 if (errno == EBADF) {
1883 continue; /* missing */
1888 /* get more information on the log */
1890 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1891 (long)&logSize, (long)&allocated, 0);
1894 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
1896 allocated ? "allocated" : "unallocated");
1898 (void)fprintf(outFileP, "%s\n", tname);
1904 /* activate/deactivate/free specified set */
1906 icl_ChangeSetState(name, op)
1912 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0);
1916 /* activate/deactivate/free all sets */
1918 icl_ChangeAllSetState(op)
1923 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0);
1927 /* set size if log */
1929 icl_ChangeLogSize(name, logSize)
1936 afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0,
1941 /* get logsize of specified log */
1943 icl_GetLogsize(logname, logSizeP, allocatedP)
1945 afs_int32 *logSizeP;
1950 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1951 (long)logSizeP, (long)allocatedP, 0);
1955 /* get state of specified set */
1957 icl_GetSetState(setname, stateP)
1963 afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname,
1964 (long)stateP, 0, 0);
1968 icl_TailKernel(outFilep, logname, waitTime)
1973 afs_int32 bufferSize = 0;
1974 afs_int32 newBufferSize;
1977 afs_int32 code, retVal = 0;
1982 struct logInfo *lip;
1984 /* get information about the specified log */
1986 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1987 (long)&bufferSize, (long)&allocated, 0);
1989 if (errno == ENOENT)
1990 (void)fprintf(stderr, "'%s' not found\n", logname);
1992 (void)fprintf(stderr,
1993 "cannot get information on log '%s' (errno = %d)\n",
1999 (void)fprintf(stderr, "'%s' not allocated\n", logname);
2003 if (bufferSize == 0)
2005 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
2007 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
2012 /* start "infinite" loop */
2014 /* read out all that's currently there */
2015 nwords = 0; /* total words copied out */
2016 i = 0; /* initialize cookie */
2018 /* display all the entries in the log */
2019 if (bufferSize - nwords <= 0)
2020 break; /* filled whole buffer, clear when done */
2022 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname,
2023 (long)(bufferp + nwords), bufferSize - nwords,
2026 /* otherwise we've got an error */
2027 fprintf(stderr, "returned error %d dumping log.\n", errno);
2031 /* otherwise, we have flags in the high order byte, and
2032 * a length (in words) in the remainder.
2041 } /* for loop over all cookies */
2043 /* otherwise we should display all of the log entries here.
2044 * Note that a record may end in the middle, in which case
2045 * we should start over with the cookie value of the start
2048 for (ix = 0; ix < nwords;) {
2049 /* start of a record */
2050 rlength = (bufferp[ix] >> 24) & 0xff;
2051 /* ensure that entire record fits */
2052 if (ix + rlength > nwords) {
2053 /* doesn't fit, adjust cookie and break */
2055 fprintf(stderr, "BOGUS: 0 length record\n");
2061 /* print the record */
2062 DisplayRecord(outFilep, &bufferp[ix], rlength);
2064 } /* for loop displaying buffer */
2069 /* see if things have changed */
2071 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
2072 (long)&newBufferSize, (long)&allocated, 0);
2074 if (errno == ENOENT)
2075 (void)fprintf(stderr, "'%s' not found\n", logname);
2077 (void)fprintf(stderr,
2078 "cannot get information on log '%s' (errno = %d)\n",
2085 (void)fprintf(stderr, "'%s' no int32er allocated\n", logname);
2090 if (bufferSize == 0) {
2091 (void)fprintf(stderr, "buffer size has become 0\n");
2095 if (bufferSize != newBufferSize) {
2096 /* have to reallocate a buffer */
2097 bufferSize = newBufferSize;
2099 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
2101 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
2107 } /* infinite loop */
2114 #if !defined(AFS_SGI_ENV)
2115 afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
2116 long call, parm0, parm1, parm2, parm3, parm4, parm5, parm6;
2119 #ifdef AFS_LINUX20_ENV
2120 #if defined AFS_LINUX_64BIT_KERNEL
2122 /* don't want to sign extend it to 64bit, so using ulong */
2123 eparm[0] = (unsigned long)parm3;
2124 eparm[1] = (unsigned long)parm4;
2125 eparm[2] = (unsigned long)parm5;
2126 eparm[3] = (unsigned long)parm6;
2134 /* Linux can only handle 5 arguments in the actual syscall. */
2135 if (call == AFSCALL_ICL) {
2136 rval = proc_afs_syscall(call, parm0, parm1, parm2, eparm, &code);
2138 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
2140 rval = proc_afs_syscall(call, parm0, parm1, parm2, parm3, &code);
2142 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
2144 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
2145 /* on sparc this function returns none value, so do it myself */
2146 __asm__ __volatile__("mov %o0, %i0; ret; restore");
2149 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2150 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
2152 #if defined(AFS_SGI_ENV)
2153 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
2155 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
2158 #endif /* AFS_LINUX20_ENV */
2166 /* init function, called once, under icl_lock */
2172 /* setup signal handler, in user space */
2178 icl_CreateSet(name, baseLogp, fatalLogp, outSetpp)
2180 struct afs_icl_log *baseLogp;
2181 struct afs_icl_log *fatalLogp;
2182 struct afs_icl_set **outSetpp;
2184 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0,
2188 /* create a set, given pointers to base and fatal logs, if any.
2189 * Logs are unlocked, but referenced, and *outSetpp is returned
2190 * referenced. Function bumps reference count on logs, since it
2191 * addds references from the new icl_set. When the set is destroyed,
2192 * those references will be released.
2194 icl_CreateSetWithFlags(name, baseLogp, fatalLogp, flags, outSetpp)
2196 struct afs_icl_log *baseLogp;
2197 struct afs_icl_log *fatalLogp;
2199 struct afs_icl_set **outSetpp;
2201 register struct afs_icl_set *setp;
2203 afs_int32 states = ICL_DEFAULT_SET_STATES;
2208 for (setp = icl_allSets; setp; setp = setp->nextp) {
2209 if (strcmp(setp->name, name) == 0) {
2212 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
2213 setp->states |= ICL_SETF_PERSISTENT;
2219 /* determine initial state */
2220 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2221 states = ICL_SETF_ACTIVE;
2222 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2223 states = ICL_SETF_FREED;
2224 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2225 states |= ICL_SETF_PERSISTENT;
2227 setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set));
2228 memset((caddr_t) setp, 0, sizeof(*setp));
2230 if (states & ICL_SETF_FREED)
2231 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2232 setp->states = states;
2234 setp->name = (char *)osi_Alloc(strlen(name) + 1);
2235 strcpy(setp->name, name);
2236 setp->nevents = ICL_DEFAULTEVENTS;
2237 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
2238 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
2239 setp->eventFlags[i] = 0xff; /* default to enabled */
2241 /* update this global info under the icl_lock */
2242 setp->nextp = icl_allSets;
2245 /* set's basic lock is still held, so we can finish init */
2247 setp->logs[0] = baseLogp;
2248 icl_LogHold(baseLogp);
2249 if (!(setp->states & ICL_SETF_FREED))
2250 icl_LogUse(baseLogp); /* log is actually being used */
2253 setp->logs[1] = fatalLogp;
2254 icl_LogHold(fatalLogp);
2255 if (!(setp->states & ICL_SETF_FREED))
2256 icl_LogUse(fatalLogp); /* log is actually being used */
2263 /* function to change event enabling information for a particular set */
2264 icl_SetEnable(setp, eventID, setValue)
2265 struct afs_icl_set *setp;
2271 if (!ICL_EVENTOK(setp, eventID)) {
2274 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2276 *tp |= ICL_EVENTMASK(eventID);
2278 *tp &= ~(ICL_EVENTMASK(eventID));
2282 /* return indication of whether a particular event ID is enabled
2283 * for tracing. If *getValuep is set to 0, the event is disabled,
2284 * otherwise it is enabled. All events start out enabled by default.
2286 icl_GetEnable(setp, eventID, getValuep)
2287 struct afs_icl_set *setp;
2291 if (!ICL_EVENTOK(setp, eventID)) {
2294 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2301 /* hold and release event sets */
2303 register struct afs_icl_set *setp;
2309 /* free a set. Called with icl_lock locked */
2311 register struct afs_icl_set *setp;
2313 register struct afs_icl_set **lpp, *tp;
2315 register struct afs_icl_log *tlp;
2317 for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2319 /* found the dude we want to remove */
2321 osi_Free(setp->name, 1 + strlen(setp->name));
2322 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
2323 for (i = 0; i < ICL_LOGSPERSET; i++) {
2324 if (tlp = setp->logs[i])
2327 osi_Free(setp, sizeof(struct afs_icl_set));
2328 break; /* won't find it twice */
2334 /* do the release, watching for deleted entries */
2336 register struct afs_icl_set *setp;
2338 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2339 icl_ZapSet(setp); /* destroys setp's lock! */
2344 /* free a set entry, dropping its reference count */
2346 register struct afs_icl_set *setp;
2348 setp->states |= ICL_SETF_DELETED;
2353 /* find a set by name, returning it held */
2354 struct afs_icl_set *
2358 register struct afs_icl_set *tp;
2360 for (tp = icl_allSets; tp; tp = tp->nextp) {
2361 if (strcmp(tp->name, name) == 0) {
2362 /* this is the dude we want */
2370 /* zero out all the logs in the set */
2372 struct afs_icl_set *setp;
2377 struct afs_icl_log *logp;
2379 for (i = 0; i < ICL_LOGSPERSET; i++) {
2380 logp = setp->logs[i];
2383 tcode = icl_ZeroLog(logp);
2385 code = tcode; /* save the last bad one */
2392 icl_EnumerateSets(aproc, arock)
2396 register struct afs_icl_set *tp, *np;
2397 register afs_int32 code;
2400 for (tp = icl_allSets; tp; tp = np) {
2401 tp->refCount++; /* hold this guy */
2402 code = (*aproc) (tp->name, arock, tp);
2403 np = tp->nextp; /* tp may disappear next, but not np */
2404 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2412 icl_AddLogToSet(setp, newlogp)
2413 struct afs_icl_set *setp;
2414 struct afs_icl_log *newlogp;
2418 struct afs_icl_log *logp;
2420 for (i = 0; i < ICL_LOGSPERSET; i++) {
2421 if (!setp->logs[i]) {
2422 setp->logs[i] = newlogp;
2424 icl_LogHold(newlogp);
2425 if (!(setp->states & ICL_SETF_FREED)) {
2426 /* bump up the number of sets using the log */
2427 icl_LogUse(newlogp);
2435 icl_SetSetStat(setp, op)
2436 struct afs_icl_set *setp;
2441 struct afs_icl_log *logp;
2444 case ICL_OP_SS_ACTIVATE: /* activate a log */
2446 * If we are not already active, see if we have released
2447 * our demand that the log be allocated (FREED set). If
2448 * we have, reassert our desire.
2450 if (!(setp->states & ICL_SETF_ACTIVE)) {
2451 if (setp->states & ICL_SETF_FREED) {
2452 /* have to reassert desire for logs */
2453 for (i = 0; i < ICL_LOGSPERSET; i++) {
2454 logp = setp->logs[i];
2461 setp->states &= ~ICL_SETF_FREED;
2463 setp->states |= ICL_SETF_ACTIVE;
2468 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2469 /* this doesn't require anything beyond clearing the ACTIVE flag */
2470 setp->states &= ~ICL_SETF_ACTIVE;
2474 case ICL_OP_SS_FREE: /* deassert design for log */
2476 * if we are already in this state, do nothing; otherwise
2477 * deassert desire for log
2479 if (setp->states & ICL_SETF_ACTIVE)
2482 if (!(setp->states & ICL_SETF_FREED)) {
2483 for (i = 0; i < ICL_LOGSPERSET; i++) {
2484 logp = setp->logs[i];
2487 icl_LogFreeUse(logp);
2491 setp->states |= ICL_SETF_FREED;
2504 struct afs_icl_log *afs_icl_allLogs = 0;
2506 /* hold and release logs */
2508 register struct afs_icl_log *logp;
2514 /* hold and release logs, called with lock already held */
2516 register struct afs_icl_log *logp;
2522 /* keep track of how many sets believe the log itself is allocated */
2524 register struct afs_icl_log *logp;
2526 if (logp->setCount == 0) {
2527 /* this is the first set actually using the log -- allocate it */
2528 if (logp->logSize == 0) {
2529 /* we weren't passed in a hint and it wasn't set */
2530 logp->logSize = ICL_DEFAULT_LOGSIZE;
2533 (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
2539 /* decrement the number of real users of the log, free if possible */
2540 icl_LogFreeUse(logp)
2541 register struct afs_icl_log *logp;
2543 if (--logp->setCount == 0) {
2544 /* no more users -- free it (but keep log structure around) */
2545 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2546 logp->firstUsed = logp->firstFree = 0;
2547 logp->logElements = 0;
2553 /* set the size of the log to 'logSize' */
2554 icl_LogSetSize(logp, logSize)
2555 register struct afs_icl_log *logp;
2559 /* nothing to worry about since it's not allocated */
2560 logp->logSize = logSize;
2563 logp->firstUsed = logp->firstFree = 0;
2564 logp->logElements = 0;
2566 /* free and allocate a new one */
2567 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2568 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
2569 logp->logSize = logSize;
2575 /* free a log. Called with icl_lock locked. */
2577 register struct afs_icl_log *logp;
2579 register struct afs_icl_log **lpp, *tp;
2581 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2583 /* found the dude we want to remove */
2585 osi_Free(logp->name, 1 + strlen(logp->name));
2586 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
2587 osi_Free(logp, sizeof(struct icl_log));
2588 break; /* won't find it twice */
2594 /* do the release, watching for deleted entries */
2596 register struct afs_icl_log *logp;
2598 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2599 icl_ZapLog(logp); /* destroys logp's lock! */
2604 /* do the release, watching for deleted entries, log already held */
2606 register struct afs_icl_log *logp;
2608 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2609 icl_ZapLog(logp); /* destroys logp's lock! */
2614 /* zero out the log */
2616 icl_ZeroLog(register struct afs_icl_log *logp)
2618 logp->firstUsed = logp->firstFree = 0;
2619 logp->logElements = 0;
2623 /* free a log entry, and drop its reference count */
2625 register struct afs_icl_log *logp;
2627 logp->states |= ICL_LOGF_DELETED;
2634 icl_EnumerateLogs(int (*aproc)
2635 (char *name, char *arock, struct afs_icl_log * tp),
2638 register struct afs_icl_log *tp;
2639 register afs_int32 code;
2642 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2643 tp->refCount++; /* hold this guy */
2644 code = (*aproc) (tp->name, arock, tp);
2645 if (--tp->refCount == 0)
2654 afs_icl_bulkSetinfo_t *
2657 unsigned int infoSize;
2660 sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
2661 1) * sizeof(afs_icl_setinfo_t);
2663 setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize);
2665 (void)fprintf(stderr,
2666 "Could not allocate the memory for bulk set info structure\n");
2670 memset((char *)setInfo, 0, infoSize);
2675 afs_icl_bulkLoginfo_t *
2678 unsigned int infoSize;
2681 sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
2682 1) * sizeof(afs_icl_loginfo_t);
2684 logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize);
2686 (void)fprintf(stderr,
2687 "Could not allocate the memory for bulk log info structure\n");
2692 memset((char *)logInfo, 0, infoSize);
2699 register struct cmd_syndesc *as;
2704 afs_int32 waitTime = 10 /* seconds */ ;
2708 FILE *outfp = stdout;
2710 struct cmd_item *itemp;
2712 if (geteuid() != 0) {
2713 printf("fstrace must be run as root\n");
2717 if (as->parms[3].items) {
2718 if (!as->parms[1].items) {
2719 (void)fprintf(stderr, "-sleep can only be used with -follow\n");
2722 waitTime = strtol(as->parms[3].items->data, NULL, 0);
2725 if (as->parms[2].items) {
2726 /* try to open the specified output file */
2727 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) {
2728 (void)fprintf(stderr, "Cannot open file '%s' for writing\n",
2729 as->parms[2].items->data);
2733 #ifdef AFS_SGI64_ENV
2734 startTime = time((time_t *) 0);
2736 startTime = time(0);
2738 (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
2741 if (as->parms[0].items) {
2742 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2743 tcode = icl_DumpKernel(outfp, itemp->data);
2745 (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
2746 itemp->data, errno);
2750 } else if (as->parms[1].items) {
2751 logname = as->parms[1].items->data;
2752 code = icl_TailKernel(outfp, logname, waitTime);
2754 (void)fprintf(stderr,
2755 "Error tailing kernel log '%s' (errno = %d)\n",
2759 code = icl_DumpKernel(outfp, NULL);
2761 (void)fprintf(outfp, "\nAFS Trace Dump - %s\n",
2762 code ? "FAILED" : "Completed");
2764 if (outfp != stdout)
2765 (void)fclose(outfp);
2773 struct cmd_syndesc *dumpSyntax;
2776 cmd_CreateSyntax("dump", DoDump, (char *)NULL, "dump AFS trace logs");
2777 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2778 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL,
2780 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL,
2782 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL,
2783 "seconds_between_reads");
2787 DoShowLog(as, arock)
2788 register struct cmd_syndesc *as;
2791 afs_int32 retVal = 0;
2796 struct cmd_item *itemp;
2798 if (geteuid() != 0) {
2799 printf("fstrace must be run as root\n");
2802 if (as->parms[2].items)
2805 if (as->parms[0].items) {
2806 /* enumerate logs for the specified sets */
2807 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2808 (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data);
2809 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
2811 (void)fprintf(stderr,
2812 "Error in enumerating set %s (errno = %d)\n",
2813 itemp->data, errno);
2817 } else if (as->parms[1].items) {
2818 /* print out log information */
2819 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
2820 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
2822 (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
2824 allocated ? "allocated" : "unallocated");
2826 (void)fprintf(stderr,
2827 "Could not find log '%s' (errno = %d)\n",
2828 itemp->data, errno);
2834 (void)fprintf(stdout, "Available logs:\n");
2835 code = icl_ListLogs(stdout, int32flg);
2837 (void)fprintf(stderr, "Error in listing logs (errno = %d)\n",
2849 struct cmd_syndesc *showSyntax;
2852 cmd_CreateSyntax("lslog", DoShowLog, (char *)NULL,
2853 "list available logs");
2854 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2855 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
2856 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL, "");
2860 DoShowSet(as, arock)
2861 register struct cmd_syndesc *as;
2864 afs_int32 retVal = 0;
2867 struct cmd_item *itemp;
2869 if (geteuid() != 0) {
2870 printf("fstrace must be run as root\n");
2873 if (as->parms[0].items) {
2874 /* print information on the specified sets */
2875 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2876 code = icl_GetSetState(itemp->data, &state);
2878 (void)fprintf(stderr,
2879 "Error getting status on set %s (errno = %d)\n",
2880 itemp->data, errno);
2883 (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
2884 (state & ICL_SETF_ACTIVE) ? "active" :
2886 (state & ICL_SETF_FREED) ? " (dormant)" : "",
2887 (state & ICL_SETF_PERSISTENT) ? " persistent" :
2892 (void)fprintf(stdout, "Available sets:\n");
2893 code = icl_ListSets(stdout);
2895 (void)fprintf(stderr, "Error in listing sets (errno = %d)\n",
2907 struct cmd_syndesc *showSyntax;
2910 cmd_CreateSyntax("lsset", DoShowSet, (char *)NULL,
2911 "list available event sets");
2912 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2917 register struct cmd_syndesc *as;
2920 afs_int32 retVal = 0;
2922 struct cmd_item *itemp;
2924 if (geteuid() != 0) {
2925 printf("fstrace must be run as root\n");
2928 if (as->parms[0].items) {
2929 /* clear logs for the specified sets */
2930 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2931 code = icl_ClearSet(itemp->data);
2933 (void)fprintf(stderr,
2934 "Error in clearing set %s (errno = %d)\n",
2935 itemp->data, errno);
2939 } else if (as->parms[1].items) {
2940 /* clear specified log */
2941 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2942 code = icl_ClearLog(itemp->data);
2944 (void)fprintf(stderr,
2945 "Error in clearing log %s (errno = %d)\n",
2946 itemp->data, errno);
2951 /* clear all logs */
2952 code = icl_ClearAll();
2954 (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n",
2966 struct cmd_syndesc *clearSyntax;
2969 cmd_CreateSyntax("clear", DoClear, (char *)NULL,
2970 "clear logs by logname or by event set");
2971 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
2973 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
2979 register struct cmd_syndesc *as;
2982 afs_int32 retVal = 0;
2987 struct cmd_item *itemp;
2989 if (geteuid() != 0) {
2990 printf("fstrace must be run as root\n");
2993 if (as->parms[1].items) {
2994 op = ICL_OP_SS_ACTIVATE;
2995 operation = "active";
2996 } else if (as->parms[2].items) {
2997 op = ICL_OP_SS_DEACTIVATE;
2998 operation = "inactive";
2999 } else if (as->parms[3].items) {
3000 op = ICL_OP_SS_DEACTIVATE;
3001 operation = "inactive";
3004 /* assume active" */
3005 op = ICL_OP_SS_ACTIVATE;
3006 operation = "active";
3009 if (as->parms[0].items) {
3010 /* activate specified sets */
3011 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
3012 code = icl_ChangeSetState(itemp->data, op);
3014 (void)fprintf(stderr,
3015 "cannot set state of %s to %s (errno = %d)\n",
3016 itemp->data, operation, errno);
3018 } else if (doFree) {
3019 /* try to make it dormant as well */
3020 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
3022 (void)fprintf(stderr,
3023 "cannot set state of %s to dormant (errno = %d)\n",
3024 itemp->data, errno);
3031 code = icl_ChangeAllSetState(op);
3033 (void)fprintf(stderr,
3034 "cannot set the state of all sets to %s (errno = %d)\n",
3037 } else if (doFree) {
3038 /* try to make it dormant as well */
3039 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
3041 (void)fprintf(stderr,
3042 "cannot set the state of all sets to dormant (errno = %d)\n",
3055 struct cmd_syndesc *setSyntax;
3058 cmd_CreateSyntax("setset", DoSet, (char *)NULL,
3059 "set state of event sets");
3060 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
3061 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL, "");
3062 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
3063 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL, "");
3068 register struct cmd_syndesc *as;
3071 afs_int32 retVal = 0;
3073 afs_int32 bufferSize;
3074 struct cmd_item *itemp;
3076 if (geteuid() != 0) {
3077 printf("fstrace must be run as root\n");
3080 /* get buffer size */
3081 bufferSize = atoi(as->parms[1].items->data);
3082 bufferSize *= BUFFER_MULTIPLIER;
3083 if (bufferSize == 0)
3084 bufferSize = ICL_DEFAULT_LOGSIZE;
3086 /* set the size of the specified logs */
3087 if (itemp = as->parms[0].items) {
3088 for (; itemp; itemp = itemp->next) {
3089 code = icl_ChangeLogSize(itemp->data, bufferSize);
3091 (void)fprintf(stderr,
3092 "Error in changing log %s buffer size (errno = %d)\n",
3093 itemp->data, errno);
3098 /* Use the only current support log, "cmfx" */
3099 code = icl_ChangeLogSize("cmfx", bufferSize);
3101 (void)fprintf(stderr,
3102 "Error in changing log cmfx buffer size (errno = %d)\n",
3114 struct cmd_syndesc *setsizeSyntax;
3117 cmd_CreateSyntax("setlog", DoResize, (char *)NULL,
3118 "set the size of a log");
3119 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
3121 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED,
3122 "1-kilobyte_units");
3125 #include "AFS_component_version_number.c"
3131 setlocale(LC_ALL, "");
3132 #ifdef AFS_SGI62_ENV
3133 set_kernel_sizeof_long();
3136 /* set up user interface then dispatch */
3144 return (cmd_Dispatch(argc, argv));
3147 #include "AFS_component_version_number.c"
3151 printf("fstrace is NOT supported for this OS\n");