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>
22 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43)
24 /*#ifdef AFS_AIX_ENV*/
35 #include <afs/afs_args.h>
37 #include <afs/afsutil.h>
40 #include <afs/sys_prototypes.h>
42 #if defined(AFS_OSF_ENV) || defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
43 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
44 int afs_icl_sizeofLong = 2;
46 int afs_icl_sizeofLong = 1;
49 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
50 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
51 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
55 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
57 set_kernel_sizeof_long(void)
62 retval = sysconf(_SC_KERN_POINTERS);
65 afs_icl_sizeofLong = 2;
68 afs_icl_sizeofLong = 1;
72 #endif /* AFS_SGI62_ENV */
73 #endif /* AFS_SGI61_ENV */
75 int afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
76 long parm4, long parm5, long parm6);
77 void dce1_error_inq_text(afs_uint32 status_to_convert,
78 char *error_text, int *status);
79 int icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
80 struct afs_icl_log *fatalLogp, afs_uint32 flags,
81 struct afs_icl_set **outSetpp);
82 int icl_LogHold(register struct afs_icl_log *logp);
83 int icl_LogUse(register struct afs_icl_log *logp);
84 int icl_LogReleNL(register struct afs_icl_log *logp);
85 int icl_LogRele(register struct afs_icl_log *logp);
86 int icl_ZeroLog(register struct afs_icl_log *logp);
87 int icl_LogFreeUse(register struct afs_icl_log *logp);
89 #define BUFFER_MULTIPLIER 1024
91 /* make it big enough to snapshot everything at once, since
92 * decoding takes so long.
94 #define IBSIZE 100000 /* default size */
97 struct logInfo *nextp;
101 char dumpFileName[256] = "";
103 RegisterIclDumpFileName(char *name)
105 (void)sprintf(dumpFileName, "icl.%.250s", name);
108 /* define globals to use for bulk info */
109 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0;
110 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0;
112 struct afs_icl_set *icl_allSets = 0;
116 /* given a type and an address, get the size of the thing
120 icl_GetSize(afs_int32 type, char *addr)
126 ICL_SIZEHACK(type, addr);
130 /* Check types in printf string "bufferp", making sure that each
131 * is compatible with the corresponding parameter type described
132 * by typesp. Also watch for prematurely running out of parameters
133 * before the string is gone.
135 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
137 CheckTypes(char *bufferp, int *typesp, int typeCount, char *outMsgBuffer)
145 for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
148 /* hit end of string. We win as long as we aren't
157 inPercent = 1 - inPercent;
161 if (tc >= '0' && tc <= '9') {
162 /* skip digits in % string */
167 /* 'l' is a type modifier. */
171 /* otherwise, we've finally gotten to the type-describing
172 * character. Make sure there's a type descriptor, and then
173 * check the type descriptor.
177 return 0; /* no more type descriptors left */
179 if (typesp[tix] != 1) /* not a string descriptor */
182 *outMsgBuffer = (char)1;
184 if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') {
185 if (typesp[tix] != 0)
186 return 0; /* not an integer descriptor */
190 *outMsgBuffer = (char)2;
193 *outMsgBuffer = (char)3;
196 *outMsgBuffer = (char)4;
200 *outMsgBuffer = (char)5;
204 /* otherwise we're fine, so eat this descriptor */
210 #else /* AFS_SGI61_ENV */
212 CheckTypes(char *bufferp, int *typesp, int typeCount)
220 for (tc = *bufferp;; tc = *(++bufferp)) {
222 /* hit end of string. We win as long as we aren't
231 inPercent = 1 - inPercent;
235 if (tc >= '0' && tc <= '9')
236 continue; /* skip digits in % string */
237 /* otherwise, we've finally gotten to the type-describing
238 * character. Make sure there's a type descriptor, and then
239 * check the type descriptor.
243 return 0; /* no more type descriptors left */
244 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
246 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
247 && (typesp[tix] != 0))
248 return 0; /* not an integer descriptor */
249 /* otherwise we're fine, so eat this descriptor */
255 #endif /* AFS_SGI61_ENV */
257 /* display a single record.
258 * alp points at the first word in the array to be interpreted
259 * rsize gives the # of words in the array
261 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
262 #define uint64_t long long
265 DisplayRecord(FILE *outFilep, register afs_int32 *alp, afs_int32 rsize)
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 #elif defined(AFS_OSF_ENV)
316 printfParms[pfpix] = alp[pix + 1];
317 printfParms[pfpix] |= (alp[pix] <<= 32);
318 #else /* !AFS_OSF_ENV && !AFS_SGI61_ENV */
319 printfParms[pfpix] = alp[pix];
324 printfTypes[pftix++] = 0;
325 printfParms[pfpix++] = alp[pix];
329 printfTypes[pftix++] = 0;
330 printfParms[pfpix++] = alp[pix];
331 printfTypes[pftix++] = 0;
332 printfParms[pfpix++] = alp[pix + 1];
335 printfTypes[pftix++] = 0;
336 printfParms[pfpix++] = alp[pix];
337 printfTypes[pftix++] = 0;
338 printfParms[pfpix++] = alp[pix + 1];
339 printfTypes[pftix++] = 0;
340 printfParms[pfpix++] = alp[pix + 2];
341 printfTypes[pftix++] = 0;
342 printfParms[pfpix++] = alp[pix + 3];
344 case ICL_TYPE_STRING:
345 printfTypes[pftix++] = 1;
347 printfStrings[pfpix++] = (char *)&alp[pix];
348 #else /* AFS_SGI64_ENV */
349 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
350 printfStrings[pfpix++] = (char *)&alp[pix];
351 #else /* AFS_SGI61_ENV */
352 printfParms[pfpix++] = (long)&alp[pix];
353 #endif /* AFS_SGI61_ENV */
354 #endif /* AFS_SGI64_ENV */
356 case ICL_TYPE_UNIXDATE:
358 printfParms[pfpix++] = (long)ctime(&tmv);
361 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
368 pix += icl_GetSize(type, (char *)&alp[pix]);
371 /* next, try to decode the opcode into a printf string */
372 dce1_error_inq_text(alp[1], msgBuffer, &status);
374 /* if we got a string back, and it is compatible with the
375 * parms we've got, then print it.
379 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
380 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
381 /* we have a string to use, but it ends "(dfs / zcm)",
382 * so we remove the extra gunk.
384 j = strlen(outMsgBuffer);
386 outMsgBuffer[j - 11] = 0;
390 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
391 alp[3] % 1000000, alp[2]);
392 for (i = 0; i < j; i++) {
393 if ((int)outMsgBuffer[i] > 5)
394 fputc(outMsgBuffer[i], outFilep);
396 switch (outMsgBuffer[i]) {
400 fprintf(outFilep, "%s", printfStrings[pfpix++]);
402 case 2: /* signed integer */
403 fprintf(outFilep, "%" AFS_INT64_FMT, printfParms[pfpix++]);
405 case 3: /* unsigned integer */
406 fprintf(outFilep, "%llu", printfParms[pfpix++]);
408 case 4: /* octal integer */
409 fprintf(outFilep, "%llo", printfParms[pfpix++]);
411 case 5: /* hex integer */
412 fprintf(outFilep, "%llx", printfParms[pfpix++]);
416 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
417 outMsgBuffer[i], pfpix);
418 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
424 fprintf(outFilep, "\n");
427 #else /* AFS_SGI61_ENV */
428 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
429 /* we have a string to use, but it ends "(dfs / zcm)",
430 * so we remove the extra gunk.
432 j = strlen(msgBuffer);
434 msgBuffer[j - 11] = 0;
435 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
436 alp[3] % 1000000, alp[2]);
437 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
438 printfParms[2], printfParms[3], printfParms[4],
439 printfParms[5], printfParms[6], printfParms[7],
440 printfParms[8], printfParms[9], printfParms[10],
441 printfParms[11], printfParms[12], printfParms[13],
442 printfParms[14], printfParms[15]);
443 fprintf(outFilep, "\n");
446 #endif /* AFS_SGI61_ENV */
448 fprintf(outFilep, "Type mismatch, using raw print.\n");
449 fprintf(outFilep, "%s", msgBuffer);
453 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(&tmv));
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:%" AFS_INT64_FMT " ", 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:
506 fprintf(outFilep, "p%d:%s ", i,
511 ("DisplayRecord: Bad type %d in raw print switch.\n",
519 pix += icl_GetSize(type, (char *)&alp[pix]);
522 fprintf(outFilep, "\n"); /* done with line */
532 #include <nl_types.h>
534 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
536 static nl_catd catopen1();
538 static nl_catd _do1_open();
539 static nl_catd cat_already_open();
540 static int make_sets();
541 static FILE *open1catfile();
542 static void add_open_cat();
543 static void cat_hard_close();
544 extern char *strchr();
546 static int catpid[NL_MAXOPEN];
547 static CATD *catsopen[NL_MAXOPEN];
548 #define PATH_FORMAT "/usr/lib/nls/msg/%L/%N:/etc/nls/msg/%L/%N"
549 #define DEFAULT_LANG "C"
550 #define TOO_MANY_HOLES(num_holes, num_non_holes) \
551 (((num_holes) > 100) && ((num_holes) > (num_non_holes)))
555 /*---- n: the number of bytes to be malloc'ed ----*/
559 t = (char *)malloc(n);
561 printf("Failed to get mem\n");
568 catopen1(char *cat, int dummy)
569 /*---- char *cat: the name of the cat to be opened ----*/
570 /*---- int dummy: dummy variable ----*/
574 nl_catd _do_open(); /*---- routine that actually opens
581 if (catd = cat_already_open(cat)) {
582 catd->_count = catd->_count + 1;
586 catd = (CATD *) rmalloc(sizeof(CATD));
589 catd->_name = (char *)rmalloc(strlen(cat) + 1);
590 if (catd->_name == NULL)
592 strcpy(catd->_name, cat);
594 catd->_magic = CAT_MAGIC;
596 #ifndef AFS_OSF20_ENV
597 catd->_pid = getpid();
600 if (_do1_open(catd) != CATD_ERR)
612 _do1_open(nl_catd catd)
613 /*---- pointer to the partially set up cat descriptor ----*/
615 int make_sets(); /*---- routine to unpack the sets into
616 fast acccess mode ----*/
617 void add_open_cat(); /*---- routine to keep a list of
620 int i; /*---- Misc counter(s) used for loop */
627 catd->_fd = open1catfile(catd->_name);
631 fread((void *)&magic, (size_t) 4, (size_t) 1, catd->_fd);
632 if (magic != CAT_MAGIC) {
633 printf("Magic was %x instead of %x -> %x\n", magic, CAT_MAGIC,
641 /* if ((catd->_mem = shmat((int)fileno(catd->_fd), NULL, SHM_MAP | SHM_RDONLY))
642 == (char * )ERR ) { */
644 if (1) { /* disable the shmat, share memory segemnt */
646 /*______________________________________________________________________
647 If the file can not be mapped then simulate mapping for the index
648 table so that make_sets cat set things up. (rmalloc an area big
649 enough for the index table and read the whole thing in)
650 ______________________________________________________________________*/
652 /* reset the file pointer to the beginning of catalog */
653 fseek(catd->_fd, (long)0, 0);
655 /* malloc the header, if fails return error */
656 catd->_hd = (struct _header *)rmalloc(sizeof(struct _header));
657 if (catd->_hd == NULL)
660 /* read in the whole header */
661 fread((void *)catd->_hd, (size_t) sizeof(struct _header), (size_t) 1,
664 /* cs is a dummpy to hold a set temperorily. The purpose of */
665 /* this for loop is to fread the whole catalog so that the */
666 /* file pointer will be moved to the end of the catalog. */
667 for (i = 0; i < catd->_hd->_n_sets; i++) {
668 fread((void *)&cs, (size_t) 4, (size_t) 1, catd->_fd);
669 fseek(catd->_fd, (long)(cs._n_msgs * sizeof(struct _msgptr)), 1);
672 /* after the for loop, ftell returns the byte offset of the */
673 /* end of the catalog relative to the begining of the file. */
674 /* i.e. i contains the byte offset of the whole catalog. */
675 i = ftell(catd->_fd);
677 /* malloc _mem as a temp pointer to hold the entire catalog. */
678 catd->_mem = (char *)rmalloc(i);
679 if (catd->_mem == NULL)
682 /* reset the file pointer to the begining. */
683 fseek(catd->_fd, (long)0, 0);
685 /* read in the whole catalog into _mem */
686 fread((void *)catd->_mem, (size_t) i, (size_t) 1, catd->_fd);
689 * If there aren't many holes in the set numbers,
690 * fully expand the compacted set array from the
691 * catalog. Then in catgets(), we'll be able to use
692 * the set number to index directly into the expanded
695 * If there are a lot of holes, leave the set array
696 * compacted. In catgets(), we'll search through it
697 * for the requested set.
700 num_holes = catd->_hd->_setmax - catd->_hd->_n_sets;
701 if (!TOO_MANY_HOLES(num_holes, catd->_hd->_n_sets)) {
702 catd->_sets_expanded = TRUE;
703 catd->_n_sets = catd->_hd->_setmax;
705 catd->_sets_expanded = FALSE;
706 catd->_n_sets = catd->_hd->_n_sets - 1;
709 /* malloc one extra set more than the max. set index */
711 (struct _catset *)rmalloc((catd->_n_sets + 1) *
712 sizeof(struct _catset));
713 if (catd->_set == NULL)
716 /* save the max. set number in catd->_setmax */
717 catd->_setmax = catd->_hd->_setmax;
718 /* call make_set to malloc memory for every message */
719 if (make_sets(catd) == -1)
727 /*______________________________________________________________________
728 Normal mapping has occurred, set a few things up and call make_sets
729 ______________________________________________________________________*/
731 catd->_hd = (struct _header *)(catd->_mem);
732 catd->_setmax = catd->_hd->_setmax;
734 (struct _catset *)rmalloc((catd->_hd->_setmax + 1) *
735 sizeof(struct _catset));
736 if (catd->_set == NULL)
738 if (make_sets(catd) == -1)
747 add_open_cat(nl_catd catd)
748 /*---- catd to be added to the list of catalogs ----*/
750 int i = 0; /*---- Misc counter(s) used for loops ----*/
751 while (i < NL_MAXOPEN && catsopen[i]) {
752 if (!strcmp(catd->_name, catsopen[i]->_name)
753 #ifndef AFS_OSF20_ENV
754 && getpid() == catsopen[i]->_pid)
758 return; /*---- The catalog is already here ----*/
762 if (i < NL_MAXOPEN) {
764 catpid[i] = getpid();
773 * FUNCTION: Expands the compacted version of the catalog index table into
774 * the fast access memory version.
776 * EXECUTION ENVIRONMENT:
778 * Make_set executes under a process.
785 make_sets(nl_catd catd)
787 struct _catset *cset;
788 char *base = catd->_mem;
789 int n_sets = catd->_hd->_n_sets;
790 int i; /*---- Misc counter(s) used for loops ----*/
791 int j; /*---- Misc counter(s) used for loops ----*/
792 int msgmax; /*---- The maximum number of _messages in a set ----*/
793 char *cmpct_set_ptr; /*---- pointer into the index table ----*/
794 struct _catset cs; /*---- used to look at the sets in the table -*/
797 cmpct_set_ptr = base + sizeof(struct _header);
799 for (i = 0; i < n_sets; i++) {
800 /* loop through each compacted set */
802 cs = *(struct _catset *)cmpct_set_ptr;
803 /* set the _catset ptr to the base of the current
807 (struct _msgptr *)(cmpct_set_ptr + 2 * sizeof(unsigned short));
808 /* set the ms array ptr to the base of
809 * compacted array of _msgptr's */
812 (catd->_sets_expanded) ? &catd->_set[cs._setno] : &catd->_set[i];
815 * If there aren't many holes in the message numbers,
816 * fully expand the compacted message array from the
817 * catalog. Then in catgets(), we'll be able to use
818 * the message number to index directly into the
821 * If there are many holes, leave the message array
822 * compacted. In catgets(), we'll search through it
823 * for the requested message.
826 msgmax = cs._mp[cs._n_msgs - 1]._msgno;
827 num_holes = msgmax - cs._n_msgs;
828 if (!TOO_MANY_HOLES(num_holes, cs._n_msgs)) {
829 cset->_msgs_expanded = TRUE;
830 cset->_n_msgs = msgmax;
832 cset->_msgs_expanded = FALSE;
833 cset->_n_msgs = cs._n_msgs - 1;
837 (struct _msgptr *)rmalloc((1 + cset->_n_msgs) *
838 sizeof(struct _msgptr));
839 if (cset->_mp == NULL)
843 (char **)rmalloc((1 + cset->_n_msgs) * sizeof(char *));
844 if (cset->_msgtxt == NULL)
847 if (cset->_msgs_expanded) {
848 for (j = 0; j < cs._n_msgs; j++) {
849 cset->_mp[cs._mp[j]._msgno] = cs._mp[j];
852 for (j = 0; j < cs._n_msgs; j++) {
853 cset->_mp[j] = cs._mp[j];
857 cset->_setno = cs._setno;
858 /* Superfluous but should have the correct data. Increment
859 * the base of the set pointer. */
862 2 * sizeof(unsigned short) + cs._n_msgs * sizeof(struct _msgptr);
873 * FUNCTION: Opens a catalog file, looking in the language path first (if
874 * there is no slash) and returns a pointer to the file stream.
876 * EXECUTION ENVIRONMENT:
878 * Opencatfile executes under a process.
880 * RETURNS: Returns a pointer to the file stream, and a NULL pointer on
885 open1catfile(char *file)
887 extern char *getenv();
888 char fl[PATH_MAX]; /*---- place to hold full path ----*/
889 char *nlspath; /*---- pointer to the nlspath val ----*/
890 FILE *fp; /*---- file pointer ----*/
891 char cpth[PATH_MAX]; /*---- current value of nlspath ----*/
893 char *fulllang; /* %L language value */
894 char lang[PATH_MAX]; /* %l language value */
895 char *territory; /* %t language value */
896 char *codeset; /* %c language value */
897 char *ptr; /* for decompose of $LANG */
902 char outptr[PATH_MAX];
905 if (strchr(file, '/')) {
906 if ((fp = fopen(file, "r"))) {
907 fcntl(fileno(fp), F_SETFD, 1);
908 /* set the close-on-exec flag for
913 if (!(nlspath = getenv("NLSPATH")))
914 nlspath = PATH_FORMAT;
915 if (!(fulllang = getenv("LANG")))
916 fulllang = DEFAULT_LANG;
917 if (fulllang == DEFAULT_LANG)
918 nlspath = PATH_FORMAT; /* if fullang is C, use the
919 * the default nlspath: */
922 ** LANG is a composite of three fields:
923 ** language_territory.codeset
924 ** and we're going to break it into those
928 strcpy(lang, fulllang);
933 ptr = strchr(lang, '_');
937 ptr = strchr(territory, '.');
943 ptr = strchr(lang, '.');
953 while (*np && *np != ':')
956 if (*np) /*---- iff on a colon then advance --*/
964 while (*ptr != '\0') {
965 while ((*ptr != '\0') && (*ptr != '%')
966 && (nchars < PATH_MAX)) {
967 *(optr++) = *(ptr++);
995 lenstr = strlen(str);
997 if (nchars < PATH_MAX) {
1005 if (nchars >= PATH_MAX) {
1011 strcpy(cpth, outptr);
1012 } else { /*---- iff leading | trailing |
1013 adjacent colons ... --*/
1017 if (valid == 1 && (fp = fopen(cpth, "r"))) {
1018 fcntl(fileno(fp), F_SETFD, 1);
1019 /* set the close-on-exec flag for
1024 if (fp = fopen(file, "r")) {
1025 fcntl(fileno(fp), F_SETFD, 1);
1026 /* set the close-on-exec flag for
1040 * NAME: cat_already_open
1042 * FUNCTION: Checkes to see if a specific cat has already been opened.
1044 * EXECUTION ENVIRONMENT:
1046 * Cat_already_open executes under a process.
1048 * RETURNS: Returns a pointer to the existing CATD if one exists, and
1049 * a NULL pointer if no CATD exists.
1053 cat_already_open(char *cat)
1054 /*---- name of the catalog to be opened ----*/
1056 int i; /*---- Misc counter(s) used for loops ----*/
1058 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1059 #ifndef AFS_OSF20_ENV
1060 if (!strcmp(cat, catsopen[i]->_name) && getpid() == catsopen[i]->_pid) {
1062 if (!strcmp(cat, catsopen[i]->_name)) {
1064 return (catsopen[i]);
1072 catclose1(nl_catd catd)
1073 /*---- the catd to be closed ----*/
1078 if (catd == CATD_ERR)
1080 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1081 #ifndef AFS_OSF20_ENV
1082 if (catd == catsopen[i] && getpid() == catsopen[i]->_pid)
1084 if (catd == catsopen[i])
1088 if (i == NL_MAXOPEN || catsopen[i] == NULL)
1090 if (catd->_fd == (FILE *) NULL)
1091 /*---- return if this is an extra open or
1092 a bad catalog discriptor ----*/
1094 if (cat_already_open(catd->_name)) {
1095 if (catd->_count == 1) {
1096 cat_hard_close(catd);
1097 return (0); /*--- the last legal clsoe ---*/
1098 } else if (catd->_count > 1) {
1099 catd->_count = catd->_count - 1;
1100 return (0); /*--- a legal close ---*/
1102 return (-1); /*--- an extra illegal close ---*/
1109 cat_hard_close(nl_catd catd)
1110 /*---- the catd to be closed ----*/
1112 int i; /*---- Misc counter(s) used for loops ----*/
1113 int j; /*---- Misc counter ----*/
1115 if (catd == CATD_ERR)
1118 /*______________________________________________________________________
1119 remove any entry for the catalog in the catsopen array
1120 ______________________________________________________________________*/
1122 for (i = 0; i < NL_MAXOPEN && catsopen[i]; i++) {
1123 if (catd == catsopen[i]) {
1124 for (; i < NL_MAXOPEN - 1; i++) {
1125 catsopen[i] = catsopen[i + 1];
1126 catpid[i] = catpid[i + 1];
1133 /*______________________________________________________________________
1134 close the cat and free up the memory
1135 ______________________________________________________________________*/
1136 if (catd->_mem == FALSE) {
1137 for (i = 0; i <= catd->_n_sets; i++) {
1138 if (catd->_set[i]._mp)
1139 free(catd->_set[i]._mp);
1140 /*---- free the _message pointer arrays ----*/
1142 if (catd->_set[i]._msgtxt) {
1143 for (j = 0; j <= catd->_set[i]._n_msgs; j++) {
1144 if (catd->_set[i]._msgtxt[j]) {
1145 /* free(catd->_set[i]._msgtxt[j]);*/
1148 if (catd->_set[i]._msgtxt)
1149 free(catd->_set[i]._msgtxt);
1155 fclose(catd->_fd); /*---- close the ctatlog ----*/
1157 free(catd->_set); /*---- free the sets ----*/
1159 free(catd->_name); /*---- free the name ----*/
1161 free(catd->_hd); /*---- free the header ----*/
1163 free(catd); /*---- free the catd ----*/
1167 _do1_read_msg(nl_catd catd, int setno, int msgno)
1168 /*---- catd: the catd of the catalog to be read from ----*/
1169 /*---- setno: the set number of the message ----*/
1170 /*---- msgno: the msgno of the message ----*/
1172 nl_catd catd1; /*--- catd for different process ----*/
1175 #ifndef AFS_OSF20_ENV
1176 if (getpid() == catd->_pid)
1180 return (_read1_msg(catd, setno, msgno));
1183 * Since our pid is different from the one in
1184 * catd, catd must have come from a catopen()
1185 * in our parent. We need a catd of our own.
1186 * The first time through here, the call to
1187 * catopen() creates a new catd and we try to
1188 * open its message catalog. After that, the
1189 * catopen() just retrieves the catd.
1191 if (((catd1 = catopen1(catd->_name, 0)) != CATD_ERR)
1192 && ((catd1->_fd == NL_FILE_CLOSED && _do1_open(catd1) != CATD_ERR)
1193 || (catd1->_fd != NL_FILE_UNUSED)))
1194 return (_read1_msg(catd1, setno, msgno));
1201 struct _catset *_cat1_get_catset();
1202 static struct _msgptr *_cat1_get_msgptr();
1204 _read1_msg(nl_catd catd, int setno, int msgno)
1206 struct _catset *set; /*--- ptr to set's _catset structure ---*/
1207 struct _msgptr *msg; /*--- ptr to msg's _msgptr structure ---*/
1208 char **msgtxt; /*--- temporary pointer to the message text
1211 set = _cat1_get_catset(catd, setno);
1213 msg = _cat1_get_msgptr(set, msgno);
1215 msgtxt = &set->_msgtxt[msg - set->_mp];
1216 if (1 /*!*msgtxt */ ) {
1217 *msgtxt = (char *)malloc(msg->_msglen + 1);
1221 fseek(catd->_fd, (long)msg->_offset, 0);
1223 ((void *)*msgtxt, (size_t) (msg->_msglen + 1), (size_t) 1,
1235 * NAME: compare_sets
1237 * FUNCTION: Compare function used by bsearch() in _cat_get_catset().
1240 * key - pointer to set number we're searching for
1241 * element - pointer to current _catset structure
1243 * RETURNS: Returns -1, 0, or 1, depending on whether the set number
1244 * is less than, equal to, or greater than the set number of
1245 * the _catset structure.
1250 compare_sets(const void *key, const void *element)
1252 int *setno = (int *)key;
1253 struct _catset *set = (struct _catset *)element;
1255 if (*setno < set->_setno)
1257 if (*setno > set->_setno)
1265 * NAME: _cat_get_catset
1267 * FUNCTION: Find a set in the catd->_set array. Assumes that the
1268 * sets in the array are sorted by increasing set number.
1271 * catd - catalog descripter obtained from catopen()
1272 * setno - message catalogue set number
1274 * RETURNS: Returns a pointer to the set on success.
1275 * On any error, returns NULL.
1280 _cat1_get_catset(nl_catd catd, int setno)
1282 struct _catset *set;
1284 if ((catd == (nl_catd) NULL) || (catd == CATD_ERR))
1285 return (struct _catset *)NULL;
1287 if (catd->_sets_expanded) {
1288 if ((setno < 0) || (setno > catd->_n_sets))
1289 return (struct _catset *)NULL;
1291 set = &catd->_set[setno];
1294 * Catch empty elements in the array. They aren't
1298 if (set->_mp == (struct _msgptr *)NULL)
1299 return (struct _catset *)NULL;
1302 (struct _catset *)bsearch((void *)&setno, catd->_set,
1304 sizeof(struct _catset), compare_sets);
1307 * Since the sets are compacted, there aren't any
1308 * empty elements in the array to check for.
1317 * NAME: compare_msgs
1319 * FUNCTION: Compare function used by bsearch() in _cat_get_msgptr().
1322 * key - pointer to message number we're searching for
1323 * element - pointer to current _msgptr structure
1325 * RETURNS: Returns -1, 0, or 1, depending on whether the message
1326 * number is less than, equal to, or greater than the message
1327 * number of the _msgptr structure.
1332 compare_msgs(const void *key, const void *element)
1334 int *msgno = (int *)key;
1335 struct _msgptr *msg = (struct _msgptr *)element;
1337 if (*msgno < msg->_msgno)
1339 if (*msgno > msg->_msgno)
1346 * NAME: _cat1_get_msgptr
1348 * FUNCTION: Find a message in a set's set->_mp array. Assumes that
1349 * the messages in the array are sorted by increasing
1353 * set - ptr to _catset structure
1354 * msgno - message catalogue message number
1356 * RETURNS: Returns a pointer to the message on success.
1357 * On any error, returns NULL.
1360 static struct _msgptr *
1361 _cat1_get_msgptr(struct _catset *set, int msgno)
1363 struct _msgptr *msg;
1365 if (set == (struct _catset *)NULL)
1366 return (struct _msgptr *)NULL;
1368 if (set->_mp == (struct _msgptr *)NULL) /* empty set */
1369 return (struct _msgptr *)NULL;
1371 if (set->_msgs_expanded) {
1372 if ((msgno < 0) || (msgno > set->_n_msgs))
1373 return (struct _msgptr *)NULL;
1375 msg = &set->_mp[msgno];
1378 * Catch empty elements in the array. They aren't
1383 return (struct _msgptr *)NULL;
1386 (struct _msgptr *)bsearch((void *)&msgno, set->_mp,
1388 sizeof(struct _msgptr), compare_msgs);
1391 * Since the messages are compacted, there aren't any
1392 * empty elements in the array to check for.
1400 catgets1(nl_catd catd, int setno, int msgno, char *def)
1401 /*---- catd: the catd to get the message from ----*/
1402 /*---- setno: the set number of the message ----*/
1403 /*---- msgno: the message number of the message ----*/
1404 /*---- def: the default string to be returned ----*/
1407 char *_do_read_msg();
1411 if (catd == NULL || catd == CATD_ERR || catd->_magic != CAT_MAGIC
1412 || catd->_fd == NL_FILE_UNUSED) {
1415 if (catd->_fd == NL_FILE_CLOSED) {
1416 catd = _do1_open(catd);
1417 if (catd == CATD_ERR)
1421 if (catd->_mem) { /*---- for mapped files ----*/
1422 if (setno <= catd->_hd->_setmax) {
1423 if (msgno < catd->_set[setno]._n_msgs) {
1424 if (catd->_set[setno]._mp[msgno]._offset) {
1425 return (catd->_mem +
1426 catd->_set[setno]._mp[msgno]._offset);
1431 } else { /*---- for unmapped files ----*/
1432 m = _do1_read_msg(catd, setno, msgno);
1442 #define FACILITY_CODE_MASK 0xF0000000
1443 #define FACILITY_CODE_SHIFT 28
1445 #define COMPONENT_CODE_MASK 0x0FFFF000
1446 #define COMPONENT_CODE_SHIFT 12
1448 #define STATUS_CODE_MASK 0x00000FFF
1449 #define STATUS_CODE_SHIFT 0
1451 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
1454 * The system-dependant location for the catalog files is defined in sysconf.h
1455 * RPC_DEFAULT_NLSPATH should be defined in sysconf.h. Otherwise we use
1456 * /usr/afs/etc/C/%s.cat
1459 #ifndef RPC_NLS_FORMAT
1460 #define RPC_NLS_FORMAT "%s.cat"
1464 dce1_error_inq_text(afs_uint32 status_to_convert,
1465 char *error_text, int *status)
1467 unsigned short facility_code;
1468 unsigned short component_code;
1469 unsigned short status_code;
1470 unsigned short i, failed = 0;
1472 char component_name[4];
1473 char *facility_name;
1474 char filename_prefix[7];
1475 char nls_filename[11];
1476 char alt_filename[80];
1478 #if defined(AFS_64BITPOINTER_ENV)
1483 static char *facility_names[] = {
1489 * set up output status for future error returns
1491 if (status != NULL) {
1495 * check for ok input status
1497 if (status_to_convert == 0) {
1498 if (status != NULL) {
1501 strcpy((char *)error_text, "successful completion");
1506 * extract the component, facility and status codes
1509 (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
1511 (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
1512 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
1515 * see if this is a recognized facility
1517 if (facility_code == 0
1518 || facility_code > sizeof(facility_names) / sizeof(char *)) {
1519 sprintf((char *)error_text, "status %08x (unknown facility)",
1523 facility_name = facility_names[facility_code - 1];
1525 * Convert component name from RAD-50 component code. (Mapping is:
1526 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
1528 component_name[3] = 0;
1529 component_name[2] = component_code % 40;
1530 component_code /= 40;
1531 component_name[1] = component_code % 40;
1532 component_name[0] = component_code / 40;
1533 for (i = 0; i < 3; i++) {
1534 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
1536 sprintf(filename_prefix, "%3s%3s", facility_name, component_name);
1537 sprintf(nls_filename, RPC_NLS_FORMAT, filename_prefix);
1540 * Open the message file
1542 #if defined(AFS_OSF_ENV)
1543 #if defined(AFS_OSF20_ENV)
1544 catd = (nl_catd) catopen(nls_filename, 0);
1546 catd = (nl_catd) catopen1(nls_filename, 0);
1549 #if defined(AFS_64BITPOINTER_ENV)
1550 J = (long)catopen(nls_filename, 0);
1552 J = (int)catopen(nls_filename, 0);
1556 if (catd == (nl_catd) - 1) {
1558 * If we did not succeed in opening message file using NLSPATH,
1559 * try to open the message file in a well-known default area
1562 #ifndef RPC_DEFAULT_NLSPATH
1563 sprintf(alt_filename, "%s/C/%s.cat", AFSDIR_CLIENT_ETC_DIRPATH,
1566 sprintf(alt_filename, RPC_DEFAULT_NLSPATH, filename_prefix);
1569 #if defined(AFS_OSF_ENV)
1570 #if defined(AFS_OSF20_ENV)
1571 catd = (nl_catd) catopen(alt_filename, 0);
1573 catd = (nl_catd) catopen1(alt_filename, 0);
1576 #if defined(AFS_64BITPOINTER_ENV)
1577 J = (long)catopen(alt_filename, 0);
1579 J = (int)catopen(alt_filename, 0);
1583 if (catd == (nl_catd) - 1) {
1584 sprintf((char *)error_text, "status %08x (%s / %s)",
1585 status_to_convert, facility_name, component_name);
1590 * try to get the specified message from the file
1592 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1593 message = (char *)catgets1(catd, 1, status_code, NO_MESSAGE);
1595 message = (char *)catgets(catd, 1, status_code, NO_MESSAGE);
1598 * if everything went well, return the resulting message
1600 if (strcmp(message, NO_MESSAGE) != 0) {
1601 sprintf((char *)error_text, "%s (%s / %s)", message, facility_name,
1603 if (status != NULL) {
1609 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1616 sprintf((char *)error_text, "status %08x (%s / %s)",
1617 status_to_convert, facility_name, component_name);
1619 #if defined(AFS_OSF_ENV) && !defined(AFS_OSF20_ENV)
1628 icl_DumpKernel(FILE *outFilep, char *setname)
1630 afs_int32 bufferSize = 0;
1633 afs_int32 code, retVal = 0;
1638 afs_int32 dummy, dummy2;
1639 struct logInfo *lip;
1641 /* first, enumerate the logs we're interested in */
1644 /* dump logs for a particular set */
1645 for (i = 0; i < ICL_LOGSPERSET; i++) {
1647 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname,
1648 i, (long)tname, sizeof(tname), 0, 0);
1650 if (errno == EBADF) {
1652 continue; /* missing slot, nothing to worry about */
1657 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1658 (long)&dummy, (long)&dummy2, 0, 0, 0);
1662 if (dummy > bufferSize) /* find biggest log */
1664 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
1665 memset((char *)lip, 0, sizeof(*lip));
1666 lip->nextp = allInfo;
1668 lip->name = (char *)malloc(strlen(tname) + 1);
1669 strcpy(lip->name, tname);
1674 for (i = 0; i < 1000; i++) {
1676 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
1677 sizeof(tname), (long)&dummy, 0, 0);
1680 if (dummy > bufferSize) /* find biggest log */
1682 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
1683 memset((char *)lip, 0, sizeof(*lip));
1684 lip->nextp = allInfo;
1686 lip->name = (char *)malloc(strlen(tname) + 1);
1687 strcpy(lip->name, tname);
1691 if (bufferSize == 0)
1693 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1697 fprintf(outFilep, "Found %d logs.\n", i);
1699 /* now print out the contents of each log */
1700 for (lip = allInfo; lip; lip = lip->nextp) {
1701 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
1702 /* read out everything first; gets a more consistent
1705 nwords = 0; /* total words copied out */
1707 /* display all the entries in the log */
1708 if (bufferSize - nwords <= 0)
1709 break; /* filled whole buffer */
1711 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name,
1712 (long)(bufferp + nwords), bufferSize - nwords,
1715 /* otherwise we've got an error */
1716 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
1719 /* otherwise, we have flags in the high order byte, and
1720 * a length (in words) in the remainder.
1722 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
1723 fprintf(outFilep, "Log wrapped; data missing.\n");
1731 } /* for loop over all cookies */
1733 /* otherwise we should display all of the log entries here.
1734 * Note that a record may end in the middle, in which case
1735 * we should start over with the cookie value of the start
1738 for (ix = 0; ix < nwords;) {
1739 /* start of a record */
1740 rlength = (bufferp[ix] >> 24) & 0xff;
1742 fprintf(outFilep, "Internal error: 0 length record\n");
1746 /* ensure that entire record fits */
1747 if (ix + rlength > nwords) {
1748 /* doesn't fit, adjust cookie and break */
1751 /* print the record */
1752 DisplayRecord(outFilep, &bufferp[ix], rlength);
1755 /* obsolete: read entire buffer first */
1756 i += rlength; /* update cookie value, too */
1758 } /* for loop displaying buffer */
1759 } /* for loop over all logs */
1766 /* clear out log 'name' */
1768 icl_ClearLog(char *name)
1772 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0, 0, 0);
1776 /* clear out set 'name' */
1778 icl_ClearSet(char *name)
1782 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0, 0, 0);
1786 /* clear out all logs */
1792 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0, 0, 0);
1796 /* list out all available sets to outFileP */
1798 icl_ListSets(FILE *outFileP)
1805 for (i = 0; i < 1000; i++) {
1807 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname,
1808 sizeof(tname), (long)&states, 0, 0);
1811 (void)fprintf(outFileP, "%s %s%s%s\n", tname,
1812 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
1813 (states & ICL_SETF_FREED) ? " (dormant)" : "",
1814 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
1820 /* list out all available logs to outFileP */
1822 icl_ListLogs(FILE *outFileP, int int32flg)
1830 for (i = 0; i < 1000; i++) {
1832 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
1833 sizeof(tname), (long)&logSize, 0, 0);
1837 /* get more information on the log */
1839 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1840 (long)&logSize, (long)&allocated, 0, 0, 0);
1843 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
1845 allocated ? "allocated" : "unallocated");
1847 (void)fprintf(outFileP, "%s\n", tname);
1853 /* list out all available logs to outFileP */
1855 icl_ListLogsBySet(FILE *outFileP, char *setname, int int32flg)
1863 for (i = 0; i < ICL_LOGSPERSET; i++) {
1865 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i,
1866 (long)tname, sizeof(tname), 0, 0);
1868 if (errno == EBADF) {
1870 continue; /* missing */
1875 /* get more information on the log */
1877 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
1878 (long)&logSize, (long)&allocated, 0, 0, 0);
1881 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
1883 allocated ? "allocated" : "unallocated");
1885 (void)fprintf(outFileP, "%s\n", tname);
1891 /* activate/deactivate/free specified set */
1893 icl_ChangeSetState(char *name, afs_int32 op)
1897 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0, 0, 0);
1901 /* activate/deactivate/free all sets */
1903 icl_ChangeAllSetState(afs_int32 op)
1907 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0, 0, 0);
1911 /* set size if log */
1913 icl_ChangeLogSize(char *name, afs_int32 logSize)
1918 afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0,
1923 /* get logsize of specified log */
1925 icl_GetLogsize(char *logname, afs_int32 *logSizeP, int *allocatedP)
1929 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1930 (long)logSizeP, (long)allocatedP, 0, 0, 0);
1934 /* get state of specified set */
1936 icl_GetSetState(char *setname, afs_int32 *stateP)
1940 afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname,
1941 (long)stateP, 0, 0, 0, 0);
1946 icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime)
1948 afs_int32 bufferSize = 0;
1949 afs_int32 newBufferSize;
1952 afs_int32 code, retVal = 0;
1958 /* get information about the specified log */
1960 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1961 (long)&bufferSize, (long)&allocated, 0, 0, 0);
1963 if (errno == ENOENT)
1964 (void)fprintf(stderr, "'%s' not found\n", logname);
1966 (void)fprintf(stderr,
1967 "cannot get information on log '%s' (errno = %d)\n",
1973 (void)fprintf(stderr, "'%s' not allocated\n", logname);
1977 if (bufferSize == 0)
1979 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1981 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1986 /* start "infinite" loop */
1988 /* read out all that's currently there */
1989 nwords = 0; /* total words copied out */
1990 i = 0; /* initialize cookie */
1992 /* display all the entries in the log */
1993 if (bufferSize - nwords <= 0)
1994 break; /* filled whole buffer, clear when done */
1996 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname,
1997 (long)(bufferp + nwords), bufferSize - nwords,
2000 /* otherwise we've got an error */
2001 fprintf(stderr, "returned error %d dumping log.\n", errno);
2005 /* otherwise, we have flags in the high order byte, and
2006 * a length (in words) in the remainder.
2015 } /* for loop over all cookies */
2017 /* otherwise we should display all of the log entries here.
2018 * Note that a record may end in the middle, in which case
2019 * we should start over with the cookie value of the start
2022 for (ix = 0; ix < nwords;) {
2023 /* start of a record */
2024 rlength = (bufferp[ix] >> 24) & 0xff;
2025 /* ensure that entire record fits */
2026 if (ix + rlength > nwords) {
2027 /* doesn't fit, adjust cookie and break */
2029 fprintf(stderr, "BOGUS: 0 length record\n");
2035 /* print the record */
2036 DisplayRecord(outFilep, &bufferp[ix], rlength);
2038 } /* for loop displaying buffer */
2043 /* see if things have changed */
2045 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
2046 (long)&newBufferSize, (long)&allocated, 0, 0, 0);
2048 if (errno == ENOENT)
2049 (void)fprintf(stderr, "'%s' not found\n", logname);
2051 (void)fprintf(stderr,
2052 "cannot get information on log '%s' (errno = %d)\n",
2059 (void)fprintf(stderr, "'%s' no int32er allocated\n", logname);
2064 if (bufferSize == 0) {
2065 (void)fprintf(stderr, "buffer size has become 0\n");
2069 if (bufferSize != newBufferSize) {
2070 /* have to reallocate a buffer */
2071 bufferSize = newBufferSize;
2073 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
2075 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
2081 } /* infinite loop */
2088 #if !defined(AFS_SGI_ENV)
2090 afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
2091 long parm4, long parm5, long parm6)
2094 #ifdef AFS_LINUX20_ENV
2095 #if defined AFS_LINUX_64BIT_KERNEL
2097 /* don't want to sign extend it to 64bit, so using ulong */
2098 eparm[0] = (unsigned long)parm3;
2099 eparm[1] = (unsigned long)parm4;
2100 eparm[2] = (unsigned long)parm5;
2101 eparm[3] = (unsigned long)parm6;
2109 /* Linux can only handle 5 arguments in the actual syscall. */
2110 if (call == AFSCALL_ICL) {
2111 rval = proc_afs_syscall(call, parm0, parm1, parm2, eparm, &code);
2113 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
2115 rval = proc_afs_syscall(call, parm0, parm1, parm2, parm3, &code);
2117 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
2119 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
2120 /* on sparc this function returns none value, so do it myself */
2121 __asm__ __volatile__("mov %o0, %i0; ret; restore");
2124 #ifdef AFS_DARWIN80_ENV
2125 code = ioctl_afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, &rval);
2126 if (!code) code = rval;
2128 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
2129 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
2131 #if defined(AFS_SGI_ENV)
2132 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
2134 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
2138 #endif /* AFS_LINUX20_ENV */
2146 /* init function, called once, under icl_lock */
2153 /* setup signal handler, in user space */
2160 icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
2161 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
2163 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0,
2167 /* create a set, given pointers to base and fatal logs, if any.
2168 * Logs are unlocked, but referenced, and *outSetpp is returned
2169 * referenced. Function bumps reference count on logs, since it
2170 * addds references from the new icl_set. When the set is destroyed,
2171 * those references will be released.
2174 icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
2175 struct afs_icl_log *fatalLogp, afs_uint32 flags,
2176 struct afs_icl_set **outSetpp)
2178 register struct afs_icl_set *setp;
2180 afs_int32 states = ICL_DEFAULT_SET_STATES;
2185 for (setp = icl_allSets; setp; setp = setp->nextp) {
2186 if (strcmp(setp->name, name) == 0) {
2189 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
2190 setp->states |= ICL_SETF_PERSISTENT;
2196 /* determine initial state */
2197 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
2198 states = ICL_SETF_ACTIVE;
2199 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
2200 states = ICL_SETF_FREED;
2201 if (flags & ICL_CRSET_FLAG_PERSISTENT)
2202 states |= ICL_SETF_PERSISTENT;
2204 setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set));
2205 memset((caddr_t) setp, 0, sizeof(*setp));
2207 if (states & ICL_SETF_FREED)
2208 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
2209 setp->states = states;
2211 setp->name = (char *)osi_Alloc(strlen(name) + 1);
2212 strcpy(setp->name, name);
2213 setp->nevents = ICL_DEFAULTEVENTS;
2214 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
2215 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
2216 setp->eventFlags[i] = 0xff; /* default to enabled */
2218 /* update this global info under the icl_lock */
2219 setp->nextp = icl_allSets;
2222 /* set's basic lock is still held, so we can finish init */
2224 setp->logs[0] = baseLogp;
2225 icl_LogHold(baseLogp);
2226 if (!(setp->states & ICL_SETF_FREED))
2227 icl_LogUse(baseLogp); /* log is actually being used */
2230 setp->logs[1] = fatalLogp;
2231 icl_LogHold(fatalLogp);
2232 if (!(setp->states & ICL_SETF_FREED))
2233 icl_LogUse(fatalLogp); /* log is actually being used */
2240 /* function to change event enabling information for a particular set */
2242 icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
2246 if (!ICL_EVENTOK(setp, eventID)) {
2249 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
2251 *tp |= ICL_EVENTMASK(eventID);
2253 *tp &= ~(ICL_EVENTMASK(eventID));
2257 /* return indication of whether a particular event ID is enabled
2258 * for tracing. If *getValuep is set to 0, the event is disabled,
2259 * otherwise it is enabled. All events start out enabled by default.
2262 icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
2264 if (!ICL_EVENTOK(setp, eventID)) {
2267 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
2274 /* hold and release event sets */
2276 icl_SetHold(register struct afs_icl_set *setp)
2282 /* free a set. Called with icl_lock locked */
2284 icl_ZapSet(register struct afs_icl_set *setp)
2286 register struct afs_icl_set **lpp, *tp;
2288 register struct afs_icl_log *tlp;
2290 for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2292 /* found the dude we want to remove */
2294 osi_Free(setp->name, 1 + strlen(setp->name));
2295 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
2296 for (i = 0; i < ICL_LOGSPERSET; i++) {
2297 if ((tlp = setp->logs[i]))
2300 osi_Free(setp, sizeof(struct afs_icl_set));
2301 break; /* won't find it twice */
2307 /* do the release, watching for deleted entries */
2309 icl_SetRele(register struct afs_icl_set *setp)
2311 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
2312 icl_ZapSet(setp); /* destroys setp's lock! */
2317 /* free a set entry, dropping its reference count */
2319 icl_SetFree(register struct afs_icl_set *setp)
2321 setp->states |= ICL_SETF_DELETED;
2326 /* find a set by name, returning it held */
2327 struct afs_icl_set *
2328 icl_FindSet(char *name)
2330 register struct afs_icl_set *tp;
2332 for (tp = icl_allSets; tp; tp = tp->nextp) {
2333 if (strcmp(tp->name, name) == 0) {
2334 /* this is the dude we want */
2342 /* zero out all the logs in the set */
2344 icl_ZeroSet(struct afs_icl_set *setp)
2349 struct afs_icl_log *logp;
2351 for (i = 0; i < ICL_LOGSPERSET; i++) {
2352 logp = setp->logs[i];
2355 tcode = icl_ZeroLog(logp);
2357 code = tcode; /* save the last bad one */
2365 icl_EnumerateSets(int (*aproc) (char *, void *, struct afs_icl_set *),
2368 register struct afs_icl_set *tp, *np;
2369 register afs_int32 code;
2372 for (tp = icl_allSets; tp; tp = np) {
2373 tp->refCount++; /* hold this guy */
2374 code = (*aproc) (tp->name, arock, tp);
2375 np = tp->nextp; /* tp may disappear next, but not np */
2376 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
2385 icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
2390 for (i = 0; i < ICL_LOGSPERSET; i++) {
2391 if (!setp->logs[i]) {
2392 setp->logs[i] = newlogp;
2394 icl_LogHold(newlogp);
2395 if (!(setp->states & ICL_SETF_FREED)) {
2396 /* bump up the number of sets using the log */
2397 icl_LogUse(newlogp);
2406 icl_SetSetStat(struct afs_icl_set *setp, int op)
2410 struct afs_icl_log *logp;
2413 case ICL_OP_SS_ACTIVATE: /* activate a log */
2415 * If we are not already active, see if we have released
2416 * our demand that the log be allocated (FREED set). If
2417 * we have, reassert our desire.
2419 if (!(setp->states & ICL_SETF_ACTIVE)) {
2420 if (setp->states & ICL_SETF_FREED) {
2421 /* have to reassert desire for logs */
2422 for (i = 0; i < ICL_LOGSPERSET; i++) {
2423 logp = setp->logs[i];
2430 setp->states &= ~ICL_SETF_FREED;
2432 setp->states |= ICL_SETF_ACTIVE;
2437 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
2438 /* this doesn't require anything beyond clearing the ACTIVE flag */
2439 setp->states &= ~ICL_SETF_ACTIVE;
2443 case ICL_OP_SS_FREE: /* deassert design for log */
2445 * if we are already in this state, do nothing; otherwise
2446 * deassert desire for log
2448 if (setp->states & ICL_SETF_ACTIVE)
2451 if (!(setp->states & ICL_SETF_FREED)) {
2452 for (i = 0; i < ICL_LOGSPERSET; i++) {
2453 logp = setp->logs[i];
2456 icl_LogFreeUse(logp);
2460 setp->states |= ICL_SETF_FREED;
2473 struct afs_icl_log *afs_icl_allLogs = 0;
2475 /* hold and release logs */
2477 icl_LogHold(register struct afs_icl_log *logp)
2483 /* hold and release logs, called with lock already held */
2485 icl_LogHoldNL(register struct afs_icl_log *logp)
2491 /* keep track of how many sets believe the log itself is allocated */
2493 icl_LogUse(register struct afs_icl_log *logp)
2495 if (logp->setCount == 0) {
2496 /* this is the first set actually using the log -- allocate it */
2497 if (logp->logSize == 0) {
2498 /* we weren't passed in a hint and it wasn't set */
2499 logp->logSize = ICL_DEFAULT_LOGSIZE;
2502 (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
2508 /* decrement the number of real users of the log, free if possible */
2510 icl_LogFreeUse(register struct afs_icl_log *logp)
2512 if (--logp->setCount == 0) {
2513 /* no more users -- free it (but keep log structure around) */
2514 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2515 logp->firstUsed = logp->firstFree = 0;
2516 logp->logElements = 0;
2522 /* set the size of the log to 'logSize' */
2524 icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
2527 /* nothing to worry about since it's not allocated */
2528 logp->logSize = logSize;
2531 logp->firstUsed = logp->firstFree = 0;
2532 logp->logElements = 0;
2534 /* free and allocate a new one */
2535 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
2536 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
2537 logp->logSize = logSize;
2543 /* free a log. Called with icl_lock locked. */
2545 icl_ZapLog(register struct afs_icl_log *logp)
2547 register struct afs_icl_log **lpp, *tp;
2549 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
2551 /* found the dude we want to remove */
2553 osi_Free(logp->name, 1 + strlen(logp->name));
2554 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
2555 osi_Free(logp, sizeof(struct icl_log));
2556 break; /* won't find it twice */
2562 /* do the release, watching for deleted entries */
2564 icl_LogRele(register struct afs_icl_log *logp)
2566 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2567 icl_ZapLog(logp); /* destroys logp's lock! */
2572 /* do the release, watching for deleted entries, log already held */
2574 icl_LogReleNL(register struct afs_icl_log *logp)
2576 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
2577 icl_ZapLog(logp); /* destroys logp's lock! */
2582 /* zero out the log */
2584 icl_ZeroLog(register struct afs_icl_log *logp)
2586 logp->firstUsed = logp->firstFree = 0;
2587 logp->logElements = 0;
2591 /* free a log entry, and drop its reference count */
2593 icl_LogFree(register struct afs_icl_log *logp)
2595 logp->states |= ICL_LOGF_DELETED;
2602 icl_EnumerateLogs(int (*aproc)
2603 (char *name, void *arock, struct afs_icl_log * tp),
2606 register struct afs_icl_log *tp;
2607 register afs_int32 code;
2610 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
2611 tp->refCount++; /* hold this guy */
2612 code = (*aproc) (tp->name, arock, tp);
2613 if (--tp->refCount == 0)
2622 afs_icl_bulkSetinfo_t *
2623 GetBulkSetInfo(void)
2625 unsigned int infoSize;
2628 sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
2629 1) * sizeof(afs_icl_setinfo_t);
2631 setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize);
2633 (void)fprintf(stderr,
2634 "Could not allocate the memory for bulk set info structure\n");
2638 memset((char *)setInfo, 0, infoSize);
2643 afs_icl_bulkLoginfo_t *
2644 GetBulkLogInfo(void)
2646 unsigned int infoSize;
2649 sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
2650 1) * sizeof(afs_icl_loginfo_t);
2652 logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize);
2654 (void)fprintf(stderr,
2655 "Could not allocate the memory for bulk log info structure\n");
2660 memset((char *)logInfo, 0, infoSize);
2666 DoDump(struct cmd_syndesc *as, void *arock)
2670 afs_int32 waitTime = 10 /* seconds */ ;
2672 FILE *outfp = stdout;
2674 struct cmd_item *itemp;
2676 if (geteuid() != 0) {
2677 printf("fstrace must be run as root\n");
2681 if (as->parms[3].items) {
2682 if (!as->parms[1].items) {
2683 (void)fprintf(stderr, "-sleep can only be used with -follow\n");
2686 waitTime = strtol(as->parms[3].items->data, NULL, 0);
2689 if (as->parms[2].items) {
2690 /* try to open the specified output file */
2691 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) {
2692 (void)fprintf(stderr, "Cannot open file '%s' for writing\n",
2693 as->parms[2].items->data);
2697 #ifdef AFS_SGI64_ENV
2698 startTime = time((time_t *) 0);
2700 startTime = time(0);
2702 (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
2705 if (as->parms[0].items) {
2706 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2707 tcode = icl_DumpKernel(outfp, itemp->data);
2709 (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
2710 itemp->data, errno);
2714 } else if (as->parms[1].items) {
2715 logname = as->parms[1].items->data;
2716 code = icl_TailKernel(outfp, logname, waitTime);
2718 (void)fprintf(stderr,
2719 "Error tailing kernel log '%s' (errno = %d)\n",
2723 code = icl_DumpKernel(outfp, NULL);
2725 (void)fprintf(outfp, "\nAFS Trace Dump - %s\n",
2726 code ? "FAILED" : "Completed");
2728 if (outfp != stdout)
2729 (void)fclose(outfp);
2737 struct cmd_syndesc *dumpSyntax;
2740 cmd_CreateSyntax("dump", DoDump, NULL, "dump AFS trace logs");
2741 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2742 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL,
2744 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL,
2746 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL,
2747 "seconds_between_reads");
2751 DoShowLog(register struct cmd_syndesc *as, void *arock)
2753 afs_int32 retVal = 0;
2758 struct cmd_item *itemp;
2760 if (geteuid() != 0) {
2761 printf("fstrace must be run as root\n");
2764 if (as->parms[2].items)
2767 if (as->parms[0].items) {
2768 /* enumerate logs for the specified sets */
2769 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2770 (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data);
2771 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
2773 (void)fprintf(stderr,
2774 "Error in enumerating set %s (errno = %d)\n",
2775 itemp->data, errno);
2779 } else if (as->parms[1].items) {
2780 /* print out log information */
2781 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
2782 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
2784 (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
2786 allocated ? "allocated" : "unallocated");
2788 (void)fprintf(stderr,
2789 "Could not find log '%s' (errno = %d)\n",
2790 itemp->data, errno);
2796 (void)fprintf(stdout, "Available logs:\n");
2797 code = icl_ListLogs(stdout, int32flg);
2799 (void)fprintf(stderr, "Error in listing logs (errno = %d)\n",
2811 struct cmd_syndesc *showSyntax;
2814 cmd_CreateSyntax("lslog", DoShowLog, NULL,
2815 "list available logs");
2816 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2817 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
2818 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL, "");
2822 DoShowSet(register struct cmd_syndesc *as, void *arock)
2824 afs_int32 retVal = 0;
2827 struct cmd_item *itemp;
2829 if (geteuid() != 0) {
2830 printf("fstrace must be run as root\n");
2833 if (as->parms[0].items) {
2834 /* print information on the specified sets */
2835 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2836 code = icl_GetSetState(itemp->data, &state);
2838 (void)fprintf(stderr,
2839 "Error getting status on set %s (errno = %d)\n",
2840 itemp->data, errno);
2843 (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
2844 (state & ICL_SETF_ACTIVE) ? "active" :
2846 (state & ICL_SETF_FREED) ? " (dormant)" : "",
2847 (state & ICL_SETF_PERSISTENT) ? " persistent" :
2852 (void)fprintf(stdout, "Available sets:\n");
2853 code = icl_ListSets(stdout);
2855 (void)fprintf(stderr, "Error in listing sets (errno = %d)\n",
2867 struct cmd_syndesc *showSyntax;
2870 cmd_CreateSyntax("lsset", DoShowSet, NULL,
2871 "list available event sets");
2872 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2876 DoClear(register struct cmd_syndesc *as, void *arock)
2878 afs_int32 retVal = 0;
2880 struct cmd_item *itemp;
2882 if (geteuid() != 0) {
2883 printf("fstrace must be run as root\n");
2886 if (as->parms[0].items) {
2887 /* clear logs for the specified sets */
2888 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2889 code = icl_ClearSet(itemp->data);
2891 (void)fprintf(stderr,
2892 "Error in clearing set %s (errno = %d)\n",
2893 itemp->data, errno);
2897 } else if (as->parms[1].items) {
2898 /* clear specified log */
2899 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2900 code = icl_ClearLog(itemp->data);
2902 (void)fprintf(stderr,
2903 "Error in clearing log %s (errno = %d)\n",
2904 itemp->data, errno);
2909 /* clear all logs */
2910 code = icl_ClearAll();
2912 (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n",
2924 struct cmd_syndesc *clearSyntax;
2927 cmd_CreateSyntax("clear", DoClear, NULL,
2928 "clear logs by logname or by event set");
2929 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
2931 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
2936 DoSet(register struct cmd_syndesc *as, void *arock)
2938 afs_int32 retVal = 0;
2943 struct cmd_item *itemp;
2945 if (geteuid() != 0) {
2946 printf("fstrace must be run as root\n");
2949 if (as->parms[1].items) {
2950 op = ICL_OP_SS_ACTIVATE;
2951 operation = "active";
2952 } else if (as->parms[2].items) {
2953 op = ICL_OP_SS_DEACTIVATE;
2954 operation = "inactive";
2955 } else if (as->parms[3].items) {
2956 op = ICL_OP_SS_DEACTIVATE;
2957 operation = "inactive";
2960 /* assume active" */
2961 op = ICL_OP_SS_ACTIVATE;
2962 operation = "active";
2965 if (as->parms[0].items) {
2966 /* activate specified sets */
2967 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
2968 code = icl_ChangeSetState(itemp->data, op);
2970 (void)fprintf(stderr,
2971 "cannot set state of %s to %s (errno = %d)\n",
2972 itemp->data, operation, errno);
2974 } else if (doFree) {
2975 /* try to make it dormant as well */
2976 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2978 (void)fprintf(stderr,
2979 "cannot set state of %s to dormant (errno = %d)\n",
2980 itemp->data, errno);
2987 code = icl_ChangeAllSetState(op);
2989 (void)fprintf(stderr,
2990 "cannot set the state of all sets to %s (errno = %d)\n",
2993 } else if (doFree) {
2994 /* try to make it dormant as well */
2995 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2997 (void)fprintf(stderr,
2998 "cannot set the state of all sets to dormant (errno = %d)\n",
3011 struct cmd_syndesc *setSyntax;
3014 cmd_CreateSyntax("setset", DoSet, NULL,
3015 "set state of event sets");
3016 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
3017 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL, "");
3018 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
3019 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL, "");
3023 DoResize(register struct cmd_syndesc *as, void *arock)
3025 afs_int32 retVal = 0;
3027 afs_int32 bufferSize;
3028 struct cmd_item *itemp;
3030 if (geteuid() != 0) {
3031 printf("fstrace must be run as root\n");
3034 /* get buffer size */
3035 bufferSize = atoi(as->parms[1].items->data);
3036 bufferSize *= BUFFER_MULTIPLIER;
3037 if (bufferSize == 0)
3038 bufferSize = ICL_DEFAULT_LOGSIZE;
3040 /* set the size of the specified logs */
3041 if ((itemp = as->parms[0].items)) {
3042 for (; itemp; itemp = itemp->next) {
3043 code = icl_ChangeLogSize(itemp->data, bufferSize);
3045 (void)fprintf(stderr,
3046 "Error in changing log %s buffer size (errno = %d)\n",
3047 itemp->data, errno);
3052 /* Use the only current support log, "cmfx" */
3053 code = icl_ChangeLogSize("cmfx", bufferSize);
3055 (void)fprintf(stderr,
3056 "Error in changing log cmfx buffer size (errno = %d)\n",
3068 struct cmd_syndesc *setsizeSyntax;
3071 cmd_CreateSyntax("setlog", DoResize, NULL,
3072 "set the size of a log");
3073 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
3075 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED,
3076 "1-kilobyte_units");
3079 #include "AFS_component_version_number.c"
3082 main(int argc, char *argv[])
3084 setlocale(LC_ALL, "");
3085 #ifdef AFS_SGI62_ENV
3086 set_kernel_sizeof_long();
3089 /* set up user interface then dispatch */
3097 return (cmd_Dispatch(argc, argv));
3100 #include "AFS_component_version_number.c"
3103 main(int argc, char *argv[])
3105 printf("fstrace is NOT supported for this OS\n");