procps.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright 1998 by Albert Cahalan; all rights reserved.
  6. * Copyright (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
  7. * SELinux support: (c) 2007 by Yuichi Nakamura <ynakam@hitachisoft.jp>
  8. *
  9. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  10. */
  11. #include "libbb.h"
  12. typedef struct unsigned_to_name_map_t {
  13. long id;
  14. char name[USERNAME_MAX_SIZE];
  15. } unsigned_to_name_map_t;
  16. typedef struct cache_t {
  17. unsigned_to_name_map_t *cache;
  18. int size;
  19. } cache_t;
  20. static cache_t username, groupname;
  21. static void clear_cache(cache_t *cp)
  22. {
  23. free(cp->cache);
  24. cp->cache = NULL;
  25. cp->size = 0;
  26. }
  27. void FAST_FUNC clear_username_cache(void)
  28. {
  29. clear_cache(&username);
  30. clear_cache(&groupname);
  31. }
  32. #if 0 /* more generic, but we don't need that yet */
  33. /* Returns -N-1 if not found. */
  34. /* cp->cache[N] is allocated and must be filled in this case */
  35. static int get_cached(cache_t *cp, unsigned id)
  36. {
  37. int i;
  38. for (i = 0; i < cp->size; i++)
  39. if (cp->cache[i].id == id)
  40. return i;
  41. i = cp->size++;
  42. cp->cache = xrealloc_vector(cp->cache, 2, i);
  43. cp->cache[i++].id = id;
  44. return -i;
  45. }
  46. #endif
  47. static char* get_cached(cache_t *cp, long id,
  48. char* FAST_FUNC x2x_utoa(long id))
  49. {
  50. int i;
  51. for (i = 0; i < cp->size; i++)
  52. if (cp->cache[i].id == id)
  53. return cp->cache[i].name;
  54. i = cp->size++;
  55. cp->cache = xrealloc_vector(cp->cache, 2, i);
  56. cp->cache[i].id = id;
  57. /* Never fails. Generates numeric string if name isn't found */
  58. safe_strncpy(cp->cache[i].name, x2x_utoa(id), sizeof(cp->cache[i].name));
  59. return cp->cache[i].name;
  60. }
  61. const char* FAST_FUNC get_cached_username(uid_t uid)
  62. {
  63. return get_cached(&username, uid, uid2uname_utoa);
  64. }
  65. const char* FAST_FUNC get_cached_groupname(gid_t gid)
  66. {
  67. return get_cached(&groupname, gid, gid2group_utoa);
  68. }
  69. #define PROCPS_BUFSIZE 1024
  70. static int read_to_buf(const char *filename, void *buf)
  71. {
  72. int fd;
  73. /* open_read_close() would do two reads, checking for EOF.
  74. * When you have 10000 /proc/$NUM/stat to read, it isn't desirable */
  75. ssize_t ret = -1;
  76. fd = open(filename, O_RDONLY);
  77. if (fd >= 0) {
  78. ret = read(fd, buf, PROCPS_BUFSIZE-1);
  79. close(fd);
  80. }
  81. ((char *)buf)[ret > 0 ? ret : 0] = '\0';
  82. return ret;
  83. }
  84. static procps_status_t* FAST_FUNC alloc_procps_scan(void)
  85. {
  86. unsigned n = getpagesize();
  87. procps_status_t* sp = xzalloc(sizeof(procps_status_t));
  88. sp->dir = xopendir("/proc");
  89. while (1) {
  90. n >>= 1;
  91. if (!n) break;
  92. sp->shift_pages_to_bytes++;
  93. }
  94. sp->shift_pages_to_kb = sp->shift_pages_to_bytes - 10;
  95. return sp;
  96. }
  97. void FAST_FUNC free_procps_scan(procps_status_t* sp)
  98. {
  99. closedir(sp->dir);
  100. #if ENABLE_FEATURE_SHOW_THREADS
  101. if (sp->task_dir)
  102. closedir(sp->task_dir);
  103. #endif
  104. free(sp->argv0);
  105. free(sp->exe);
  106. IF_SELINUX(free(sp->context);)
  107. free(sp);
  108. }
  109. #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP
  110. static unsigned long fast_strtoul_16(char **endptr)
  111. {
  112. unsigned char c;
  113. char *str = *endptr;
  114. unsigned long n = 0;
  115. while ((c = *str++) != ' ') {
  116. c = ((c|0x20) - '0');
  117. if (c > 9)
  118. // c = c + '0' - 'a' + 10:
  119. c = c - ('a' - '0' - 10);
  120. n = n*16 + c;
  121. }
  122. *endptr = str; /* We skip trailing space! */
  123. return n;
  124. }
  125. #endif
  126. #if ENABLE_FEATURE_FAST_TOP || ENABLE_FEATURE_TOPMEM || ENABLE_PMAP
  127. /* We cut a lot of corners here for speed */
  128. static unsigned long fast_strtoul_10(char **endptr)
  129. {
  130. char c;
  131. char *str = *endptr;
  132. unsigned long n = *str - '0';
  133. while ((c = *++str) != ' ')
  134. n = n*10 + (c - '0');
  135. *endptr = str + 1; /* We skip trailing space! */
  136. return n;
  137. }
  138. static long fast_strtol_10(char **endptr)
  139. {
  140. if (**endptr != '-')
  141. return fast_strtoul_10(endptr);
  142. (*endptr)++;
  143. return - (long)fast_strtoul_10(endptr);
  144. }
  145. static char *skip_fields(char *str, int count)
  146. {
  147. do {
  148. while (*str++ != ' ')
  149. continue;
  150. /* we found a space char, str points after it */
  151. } while (--count);
  152. return str;
  153. }
  154. #endif
  155. #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP
  156. int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
  157. void (*cb)(struct smaprec *, void *), void *data)
  158. {
  159. FILE *file;
  160. struct smaprec currec;
  161. char filename[sizeof("/proc/%u/smaps") + sizeof(int)*3];
  162. char buf[PROCPS_BUFSIZE];
  163. #if !ENABLE_PMAP
  164. void (*cb)(struct smaprec *, void *) = NULL;
  165. void *data = NULL;
  166. #endif
  167. sprintf(filename, "/proc/%u/smaps", (int)pid);
  168. file = fopen_for_read(filename);
  169. if (!file)
  170. return 1;
  171. memset(&currec, 0, sizeof(currec));
  172. while (fgets(buf, PROCPS_BUFSIZE, file)) {
  173. // Each mapping datum has this form:
  174. // f7d29000-f7d39000 rw-s ADR M:m OFS FILE
  175. // Size: nnn kB
  176. // Rss: nnn kB
  177. // .....
  178. char *tp = buf, *p;
  179. #define SCAN(S, X) \
  180. if (strncmp(tp, S, sizeof(S)-1) == 0) { \
  181. tp = skip_whitespace(tp + sizeof(S)-1); \
  182. total->X += currec.X = fast_strtoul_10(&tp); \
  183. continue; \
  184. }
  185. if (cb) {
  186. SCAN("Pss:" , smap_pss );
  187. SCAN("Swap:" , smap_swap );
  188. }
  189. SCAN("Private_Dirty:", private_dirty);
  190. SCAN("Private_Clean:", private_clean);
  191. SCAN("Shared_Dirty:" , shared_dirty );
  192. SCAN("Shared_Clean:" , shared_clean );
  193. #undef SCAN
  194. tp = strchr(buf, '-');
  195. if (tp) {
  196. // We reached next mapping - the line of this form:
  197. // f7d29000-f7d39000 rw-s ADR M:m OFS FILE
  198. if (cb) {
  199. /* If we have a previous record, there's nothing more
  200. * for it, call the callback and clear currec
  201. */
  202. if (currec.smap_size)
  203. cb(&currec, data);
  204. free(currec.smap_name);
  205. }
  206. memset(&currec, 0, sizeof(currec));
  207. *tp = ' ';
  208. tp = buf;
  209. currec.smap_start = fast_strtoul_16(&tp);
  210. currec.smap_size = (fast_strtoul_16(&tp) - currec.smap_start) >> 10;
  211. strncpy(currec.smap_mode, tp, sizeof(currec.smap_mode)-1);
  212. // skipping "rw-s ADR M:m OFS "
  213. tp = skip_whitespace(skip_fields(tp, 4));
  214. // filter out /dev/something (something != zero)
  215. if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) {
  216. if (currec.smap_mode[1] == 'w') {
  217. currec.mapped_rw = currec.smap_size;
  218. total->mapped_rw += currec.smap_size;
  219. } else if (currec.smap_mode[1] == '-') {
  220. currec.mapped_ro = currec.smap_size;
  221. total->mapped_ro += currec.smap_size;
  222. }
  223. }
  224. if (strcmp(tp, "[stack]\n") == 0)
  225. total->stack += currec.smap_size;
  226. if (cb) {
  227. p = skip_non_whitespace(tp);
  228. if (p == tp) {
  229. currec.smap_name = xstrdup(" [ anon ]");
  230. } else {
  231. *p = '\0';
  232. currec.smap_name = xstrdup(tp);
  233. }
  234. }
  235. total->smap_size += currec.smap_size;
  236. }
  237. }
  238. fclose(file);
  239. if (cb) {
  240. if (currec.smap_size)
  241. cb(&currec, data);
  242. free(currec.smap_name);
  243. }
  244. return 0;
  245. }
  246. #endif
  247. void BUG_comm_size(void);
  248. procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
  249. {
  250. struct dirent *entry;
  251. char buf[PROCPS_BUFSIZE];
  252. char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
  253. char *filename_tail;
  254. long tasknice;
  255. unsigned pid;
  256. int n;
  257. struct stat sb;
  258. if (!sp)
  259. sp = alloc_procps_scan();
  260. for (;;) {
  261. #if ENABLE_FEATURE_SHOW_THREADS
  262. if ((flags & PSSCAN_TASKS) && sp->task_dir) {
  263. entry = readdir(sp->task_dir);
  264. if (entry)
  265. goto got_entry;
  266. closedir(sp->task_dir);
  267. sp->task_dir = NULL;
  268. }
  269. #endif
  270. entry = readdir(sp->dir);
  271. if (entry == NULL) {
  272. free_procps_scan(sp);
  273. return NULL;
  274. }
  275. IF_FEATURE_SHOW_THREADS(got_entry:)
  276. pid = bb_strtou(entry->d_name, NULL, 10);
  277. if (errno)
  278. continue;
  279. #if ENABLE_FEATURE_SHOW_THREADS
  280. if ((flags & PSSCAN_TASKS) && !sp->task_dir) {
  281. /* We found another /proc/PID. Do not use it,
  282. * there will be /proc/PID/task/PID (same PID!),
  283. * so just go ahead and dive into /proc/PID/task. */
  284. char task_dir[sizeof("/proc/%u/task") + sizeof(int)*3];
  285. sprintf(task_dir, "/proc/%u/task", pid);
  286. sp->task_dir = xopendir(task_dir);
  287. continue;
  288. }
  289. #endif
  290. /* After this point we can:
  291. * "break": stop parsing, return the data
  292. * "continue": try next /proc/XXX
  293. */
  294. memset(&sp->vsz, 0, sizeof(*sp) - offsetof(procps_status_t, vsz));
  295. sp->pid = pid;
  296. if (!(flags & ~PSSCAN_PID))
  297. break; /* we needed only pid, we got it */
  298. #if ENABLE_SELINUX
  299. if (flags & PSSCAN_CONTEXT) {
  300. if (getpidcon(sp->pid, &sp->context) < 0)
  301. sp->context = NULL;
  302. }
  303. #endif
  304. filename_tail = filename + sprintf(filename, "/proc/%u/", pid);
  305. if (flags & PSSCAN_UIDGID) {
  306. if (stat(filename, &sb))
  307. continue; /* process probably exited */
  308. /* Effective UID/GID, not real */
  309. sp->uid = sb.st_uid;
  310. sp->gid = sb.st_gid;
  311. }
  312. if (flags & PSSCAN_STAT) {
  313. char *cp, *comm1;
  314. int tty;
  315. #if !ENABLE_FEATURE_FAST_TOP
  316. unsigned long vsz, rss;
  317. #endif
  318. /* see proc(5) for some details on this */
  319. strcpy(filename_tail, "stat");
  320. n = read_to_buf(filename, buf);
  321. if (n < 0)
  322. continue; /* process probably exited */
  323. cp = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
  324. /*if (!cp || cp[1] != ' ')
  325. continue;*/
  326. cp[0] = '\0';
  327. if (sizeof(sp->comm) < 16)
  328. BUG_comm_size();
  329. comm1 = strchr(buf, '(');
  330. /*if (comm1)*/
  331. safe_strncpy(sp->comm, comm1 + 1, sizeof(sp->comm));
  332. #if !ENABLE_FEATURE_FAST_TOP
  333. n = sscanf(cp+2,
  334. "%c %u " /* state, ppid */
  335. "%u %u %d %*s " /* pgid, sid, tty, tpgid */
  336. "%*s %*s %*s %*s %*s " /* flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
  337. "%lu %lu " /* utime, stime */
  338. "%*s %*s %*s " /* cutime, cstime, priority */
  339. "%ld " /* nice */
  340. "%*s %*s " /* timeout, it_real_value */
  341. "%lu " /* start_time */
  342. "%lu " /* vsize */
  343. "%lu " /* rss */
  344. # if ENABLE_FEATURE_TOP_SMP_PROCESS
  345. "%*s %*s %*s %*s %*s %*s " /*rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
  346. "%*s %*s %*s %*s " /*signal, blocked, sigignore, sigcatch */
  347. "%*s %*s %*s %*s " /*wchan, nswap, cnswap, exit_signal */
  348. "%d" /*cpu last seen on*/
  349. # endif
  350. ,
  351. sp->state, &sp->ppid,
  352. &sp->pgid, &sp->sid, &tty,
  353. &sp->utime, &sp->stime,
  354. &tasknice,
  355. &sp->start_time,
  356. &vsz,
  357. &rss
  358. # if ENABLE_FEATURE_TOP_SMP_PROCESS
  359. , &sp->last_seen_on_cpu
  360. # endif
  361. );
  362. if (n < 11)
  363. continue; /* bogus data, get next /proc/XXX */
  364. # if ENABLE_FEATURE_TOP_SMP_PROCESS
  365. if (n < 11+15)
  366. sp->last_seen_on_cpu = 0;
  367. # endif
  368. /* vsz is in bytes and we want kb */
  369. sp->vsz = vsz >> 10;
  370. /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */
  371. sp->rss = rss << sp->shift_pages_to_kb;
  372. sp->tty_major = (tty >> 8) & 0xfff;
  373. sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00);
  374. #else
  375. /* This costs ~100 bytes more but makes top faster by 20%
  376. * If you run 10000 processes, this may be important for you */
  377. sp->state[0] = cp[2];
  378. cp += 4;
  379. sp->ppid = fast_strtoul_10(&cp);
  380. sp->pgid = fast_strtoul_10(&cp);
  381. sp->sid = fast_strtoul_10(&cp);
  382. tty = fast_strtoul_10(&cp);
  383. sp->tty_major = (tty >> 8) & 0xfff;
  384. sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00);
  385. cp = skip_fields(cp, 6); /* tpgid, flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
  386. sp->utime = fast_strtoul_10(&cp);
  387. sp->stime = fast_strtoul_10(&cp);
  388. cp = skip_fields(cp, 3); /* cutime, cstime, priority */
  389. tasknice = fast_strtol_10(&cp);
  390. cp = skip_fields(cp, 2); /* timeout, it_real_value */
  391. sp->start_time = fast_strtoul_10(&cp);
  392. /* vsz is in bytes and we want kb */
  393. sp->vsz = fast_strtoul_10(&cp) >> 10;
  394. /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */
  395. sp->rss = fast_strtoul_10(&cp) << sp->shift_pages_to_kb;
  396. # if ENABLE_FEATURE_TOP_SMP_PROCESS
  397. /* (6): rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
  398. /* (4): signal, blocked, sigignore, sigcatch */
  399. /* (4): wchan, nswap, cnswap, exit_signal */
  400. cp = skip_fields(cp, 14);
  401. //FIXME: is it safe to assume this field exists?
  402. sp->last_seen_on_cpu = fast_strtoul_10(&cp);
  403. # endif
  404. #endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */
  405. #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
  406. sp->niceness = tasknice;
  407. #endif
  408. if (sp->vsz == 0 && sp->state[0] != 'Z')
  409. sp->state[1] = 'W';
  410. else
  411. sp->state[1] = ' ';
  412. if (tasknice < 0)
  413. sp->state[2] = '<';
  414. else if (tasknice) /* > 0 */
  415. sp->state[2] = 'N';
  416. else
  417. sp->state[2] = ' ';
  418. }
  419. #if ENABLE_FEATURE_TOPMEM
  420. if (flags & PSSCAN_SMAPS)
  421. procps_read_smaps(pid, &sp->smaps, NULL, NULL);
  422. #endif /* TOPMEM */
  423. #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
  424. if (flags & PSSCAN_RUIDGID) {
  425. FILE *file;
  426. strcpy(filename_tail, "status");
  427. file = fopen_for_read(filename);
  428. if (file) {
  429. while (fgets(buf, sizeof(buf), file)) {
  430. char *tp;
  431. #define SCAN_TWO(str, name, statement) \
  432. if (strncmp(buf, str, sizeof(str)-1) == 0) { \
  433. tp = skip_whitespace(buf + sizeof(str)-1); \
  434. sscanf(tp, "%u", &sp->name); \
  435. statement; \
  436. }
  437. SCAN_TWO("Uid:", ruid, continue);
  438. SCAN_TWO("Gid:", rgid, break);
  439. #undef SCAN_TWO
  440. }
  441. fclose(file);
  442. }
  443. }
  444. #endif /* PS_ADDITIONAL_COLUMNS */
  445. if (flags & PSSCAN_EXE) {
  446. strcpy(filename_tail, "exe");
  447. free(sp->exe);
  448. sp->exe = xmalloc_readlink(filename);
  449. }
  450. /* Note: if /proc/PID/cmdline is empty,
  451. * code below "breaks". Therefore it must be
  452. * the last code to parse /proc/PID/xxx data
  453. * (we used to have /proc/PID/exe parsing after it
  454. * and were getting stale sp->exe).
  455. */
  456. #if 0 /* PSSCAN_CMD is not used */
  457. if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) {
  458. free(sp->argv0);
  459. sp->argv0 = NULL;
  460. free(sp->cmd);
  461. sp->cmd = NULL;
  462. strcpy(filename_tail, "cmdline");
  463. /* TODO: to get rid of size limits, read into malloc buf,
  464. * then realloc it down to real size. */
  465. n = read_to_buf(filename, buf);
  466. if (n <= 0)
  467. break;
  468. if (flags & PSSCAN_ARGV0)
  469. sp->argv0 = xstrdup(buf);
  470. if (flags & PSSCAN_CMD) {
  471. do {
  472. n--;
  473. if ((unsigned char)(buf[n]) < ' ')
  474. buf[n] = ' ';
  475. } while (n);
  476. sp->cmd = xstrdup(buf);
  477. }
  478. }
  479. #else
  480. if (flags & (PSSCAN_ARGV0|PSSCAN_ARGVN)) {
  481. free(sp->argv0);
  482. sp->argv0 = NULL;
  483. strcpy(filename_tail, "cmdline");
  484. n = read_to_buf(filename, buf);
  485. if (n <= 0)
  486. break;
  487. if (flags & PSSCAN_ARGVN) {
  488. sp->argv_len = n;
  489. sp->argv0 = xmalloc(n + 1);
  490. memcpy(sp->argv0, buf, n + 1);
  491. /* sp->argv0[n] = '\0'; - buf has it */
  492. } else {
  493. sp->argv_len = 0;
  494. sp->argv0 = xstrdup(buf);
  495. }
  496. }
  497. #endif
  498. break;
  499. } /* for (;;) */
  500. return sp;
  501. }
  502. void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm)
  503. {
  504. int sz;
  505. char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
  506. sprintf(filename, "/proc/%u/cmdline", pid);
  507. sz = open_read_close(filename, buf, col - 1);
  508. if (sz > 0) {
  509. buf[sz] = '\0';
  510. while (--sz >= 0 && buf[sz] == '\0')
  511. continue;
  512. do {
  513. if ((unsigned char)(buf[sz]) < ' ')
  514. buf[sz] = ' ';
  515. } while (--sz >= 0);
  516. } else {
  517. snprintf(buf, col, "[%s]", comm);
  518. }
  519. }
  520. /* from kernel:
  521. // pid comm S ppid pgid sid tty_nr tty_pgrp flg
  522. sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
  523. %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
  524. %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu\n",
  525. task->pid,
  526. tcomm,
  527. state,
  528. ppid,
  529. pgid,
  530. sid,
  531. tty_nr,
  532. tty_pgrp,
  533. task->flags,
  534. min_flt,
  535. cmin_flt,
  536. maj_flt,
  537. cmaj_flt,
  538. cputime_to_clock_t(utime),
  539. cputime_to_clock_t(stime),
  540. cputime_to_clock_t(cutime),
  541. cputime_to_clock_t(cstime),
  542. priority,
  543. nice,
  544. num_threads,
  545. // 0,
  546. start_time,
  547. vsize,
  548. mm ? get_mm_rss(mm) : 0,
  549. rsslim,
  550. mm ? mm->start_code : 0,
  551. mm ? mm->end_code : 0,
  552. mm ? mm->start_stack : 0,
  553. esp,
  554. eip,
  555. the rest is some obsolete cruft
  556. */