home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v3 / text0030.txt < prev    next >
Encoding:
Internet Message Format  |  1987-06-30  |  3.6 KB

  1. Date: Wed, 20 Nov 85 13:47:00 est
  2. From: seismo!cbpavo.cbosgd.ATT.UUCP!mark (Mark Horton)
  3.  
  4. After looking at the cc -E / sed approach to reading limits.h, I
  5. wanted to pass along a couple of other ideas.  (There are lots of
  6. UNIX systems out there that don't have C compilers on line, in
  7. particular, both Xenix and the AT&T 3B2 come without them until
  8. you add them in, and they take up enough cash and disk space that
  9. I'll bet many non-hackers won't install them.)
  10.  
  11. One idea is to do what netnews does to figure out the system name.
  12. I'll enclose the code at the end (the code is public domain)
  13. but basically it opens /usr/include/whoami.h and looks for a line
  14.     #define sysname "whatever"
  15. and extracts the "whatever".  It uses scanf, but hard code could be
  16. written to make this a bit faster and more robust.  It does depend
  17. on the full path name /usr/include/file.h, and it does expect the
  18. #define to be in a reasonably standard format, but these aren't
  19. overly cumbersome restrictions, are they?  (Dare we assume that
  20. /usr/include will be there on all systems, even those without
  21. compilers?)
  22.  
  23. Another idea is a bit more complex, but solves the "two copies of
  24. the information" problem while still keeping a non-C file like
  25. the proposed /etc/limits.  The idea is to keep a single copy in
  26. /etc/limits, and use the obvious subroutine to get the values for
  27. user code (which then has to malloc things.)  But the kernel has
  28. to know these numbers too, and it's not exactly reasonable for the
  29. kernel to go opening up a user file.  Perhaps a user program can be
  30. written that will read the file, and download it into the kernel
  31. with some kind of (system dependent) magic, such as poking in /dev/kmem,
  32. or a special ioctl, or whatever.  Then the kernel can malloc the
  33. appropriate data structures for the appropriate sizes.
  34.  
  35. This second idea has a chicken-and-egg problem, in that the data
  36. structures better be allocated EARLY, and the obvious place to do
  37. the downloading is /etc/rc, which is awfully late for such things.
  38. One possibility is for /etc/init to do this before it does much of
  39. anything else, although this is still probably too late (after all,
  40. it has to open the file, and this means the file table has to exist.
  41. Also, it's a process, so the process table must exist.)  One possibility
  42. for handling this is for the kernel to have a very small set of minimal
  43. tables to use until the real numbers come in, at which time it swings
  44. a new pointer to the new tables.  (This is getting pretty ugly, isn't it?)
  45.  
  46. A third possibility is for the kernel to use the limits.h file, but
  47. for /etc/rc to run a program that reads the values, translates them
  48. into an easily parsed format (possibly binary), and puts these values
  49. into /etc/limits.  Then the hard work is done only once per boot.
  50. This might make it hard to write programs like fsck that run single
  51. user, however.
  52.  
  53.     Mark
  54.  
  55. #define HDRFILE "/usr/include/whoami.h"
  56.  
  57. uname(uptr)
  58. struct utsname *uptr;
  59. {
  60.         char buf[BUFSIZ];
  61.         FILE *fd;
  62.          
  63.         fd = fopen(HDRFILE, "r");
  64.         if (fd == NULL) {
  65.                 fprintf(stderr, "Cannot open %s\n", HDRFILE);
  66.                 exit(1);
  67.         }
  68.          
  69.         for (;;) {      /* each line in the file */
  70.                 if (fgets(buf, sizeof buf, fd) == NULL) {
  71.                         fprintf(stderr, "no sysname in %s\n", HDRFILE);
  72.                         fclose(fd);
  73.                         exit(2);
  74.                 }
  75.                 if (sscanf(buf, "#define sysname \"%[^\"]\"", uptr->nodename) == 1) {
  76.                         fclose(fd);
  77.                         return;
  78.                 }
  79.         }
  80. }
  81.  
  82. Volume-Number: Volume 3, Number 32
  83.  
  84.