Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2258 lines
58 KiB

  1. /*
  2. posixdbg.c
  3. POSIX debugging for those of us without debugging gear
  4. */
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <stdarg.h>
  9. #include <sys/wait.h>
  10. #include <signal.h>
  11. #include <sys/utsname.h>
  12. #include <time.h>
  13. #include <sys/times.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <dirent.h>
  17. #include <fcntl.h>
  18. #include <sys/stat.h>
  19. #include <utime.h>
  20. #include <termios.h>
  21. #include <setjmp.h>
  22. #include <grp.h>
  23. #include <pwd.h>
  24. #define NARGS 16 /* maximum number of arguments for execl* calls (for display purposes) */
  25. #define NENVS 32 /* maximum number of environment variables for execle call (for display purposes) */
  26. struct sigmap {
  27. int signum;
  28. const char *signame;
  29. };
  30. struct howmap {
  31. int hownum;
  32. const char *howname;
  33. };
  34. struct scnamemap {
  35. int scnamenum;
  36. const char *scnamename;
  37. };
  38. struct pcnamemap {
  39. int pcnamenum;
  40. const char *pcnamename;
  41. };
  42. struct cmdmap {
  43. int cmdnum;
  44. const char *cmdname;
  45. };
  46. struct whencemap {
  47. int whencenum;
  48. const char *whencename;
  49. };
  50. struct speedmap {
  51. speed_t speednum;
  52. const char *speedname;
  53. };
  54. struct optactmap {
  55. int optactnum;
  56. const char *optactname;
  57. };
  58. struct queuemap {
  59. int queuenum;
  60. const char *queuename;
  61. };
  62. struct actionmap {
  63. int actionnum;
  64. const char *actionname;
  65. };
  66. static const char *canonical_string (const char *string)
  67. {
  68. static const char null[] = "NULL";
  69. static char buf[BUFSIZ];
  70. const char *ret;
  71. if (string == NULL)
  72. ret = null;
  73. else
  74. {
  75. (void) sprintf(buf, "\"%s\"", string);
  76. ret = (const char *) buf;
  77. }
  78. return ret;
  79. }
  80. char *options_string (int waitpid_options)
  81. {
  82. static const char bitwise_or[] = "|";
  83. static char buf[BUFSIZ];
  84. char integer_string[11];
  85. *buf = '\0';
  86. if (waitpid_options & WNOHANG)
  87. {
  88. (void) strcat(buf, "WNOHANG");
  89. waitpid_options &= ~WNOHANG;
  90. }
  91. if (waitpid_options & WUNTRACED)
  92. {
  93. if (*buf != '\0')
  94. (void) strcat(buf, bitwise_or);
  95. (void) strcat(buf, "WUNTRACED");
  96. waitpid_options &= ~WUNTRACED;
  97. }
  98. if (waitpid_options)
  99. {
  100. if (*buf != '\0')
  101. (void) strcat(buf, bitwise_or);
  102. (void) sprintf(integer_string, "%#08X", (unsigned int) waitpid_options);
  103. (void) strcat(buf, integer_string);
  104. }
  105. return buf;
  106. }
  107. char *signum_string (int function_signum)
  108. {
  109. static const struct sigmap sigtable[] = {
  110. { SIGABRT, "SIGABRT" }, { SIGALRM, "SIGALRM" }, { SIGFPE, "SIGFPE" }, { SIGHUP, "SIGHUP" },
  111. { SIGILL, "SIGILL" }, { SIGINT, "SIGINT" }, { SIGKILL, "SIGKILL" }, { SIGPIPE, "SIGPIPE" },
  112. { SIGQUIT, "SIGQUIT" }, { SIGSEGV, "SIGSEGV" }, { SIGTERM, "SIGTERM" }, { SIGUSR1, "SIGUSR1" },
  113. { SIGUSR2, "SIGUSR2" }, { SIGCHLD, "SIGCHLD" }, { SIGCONT, "SIGCONT" }, { SIGSTOP, "SIGSTOP" },
  114. { SIGTSTP, "SIGTSTP" }, { SIGTTIN, "SIGTTIN" }, { SIGTTOU, "SIGTTOU" }, { 0, NULL }
  115. };
  116. static char buf[BUFSIZ];
  117. const struct sigmap *sigtblptr;
  118. for (sigtblptr = sigtable; sigtblptr->signum != 0; ++sigtblptr)
  119. if (sigtblptr->signum == function_signum)
  120. break;
  121. if (sigtblptr->signum == 0)
  122. (void) sprintf(buf, "%d", function_signum);
  123. else
  124. (void) strcpy(buf, sigtblptr->signame);
  125. return buf;
  126. }
  127. char *how_string (int sigprocmask_how)
  128. {
  129. static const struct howmap howtable[] = {
  130. { SIG_BLOCK, "SIG_BLOCK" }, { SIG_UNBLOCK, "SIG_UNBLOCK" }, { SIG_SETMASK, "SIG_SETMASK" },
  131. { 0, NULL }
  132. };
  133. static char buf[BUFSIZ];
  134. const struct howmap *howtblptr;
  135. for (howtblptr = howtable; howtblptr->hownum != 0; ++howtblptr)
  136. if (howtblptr->hownum == sigprocmask_how)
  137. break;
  138. if (howtblptr->hownum == 0)
  139. (void) sprintf(buf, "%d", sigprocmask_how);
  140. else
  141. (void) strcpy(buf, howtblptr->howname);
  142. return buf;
  143. }
  144. char *scname_string (int sysconf_name)
  145. {
  146. static const struct scnamemap scnametable[] = {
  147. { _SC_ARG_MAX, "_SC_ARG_MAX" }, { _SC_CHILD_MAX, "_SC_CHILD_MAX" },
  148. { _SC_CLK_TCK, "_SC_CLK_TCK" }, { _SC_NGROUPS_MAX, "_SC_NGROUPS_MAX" },
  149. { _SC_OPEN_MAX, "_SC_OPEN_MAX" }, { _SC_STREAM_MAX, "_SC_STREAM_MAX" },
  150. { _SC_TZNAME_MAX, "_SC_TZNAME_MAX" }, { _SC_JOB_CONTROL, "_SC_JOB_CONTROL" },
  151. { _SC_SAVED_IDS, "_SC_SAVED_IDS" }, { _SC_VERSION, "_SC_VERSION" },
  152. { 0, NULL }
  153. };
  154. static char buf[BUFSIZ];
  155. const struct scnamemap *scnametblptr;
  156. for (scnametblptr = scnametable; scnametblptr->scnamenum != 0; ++scnametblptr)
  157. if (scnametblptr->scnamenum == sysconf_name)
  158. break;
  159. if (scnametblptr->scnamenum == 0)
  160. (void) sprintf(buf, "%d", sysconf_name);
  161. else
  162. (void) strcpy(buf, scnametblptr->scnamename);
  163. return buf;
  164. }
  165. char *oflag_string (int open_oflag)
  166. {
  167. static const char bitwise_or[] = "|";
  168. static char buf[BUFSIZ];
  169. char integer_string[11];
  170. *buf = '\0';
  171. if ((open_oflag & O_ACCMODE) == O_RDONLY)
  172. {
  173. (void) strcat(buf, "O_RDONLY");
  174. open_oflag &= ~O_ACCMODE;
  175. }
  176. else if ((open_oflag & O_ACCMODE) == O_WRONLY)
  177. {
  178. (void) strcat(buf, "O_WRONLY");
  179. open_oflag &= ~O_ACCMODE;
  180. }
  181. else if ((open_oflag & O_ACCMODE) == O_RDWR)
  182. {
  183. (void) strcat(buf, "O_RDWR");
  184. open_oflag &= ~O_ACCMODE;
  185. }
  186. if (open_oflag & O_APPEND)
  187. {
  188. if (*buf != '\0')
  189. (void) strcat(buf, bitwise_or);
  190. (void) strcat(buf, "O_APPEND");
  191. open_oflag &= ~O_APPEND;
  192. }
  193. if (open_oflag & O_CREAT)
  194. {
  195. if (*buf != '\0')
  196. (void) strcat(buf, bitwise_or);
  197. (void) strcat(buf, "O_CREAT");
  198. open_oflag &= ~O_CREAT;
  199. }
  200. if (open_oflag & O_EXCL)
  201. {
  202. if (*buf != '\0')
  203. (void) strcat(buf, bitwise_or);
  204. (void) strcat(buf, "O_EXCL");
  205. open_oflag &= ~O_EXCL;
  206. }
  207. if (open_oflag & O_NOCTTY)
  208. {
  209. if (*buf != '\0')
  210. (void) strcat(buf, bitwise_or);
  211. (void) strcat(buf, "O_NOCTTY");
  212. open_oflag &= ~O_NOCTTY;
  213. }
  214. if (open_oflag & O_NONBLOCK)
  215. {
  216. if (*buf != '\0')
  217. (void) strcat(buf, bitwise_or);
  218. (void) strcat(buf, "O_NONBLOCK");
  219. open_oflag &= ~O_NONBLOCK;
  220. }
  221. if (open_oflag & O_TRUNC)
  222. {
  223. if (*buf != '\0')
  224. (void) strcat(buf, bitwise_or);
  225. (void) strcat(buf, "O_TRUNC");
  226. open_oflag &= ~O_TRUNC;
  227. }
  228. if (open_oflag)
  229. {
  230. if (*buf != '\0')
  231. (void) strcat(buf, bitwise_or);
  232. (void) sprintf(integer_string, "%#08X", (unsigned int) open_oflag);
  233. (void) strcat(buf, integer_string);
  234. }
  235. return buf;
  236. }
  237. char *mode_string (mode_t function_mode)
  238. {
  239. static const char bitwise_or[] = "|";
  240. static char buf[BUFSIZ];
  241. char mode_t_string[13];
  242. *buf = '\0';
  243. if (function_mode & S_IRUSR)
  244. {
  245. (void) strcat(buf, "S_IRUSR");
  246. function_mode &= ~S_IRUSR;
  247. }
  248. if (function_mode & S_IWUSR)
  249. {
  250. if (*buf != '\0')
  251. (void) strcat(buf, bitwise_or);
  252. (void) strcat(buf, "S_IWUSR");
  253. function_mode &= ~S_IWUSR;
  254. }
  255. if (function_mode & S_IXUSR)
  256. {
  257. if (*buf != '\0')
  258. (void) strcat(buf, bitwise_or);
  259. (void) strcat(buf, "S_IXUSR");
  260. function_mode &= ~S_IXUSR;
  261. }
  262. if (function_mode & S_IRGRP)
  263. {
  264. if (*buf != '\0')
  265. (void) strcat(buf, bitwise_or);
  266. (void) strcat(buf, "S_IRGRP");
  267. function_mode &= ~S_IRGRP;
  268. }
  269. if (function_mode & S_IWGRP)
  270. {
  271. if (*buf != '\0')
  272. (void) strcat(buf, bitwise_or);
  273. (void) strcat(buf, "S_IWGRP");
  274. function_mode &= ~S_IWGRP;
  275. }
  276. if (function_mode & S_IXGRP)
  277. {
  278. if (*buf != '\0')
  279. (void) strcat(buf, bitwise_or);
  280. (void) strcat(buf, "S_IXGRP");
  281. function_mode &= ~S_IXGRP;
  282. }
  283. if (function_mode & S_IROTH)
  284. {
  285. if (*buf != '\0')
  286. (void) strcat(buf, bitwise_or);
  287. (void) strcat(buf, "S_IROTH");
  288. function_mode &= ~S_IROTH;
  289. }
  290. if (function_mode & S_IWOTH)
  291. {
  292. if (*buf != '\0')
  293. (void) strcat(buf, bitwise_or);
  294. (void) strcat(buf, "S_IWOTH");
  295. function_mode &= ~S_IWOTH;
  296. }
  297. if (function_mode & S_IXOTH)
  298. {
  299. if (*buf != '\0')
  300. (void) strcat(buf, bitwise_or);
  301. (void) strcat(buf, "S_IXOTH");
  302. function_mode &= ~S_IXOTH;
  303. }
  304. if (function_mode & S_ISUID)
  305. {
  306. if (*buf != '\0')
  307. (void) strcat(buf, bitwise_or);
  308. (void) strcat(buf, "S_ISUID");
  309. function_mode &= ~S_ISUID;
  310. }
  311. if (function_mode & S_ISGID)
  312. {
  313. if (*buf != '\0')
  314. (void) strcat(buf, bitwise_or);
  315. (void) strcat(buf, "S_ISGID");
  316. function_mode &= ~S_ISGID;
  317. }
  318. if (function_mode)
  319. {
  320. if (*buf != '\0')
  321. (void) strcat(buf, bitwise_or);
  322. (void) sprintf(mode_t_string, "%#11lo", (unsigned long) function_mode);
  323. (void) strcat(buf, mode_t_string);
  324. }
  325. return buf;
  326. }
  327. char *amode_string (int access_amode)
  328. {
  329. static const char bitwise_or[] = "|";
  330. static char buf[BUFSIZ];
  331. char integer_string[11];
  332. *buf = '\0';
  333. if (access_amode == F_OK)
  334. {
  335. (void) strcat(buf, "F_OK");
  336. access_amode &= ~F_OK;
  337. }
  338. else
  339. {
  340. if (access_amode & R_OK)
  341. {
  342. (void) strcat(buf, "R_OK");
  343. access_amode &= ~R_OK;
  344. }
  345. if (access_amode & W_OK)
  346. {
  347. if (*buf != '\0')
  348. (void) strcat(buf, bitwise_or);
  349. (void) strcat(buf, "W_OK");
  350. access_amode &= ~W_OK;
  351. }
  352. if (access_amode & X_OK)
  353. {
  354. if (*buf != '\0')
  355. (void) strcat(buf, bitwise_or);
  356. (void) strcat(buf, "X_OK");
  357. access_amode &= ~X_OK;
  358. }
  359. }
  360. if (access_amode)
  361. {
  362. if (*buf != '\0')
  363. (void) strcat(buf, bitwise_or);
  364. (void) sprintf(integer_string, "%#08X", (unsigned int) access_amode);
  365. (void) strcat(buf, integer_string);
  366. }
  367. return buf;
  368. }
  369. char *pcname_string (int function_name)
  370. {
  371. static const struct pcnamemap pcnametable[] = {
  372. { _PC_LINK_MAX, "_PC_LINK_MAX" }, { _PC_MAX_CANON, "_PC_MAX_CANON" },
  373. { _PC_MAX_INPUT, "_PC_MAX_INPUT" }, { _PC_NAME_MAX, "_PC_NAME_MAX" },
  374. { _PC_PATH_MAX, "_PC_PATH_MAX" }, { _PC_PIPE_BUF, "_PC_PIPE_BUF" },
  375. { _PC_CHOWN_RESTRICTED, "_PC_CHOWN_RESTRICTED" }, { _PC_NO_TRUNC, "_PC_NO_TRUNC" },
  376. { _PC_VDISABLE, "_PC_VDISABLE" }, { 0, NULL }
  377. };
  378. static char buf[BUFSIZ];
  379. const struct pcnamemap *pcnametblptr;
  380. for (pcnametblptr = pcnametable; pcnametblptr->pcnamenum != 0; ++pcnametblptr)
  381. if (pcnametblptr->pcnamenum == function_name)
  382. break;
  383. if (pcnametblptr->pcnamenum == 0)
  384. (void) sprintf(buf, "%d", function_name);
  385. else
  386. (void) strcpy(buf, pcnametblptr->pcnamename);
  387. return buf;
  388. }
  389. char *cmd_string (int fcntl_cmd)
  390. {
  391. static const struct cmdmap cmdtable[] = {
  392. { F_DUPFD, "F_DUPFD" }, { F_GETFD, "F_GETFD" }, { F_SETFD, "F_SETFD" }, { F_GETFL, "F_GETFL" },
  393. { F_SETFL, "F_SETFL" }, { F_GETLK, "F_GETLK" }, { F_SETLK, "F_SETLK" }, { F_SETLKW, "F_SETLKW" },
  394. { 0, NULL }
  395. };
  396. static char buf[BUFSIZ];
  397. const struct cmdmap *cmdtblptr;
  398. for (cmdtblptr = cmdtable; cmdtblptr->cmdnum != 0; ++cmdtblptr)
  399. if (cmdtblptr->cmdnum == fcntl_cmd)
  400. break;
  401. if (cmdtblptr->cmdnum == 0)
  402. (void) sprintf(buf, "%d", fcntl_cmd);
  403. else
  404. (void) strcpy(buf, cmdtblptr->cmdname);
  405. return buf;
  406. }
  407. char *whence_string (int lseek_whence)
  408. {
  409. static const struct whencemap whencetable[] = {
  410. { SEEK_SET, "SEEK_SET" }, { SEEK_CUR, "SEEK_CUR" }, { SEEK_END, "SEEK_END" }, { 0, NULL }
  411. };
  412. static char buf[BUFSIZ];
  413. const struct whencemap *whencetblptr;
  414. for (whencetblptr = whencetable; whencetblptr->whencenum != 0; ++whencetblptr)
  415. if (whencetblptr->whencenum == lseek_whence)
  416. break;
  417. if (whencetblptr->whencenum == 0)
  418. (void) sprintf(buf, "%d", lseek_whence);
  419. else
  420. (void) strcpy(buf, whencetblptr->whencename);
  421. return buf;
  422. }
  423. char *speed_string (speed_t function_speed)
  424. {
  425. static const struct speedmap speedtable[] = {
  426. { B0, "B0" }, { B50, "B50" }, { B75, "B75" }, { B110, "B110" }, { B134, "B134" },
  427. { B150, "B150" }, { B200, "B200" }, { B300, "B300" }, { B600, "B600" }, { B1200, "B1200" },
  428. { B1800, "B1800" }, { B2400, "B2400" }, { B4800, "B4800" }, { B9600, "B9600" }, { B19200, "B19200" },
  429. { B38400, "B38400" }, { 0, NULL }
  430. };
  431. static char buf[BUFSIZ];
  432. const struct speedmap *speedtblptr;
  433. for (speedtblptr = speedtable; speedtblptr->speednum != 0; ++speedtblptr)
  434. if (speedtblptr->speednum == function_speed)
  435. break;
  436. if (speedtblptr->speednum == 0)
  437. (void) sprintf(buf, "%d", function_speed);
  438. else
  439. (void) strcpy(buf, speedtblptr->speedname);
  440. return buf;
  441. }
  442. char *optact_string (int tcsetattr_optact)
  443. {
  444. static const struct optactmap optacttable[] = {
  445. { TCSANOW, "TCSANOW" }, { TCSADRAIN, "TCSADRAIN" }, { TCSAFLUSH, "TCSAFLUSH" }, { 0, NULL }
  446. };
  447. static char buf[BUFSIZ];
  448. const struct optactmap *optacttblptr;
  449. for (optacttblptr = optacttable; optacttblptr->optactnum != 0; ++optacttblptr)
  450. if (optacttblptr->optactnum == tcsetattr_optact)
  451. break;
  452. if (optacttblptr->optactnum == 0)
  453. (void) sprintf(buf, "%d", tcsetattr_optact);
  454. else
  455. (void) strcpy(buf, optacttblptr->optactname);
  456. return buf;
  457. }
  458. char *queue_string (int tcflush_queue)
  459. {
  460. static const struct queuemap queuetable[] = {
  461. { TCIFLUSH, "TCIFLUSH" }, { TCOFLUSH, "TCOFLUSH" }, { TCIOFLUSH, "TCIOFLUSH" }, { 0, NULL }
  462. };
  463. static char buf[BUFSIZ];
  464. const struct queuemap *queuetblptr;
  465. for (queuetblptr = queuetable; queuetblptr->queuenum != 0; ++queuetblptr)
  466. if (queuetblptr->queuenum == tcflush_queue)
  467. break;
  468. if (queuetblptr->queuenum == 0)
  469. (void) sprintf(buf, "%d", tcflush_queue);
  470. else
  471. (void) strcpy(buf, queuetblptr->queuename);
  472. return buf;
  473. }
  474. char *action_string (int tcflow_action)
  475. {
  476. static const struct actionmap actiontable[] = {
  477. { TCOOFF, "TCOOFF" }, { TCOON, "TCOON" }, { TCIOFF, "TCIOFF" }, { TCION, "TCION" }, { 0, NULL }
  478. };
  479. static char buf[BUFSIZ];
  480. const struct actionmap *actiontblptr;
  481. for (actiontblptr = actiontable; actiontblptr->actionnum != 0; ++actiontblptr)
  482. if (actiontblptr->actionnum == tcflow_action)
  483. break;
  484. if (actiontblptr->actionnum == 0)
  485. (void) sprintf(buf, "%d", tcflow_action);
  486. else
  487. (void) strcpy(buf, actiontblptr->actionname);
  488. return buf;
  489. }
  490. /* Section 3: Process Primitives */
  491. pid_t posix_debug_fork (void)
  492. {
  493. pid_t ret;
  494. int err;
  495. (void) fprintf(stderr, "entering fork()\n");
  496. (void) fflush(stderr);
  497. ret = fork();
  498. err = errno;
  499. (void) fprintf(stderr, "exiting fork with %ld", (long) ret);
  500. if (ret == (pid_t) -1)
  501. (void) fprintf(stderr, "; errno: %d", err);
  502. (void) fprintf(stderr, "\n");
  503. (void) fflush(stderr);
  504. return ret;
  505. }
  506. int posix_debug_execl (const char *path, const char *arg, ...)
  507. {
  508. va_list va;
  509. int ret, err, i;
  510. const char *args[NARGS];
  511. va_start(va, arg);
  512. (void) fprintf(stderr, "entering execl(%s, %s", canonical_string(path), canonical_string(arg));
  513. for (i = 0; i < NARGS; ++i)
  514. {
  515. args[i] = va_arg(va, const char *);
  516. (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  517. if (args[i] == NULL)
  518. break;
  519. }
  520. va_end(va);
  521. if (i == NARGS)
  522. (void) fprintf(stderr, ", ..., NULL");
  523. (void) fprintf(stderr, ")\n");
  524. (void) fflush(stderr);
  525. if (i == 0)
  526. ret = execl(path, arg, NULL);
  527. else if (i == 1)
  528. ret = execl(path, arg, args[0], NULL);
  529. else if (i == 2)
  530. ret = execl(path, arg, args[0], args[1], NULL);
  531. else if (i == 3)
  532. ret = execl(path, arg, args[0], args[1], args[2], NULL);
  533. else if (i == 4)
  534. ret = execl(path, arg, args[0], args[1], args[2], args[3], NULL);
  535. else if (i == 5)
  536. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], NULL);
  537. else if (i == 6)
  538. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL);
  539. else if (i == 7)
  540. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL);
  541. else if (i == 8)
  542. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL);
  543. else if (i == 9)
  544. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL);
  545. else if (i == 10)
  546. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  547. NULL);
  548. else if (i == 11)
  549. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  550. args[10], NULL);
  551. else if (i == 12)
  552. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  553. args[10], args[11], NULL);
  554. else if (i == 13)
  555. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  556. args[10], args[11], args[12], NULL);
  557. else if (i == 14)
  558. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  559. args[10], args[11], args[12], args[13], NULL);
  560. else if (i == 15)
  561. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  562. args[10], args[11], args[12], args[13], args[14], NULL);
  563. else
  564. ret = execl(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  565. args[10], args[11], args[12], args[13], args[14], args[15], NULL);
  566. /*
  567. If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  568. */
  569. err = errno;
  570. (void) fprintf(stderr, "exiting execl with %d", ret);
  571. if (ret == -1)
  572. (void) fprintf(stderr, "; errno: %d", err);
  573. (void) fprintf(stderr, "\n");
  574. (void) fflush(stderr);
  575. return ret;
  576. }
  577. int posix_debug_execv (const char *path, char * const argv[])
  578. {
  579. int ret, err;
  580. (void) fprintf(stderr, "entering execv(%s, %p)\n", canonical_string(path), argv);
  581. (void) fflush(stderr);
  582. ret = execv(path, argv);
  583. err = errno;
  584. (void) fprintf(stderr, "exiting execv with %d", ret);
  585. if (ret == -1)
  586. (void) fprintf(stderr, "; errno: %d", err);
  587. (void) fprintf(stderr, "\n");
  588. (void) fflush(stderr);
  589. return ret;
  590. }
  591. int posix_debug_execle (const char *path, const char *arg, ...)
  592. {
  593. va_list va;
  594. int ret, err, i, j;
  595. const char *args[NARGS];
  596. const char *envp[NENVS]; /* POSIX says it should be char * const [], but that's unassignable! */
  597. (void) fprintf(stderr, "entering execle(%s, %s", canonical_string(path), canonical_string(arg));
  598. for (i = 0; i < NARGS; ++i)
  599. {
  600. args[i] = va_arg(va, const char *);
  601. (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  602. if (args[i] == NULL)
  603. break;
  604. }
  605. if (i == NARGS)
  606. {
  607. while (va_arg(va, const char *) != NULL)
  608. ;
  609. (void) fprintf(stderr, ", ..., NULL");
  610. }
  611. for (j = 0; j < NENVS; ++j)
  612. {
  613. envp[j] = va_arg(va, char * const);
  614. (void) fprintf(stderr, ", %s", canonical_string(envp[j]));
  615. if (envp[j] == NULL)
  616. break;
  617. }
  618. if (j == NENVS)
  619. {
  620. envp[NENVS - 1] = NULL;
  621. (void) fprintf(stderr, ", ..., NULL");
  622. }
  623. va_end(va);
  624. (void) fprintf(stderr, ")\n");
  625. (void) fflush(stderr);
  626. if (i == 0)
  627. ret = execle(path, arg, NULL, envp);
  628. else if (i == 1)
  629. ret = execle(path, arg, args[0], NULL, envp);
  630. else if (i == 2)
  631. ret = execle(path, arg, args[0], args[1], NULL, envp);
  632. else if (i == 3)
  633. ret = execle(path, arg, args[0], args[1], args[2], NULL, envp);
  634. else if (i == 4)
  635. ret = execle(path, arg, args[0], args[1], args[2], args[3], NULL, envp);
  636. else if (i == 5)
  637. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], NULL, envp);
  638. else if (i == 6)
  639. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL, envp);
  640. else if (i == 7)
  641. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL, envp);
  642. else if (i == 8)
  643. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL, envp);
  644. else if (i == 9)
  645. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL,
  646. envp);
  647. else if (i == 10)
  648. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  649. NULL, envp);
  650. else if (i == 11)
  651. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  652. args[10], NULL, envp);
  653. else if (i == 12)
  654. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  655. args[10], args[11], NULL, envp);
  656. else if (i == 13)
  657. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  658. args[10], args[11], args[12], NULL, envp);
  659. else if (i == 14)
  660. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  661. args[10], args[11], args[12], args[13], NULL, envp);
  662. else if (i == 15)
  663. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  664. args[10], args[11], args[12], args[13], args[14], NULL, envp);
  665. else
  666. ret = execle(path, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  667. args[10], args[11], args[12], args[13], args[14], args[15], NULL, envp);
  668. /*
  669. If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  670. */
  671. err = errno;
  672. (void) fprintf(stderr, "exiting execle with %d", ret);
  673. if (ret == -1)
  674. (void) fprintf(stderr, "; errno: %d", err);
  675. (void) fprintf(stderr, "\n");
  676. (void) fflush(stderr);
  677. return ret;
  678. }
  679. int posix_debug_execve (const char *path, char * const argv[], char * const envp[])
  680. {
  681. int ret, err;
  682. (void) fprintf(stderr, "entering execve(%s, %p, %p)\n", canonical_string(path), argv, envp);
  683. (void) fflush(stderr);
  684. ret = execve(path, argv, envp);
  685. err = errno;
  686. (void) fprintf(stderr, "exiting execve with %d", ret);
  687. if (ret == -1)
  688. (void) fprintf(stderr, "; errno: %d", err);
  689. (void) fprintf(stderr, "\n");
  690. (void) fflush(stderr);
  691. return ret;
  692. }
  693. int posix_debug_execlp (const char *file, const char *arg, ...)
  694. {
  695. va_list va;
  696. int ret, err, i;
  697. const char *args[NARGS];
  698. va_start(va, arg);
  699. (void) fprintf(stderr, "entering execlp(%s, %s", canonical_string(file), canonical_string(arg));
  700. for (i = 0; i < NARGS; ++i)
  701. {
  702. args[i] = va_arg(va, const char *);
  703. (void) fprintf(stderr, ", %s", canonical_string(args[i]));
  704. if (args[i] == NULL)
  705. break;
  706. }
  707. va_end(va);
  708. if (i == NARGS)
  709. (void) fprintf(stderr, ", ..., NULL");
  710. (void) fprintf(stderr, ")\n");
  711. (void) fflush(stderr);
  712. if (i == 0)
  713. ret = execlp(file, arg, NULL);
  714. else if (i == 1)
  715. ret = execlp(file, arg, args[0], NULL);
  716. else if (i == 2)
  717. ret = execlp(file, arg, args[0], args[1], NULL);
  718. else if (i == 3)
  719. ret = execlp(file, arg, args[0], args[1], args[2], NULL);
  720. else if (i == 4)
  721. ret = execlp(file, arg, args[0], args[1], args[2], args[3], NULL);
  722. else if (i == 5)
  723. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], NULL);
  724. else if (i == 6)
  725. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], NULL);
  726. else if (i == 7)
  727. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], NULL);
  728. else if (i == 8)
  729. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], NULL);
  730. else if (i == 9)
  731. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], NULL);
  732. else if (i == 10)
  733. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  734. NULL);
  735. else if (i == 11)
  736. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  737. args[10], NULL);
  738. else if (i == 12)
  739. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  740. args[10], args[11], NULL);
  741. else if (i == 13)
  742. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  743. args[10], args[11], args[12], NULL);
  744. else if (i == 14)
  745. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  746. args[10], args[11], args[12], args[13], NULL);
  747. else if (i == 15)
  748. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  749. args[10], args[11], args[12], args[13], args[14], NULL);
  750. else
  751. ret = execlp(file, arg, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9],
  752. args[10], args[11], args[12], args[13], args[14], args[15], NULL);
  753. /*
  754. If NARGS changes from its original value of 16, add or subtract "if" cases according to this pattern.
  755. */
  756. err = errno;
  757. (void) fprintf(stderr, "exiting execlp with %d", ret);
  758. if (ret == -1)
  759. (void) fprintf(stderr, "; errno: %d", err);
  760. (void) fprintf(stderr, "\n");
  761. (void) fflush(stderr);
  762. return ret;
  763. }
  764. int posix_debug_execvp (const char *file, char * const argv[])
  765. {
  766. int ret, err;
  767. (void) fprintf(stderr, "entering execvp(%s, %p)\n", canonical_string(file), argv);
  768. (void) fflush(stderr);
  769. ret = execvp(file, argv);
  770. err = errno;
  771. (void) fprintf(stderr, "exiting execvp with %d", ret);
  772. if (ret == -1)
  773. (void) fprintf(stderr, "; errno: %d", err);
  774. (void) fprintf(stderr, "\n");
  775. (void) fflush(stderr);
  776. return ret;
  777. }
  778. pid_t posix_debug_wait (int *statloc)
  779. {
  780. pid_t ret;
  781. int err;
  782. (void) fprintf(stderr, "entering wait(%p)\n", statloc);
  783. (void) fflush(stderr);
  784. ret = wait(statloc);
  785. err = errno;
  786. (void) fprintf(stderr, "exiting wait with %ld", (long) ret);
  787. if (ret == (pid_t) -1)
  788. (void) fprintf(stderr, "; errno: %d", err);
  789. (void) fprintf(stderr, "\n");
  790. (void) fflush(stderr);
  791. return ret;
  792. }
  793. pid_t posix_debug_waitpid (pid_t pid, int *statloc, int options)
  794. {
  795. pid_t ret;
  796. int err;
  797. (void) fprintf(stderr, "entering waitpid(%ld, %p, %s)\n", (long) pid, statloc, options_string(options));
  798. (void) fflush(stderr);
  799. ret = waitpid(pid, statloc, options);
  800. err = errno;
  801. (void) fprintf(stderr, "exiting waitpid with %ld", (long) ret);
  802. if (ret == (pid_t) -1)
  803. (void) fprintf(stderr, "; errno: %d", err);
  804. (void) fprintf(stderr, "\n");
  805. (void) fflush(stderr);
  806. return ret;
  807. }
  808. void posix_debug__exit (int status)
  809. {
  810. int err, saved_errno;
  811. (void) fprintf(stderr, "entering _exit(%d)\n", status);
  812. (void) fflush(stderr);
  813. saved_errno = errno;
  814. _exit(status);
  815. err = errno;
  816. (void) fprintf(stderr, "exiting _exit");
  817. if (saved_errno != err)
  818. (void) fprintf(stderr, "; errno: %d", err);
  819. (void) fprintf(stderr, "\n");
  820. (void) fflush(stderr);
  821. }
  822. int posix_debug_kill (pid_t pid, int sig)
  823. {
  824. int ret, err;
  825. (void) fprintf(stderr, "entering kill(%ld, %s)\n", (long) pid, signum_string(sig));
  826. (void) fflush(stderr);
  827. ret = kill(pid, sig);
  828. err = errno;
  829. (void) fprintf(stderr, "exiting kill with %d", ret);
  830. if (ret == -1)
  831. (void) fprintf(stderr, "; errno: %d", err);
  832. (void) fprintf(stderr, "\n");
  833. (void) fflush(stderr);
  834. return ret;
  835. }
  836. int posix_debug_sigemptyset (sigset_t *set)
  837. {
  838. int ret, err;
  839. (void) fprintf(stderr, "entering sigemptyset(%p)\n", set);
  840. (void) fflush(stderr);
  841. ret = sigemptyset(set);
  842. err = errno;
  843. (void) fprintf(stderr, "exiting sigemptyset with %d", ret);
  844. if (ret == -1)
  845. (void) fprintf(stderr, "; errno: %d", err);
  846. (void) fprintf(stderr, "\n");
  847. (void) fflush(stderr);
  848. return ret;
  849. }
  850. int posix_debug_sigfillset (sigset_t *set)
  851. {
  852. int ret, err;
  853. (void) fprintf(stderr, "entering sigfillset(%p)\n", set);
  854. (void) fflush(stderr);
  855. ret = sigfillset(set);
  856. err = errno;
  857. (void) fprintf(stderr, "exiting sigfillset with %d", ret);
  858. if (ret == -1)
  859. (void) fprintf(stderr, "; errno: %d", err);
  860. (void) fprintf(stderr, "\n");
  861. (void) fflush(stderr);
  862. return ret;
  863. }
  864. int posix_debug_sigaddset (sigset_t *set, int signo)
  865. {
  866. int ret, err;
  867. (void) fprintf(stderr, "entering sigaddset(%p, %s)\n", set, signum_string(signo));
  868. (void) fflush(stderr);
  869. ret = sigaddset(set, signo);
  870. err = errno;
  871. (void) fprintf(stderr, "exiting sigaddset with %d", ret);
  872. if (ret == -1)
  873. (void) fprintf(stderr, "; errno: %d", err);
  874. (void) fprintf(stderr, "\n");
  875. (void) fflush(stderr);
  876. return ret;
  877. }
  878. int posix_debug_sigdelset (sigset_t *set, int signo)
  879. {
  880. int ret, err;
  881. (void) fprintf(stderr, "entering sigdelset(%p, %s)\n", set, signum_string(signo));
  882. (void) fflush(stderr);
  883. ret = sigdelset(set, signo);
  884. err = errno;
  885. (void) fprintf(stderr, "exiting sigdelset with %d", ret);
  886. if (ret == -1)
  887. (void) fprintf(stderr, "; errno: %d", err);
  888. (void) fprintf(stderr, "\n");
  889. (void) fflush(stderr);
  890. return ret;
  891. }
  892. int posix_debug_sigismember (const sigset_t *set, int signo)
  893. {
  894. int ret, err;
  895. (void) fprintf(stderr, "entering sigismember(%p, %s)\n", set, signum_string(signo));
  896. (void) fflush(stderr);
  897. ret = sigismember(set, signo);
  898. err = errno;
  899. (void) fprintf(stderr, "exiting sigismember with %d", ret);
  900. if (ret == -1)
  901. (void) fprintf(stderr, "; errno: %d", err);
  902. (void) fprintf(stderr, "\n");
  903. (void) fflush(stderr);
  904. return ret;
  905. }
  906. int posix_debug_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
  907. {
  908. int ret, err;
  909. (void) fprintf(stderr, "entering sigaction(%s, %p, %p)\n", signum_string(sig), act, oact);
  910. (void) fflush(stderr);
  911. ret = sigaction(sig, act, oact);
  912. err = errno;
  913. (void) fprintf(stderr, "exiting sigaction with %d", ret);
  914. if (ret == -1)
  915. (void) fprintf(stderr, "; errno: %d", err);
  916. (void) fprintf(stderr, "\n");
  917. (void) fflush(stderr);
  918. return ret;
  919. }
  920. int posix_debug_sigprocmask (int how, const sigset_t *set, sigset_t *oset)
  921. {
  922. int ret, err;
  923. (void) fprintf(stderr, "entering sigprocmask(%s, %p, %p)\n", how_string(how), set, oset);
  924. (void) fflush(stderr);
  925. ret = sigprocmask(how, set, oset);
  926. err = errno;
  927. (void) fprintf(stderr, "exiting sigprocmask with %d", ret);
  928. if (ret == -1)
  929. (void) fprintf(stderr, "; errno: %d", err);
  930. (void) fprintf(stderr, "\n");
  931. (void) fflush(stderr);
  932. return ret;
  933. }
  934. int posix_debug_sigpending (sigset_t *set)
  935. {
  936. int ret, err;
  937. (void) fprintf(stderr, "entering sigpending(%p)\n", set);
  938. (void) fflush(stderr);
  939. ret = sigpending(set);
  940. err = errno;
  941. (void) fprintf(stderr, "exiting sigpending with %d", ret);
  942. if (ret == -1)
  943. (void) fprintf(stderr, "; errno: %d", err);
  944. (void) fprintf(stderr, "\n");
  945. (void) fflush(stderr);
  946. return ret;
  947. }
  948. int posix_debug_sigsuspend (const sigset_t *sigmask)
  949. {
  950. int ret, err;
  951. (void) fprintf(stderr, "entering sigsuspend(%p)\n", sigmask);
  952. (void) fflush(stderr);
  953. ret = sigsuspend(sigmask);
  954. err = errno;
  955. (void) fprintf(stderr, "exiting sigsuspend with %d", ret);
  956. if (ret == -1)
  957. (void) fprintf(stderr, "; errno: %d", err);
  958. (void) fprintf(stderr, "\n");
  959. (void) fflush(stderr);
  960. return ret;
  961. }
  962. unsigned int posix_debug_alarm (unsigned int seconds)
  963. {
  964. unsigned int ret;
  965. (void) fprintf(stderr, "entering alarm(%u)\n", seconds);
  966. (void) fflush(stderr);
  967. ret = alarm(seconds);
  968. (void) fprintf(stderr, "exiting alarm with %u\n", ret);
  969. (void) fflush(stderr);
  970. return ret;
  971. }
  972. int posix_debug_pause (void)
  973. {
  974. int ret, err;
  975. (void) fprintf(stderr, "entering pause()\n");
  976. (void) fflush(stderr);
  977. ret = pause();
  978. err = errno;
  979. (void) fprintf(stderr, "exiting pause with %d", ret);
  980. if (ret == -1)
  981. (void) fprintf(stderr, "; errno: %d", err);
  982. (void) fprintf(stderr, "\n");
  983. (void) fflush(stderr);
  984. return ret;
  985. }
  986. unsigned int posix_debug_sleep (unsigned int seconds)
  987. {
  988. unsigned int ret;
  989. (void) fprintf(stderr, "entering sleep(%u)\n", seconds);
  990. (void) fflush(stderr);
  991. ret = sleep(seconds);
  992. (void) fprintf(stderr, "exiting sleep with %u\n", ret);
  993. (void) fflush(stderr);
  994. return ret;
  995. }
  996. /* Section 4: Process Environment */
  997. pid_t posix_debug_getpid (void)
  998. {
  999. pid_t ret;
  1000. (void) fprintf(stderr, "entering getpid()\n");
  1001. (void) fflush(stderr);
  1002. ret = getpid();
  1003. (void) fprintf(stderr, "exiting getpid with %ld\n", (long) ret);
  1004. (void) fflush(stderr);
  1005. return ret;
  1006. }
  1007. pid_t posix_debug_getppid (void)
  1008. {
  1009. pid_t ret;
  1010. (void) fprintf(stderr, "entering getppid()\n");
  1011. (void) fflush(stderr);
  1012. ret = getppid();
  1013. (void) fprintf(stderr, "exiting getppid with %ld\n", (long) ret);
  1014. (void) fflush(stderr);
  1015. return ret;
  1016. }
  1017. uid_t posix_debug_getuid (void)
  1018. {
  1019. uid_t ret;
  1020. (void) fprintf(stderr, "entering getuid()\n");
  1021. (void) fflush(stderr);
  1022. ret = getuid();
  1023. (void) fprintf(stderr, "exiting getuid with %lu\n", (unsigned long) ret);
  1024. (void) fflush(stderr);
  1025. return ret;
  1026. }
  1027. uid_t posix_debug_geteuid (void)
  1028. {
  1029. uid_t ret;
  1030. (void) fprintf(stderr, "entering geteuid()\n");
  1031. (void) fflush(stderr);
  1032. ret = geteuid();
  1033. (void) fprintf(stderr, "exiting geteuid with %lu\n", (unsigned long) ret);
  1034. (void) fflush(stderr);
  1035. return ret;
  1036. }
  1037. gid_t posix_debug_getgid (void)
  1038. {
  1039. gid_t ret;
  1040. (void) fprintf(stderr, "entering getgid()\n");
  1041. (void) fflush(stderr);
  1042. ret = getgid();
  1043. (void) fprintf(stderr, "exiting getgid with %lu\n", (unsigned long) ret);
  1044. (void) fflush(stderr);
  1045. return ret;
  1046. }
  1047. gid_t posix_debug_getegid (void)
  1048. {
  1049. gid_t ret;
  1050. (void) fprintf(stderr, "entering getegid()\n");
  1051. (void) fflush(stderr);
  1052. ret = getegid();
  1053. (void) fprintf(stderr, "exiting getegid with %lu\n", (unsigned long) ret);
  1054. (void) fflush(stderr);
  1055. return ret;
  1056. }
  1057. int posix_debug_setuid (uid_t uid)
  1058. {
  1059. int ret, err;
  1060. (void) fprintf(stderr, "entering setuid(%lu)\n", (unsigned long) uid);
  1061. (void) fflush(stderr);
  1062. ret = setuid(uid);
  1063. err = errno;
  1064. (void) fprintf(stderr, "exiting setuid with %d", ret);
  1065. if (ret == -1)
  1066. (void) fprintf(stderr, "; errno: %d", err);
  1067. (void) fprintf(stderr, "\n");
  1068. (void) fflush(stderr);
  1069. return ret;
  1070. }
  1071. int posix_debug_setgid (gid_t gid)
  1072. {
  1073. int ret, err;
  1074. (void) fprintf(stderr, "entering setgid(%lu)\n", (unsigned long) gid);
  1075. (void) fflush(stderr);
  1076. ret = setgid(gid);
  1077. err = errno;
  1078. (void) fprintf(stderr, "exiting setgid with %d", ret);
  1079. if (ret == -1)
  1080. (void) fprintf(stderr, "; errno: %d", err);
  1081. (void) fprintf(stderr, "\n");
  1082. (void) fflush(stderr);
  1083. return ret;
  1084. }
  1085. int posix_debug_getgroups (int gidsetsize, gid_t grouplist[])
  1086. {
  1087. int ret, err;
  1088. (void) fprintf(stderr, "entering getgroups(%d, %p)\n", gidsetsize, grouplist);
  1089. (void) fflush(stderr);
  1090. ret = getgroups(gidsetsize, grouplist);
  1091. err = errno;
  1092. (void) fprintf(stderr, "exiting getgroups with %d", ret);
  1093. if (ret == -1)
  1094. (void) fprintf(stderr, "; errno: %d", err);
  1095. (void) fprintf(stderr, "\n");
  1096. (void) fflush(stderr);
  1097. return ret;
  1098. }
  1099. char *posix_debug_getlogin (void)
  1100. {
  1101. char *ret;
  1102. (void) fprintf(stderr, "entering getlogin()\n");
  1103. (void) fflush(stderr);
  1104. ret = getlogin();
  1105. (void) fprintf(stderr, "exiting getlogin with %s\n", canonical_string(ret));
  1106. (void) fflush(stderr);
  1107. return ret;
  1108. }
  1109. pid_t posix_debug_getpgrp (void)
  1110. {
  1111. pid_t ret;
  1112. (void) fprintf(stderr, "entering getpgrp()\n");
  1113. (void) fflush(stderr);
  1114. ret = getpgrp();
  1115. (void) fprintf(stderr, "exiting getpgrp with %ld\n", (long) ret);
  1116. (void) fflush(stderr);
  1117. return ret;
  1118. }
  1119. pid_t posix_debug_setsid (void)
  1120. {
  1121. pid_t ret;
  1122. int err;
  1123. (void) fprintf(stderr, "entering setsid()\n");
  1124. (void) fflush(stderr);
  1125. ret = setsid();
  1126. err = errno;
  1127. (void) fprintf(stderr, "exiting setsid with %ld", (long) ret);
  1128. if (ret == (pid_t) -1)
  1129. (void) fprintf(stderr, "; errno: %d", err);
  1130. (void) fprintf(stderr, "\n");
  1131. (void) fflush(stderr);
  1132. return ret;
  1133. }
  1134. int posix_debug_setpgid (pid_t pid, pid_t pgid)
  1135. {
  1136. int ret, err;
  1137. (void) fprintf(stderr, "entering setpgid(%ld, %ld)\n", (long) pid, (long) pgid);
  1138. (void) fflush(stderr);
  1139. ret = setpgid(pid, pgid);
  1140. err = errno;
  1141. (void) fprintf(stderr, "exiting setpgid with %d", ret);
  1142. if (ret == -1)
  1143. (void) fprintf(stderr, "; errno: %d", err);
  1144. (void) fprintf(stderr, "\n");
  1145. (void) fflush(stderr);
  1146. return ret;
  1147. }
  1148. int posix_debug_uname (struct utsname *name)
  1149. {
  1150. int ret, err;
  1151. (void) fprintf(stderr, "entering uname(%p)\n", name);
  1152. (void) fflush(stderr);
  1153. ret = uname(name);
  1154. err = errno;
  1155. (void) fprintf(stderr, "exiting uname with %d", ret);
  1156. if (ret == -1)
  1157. (void) fprintf(stderr, "; errno: %d", err);
  1158. (void) fprintf(stderr, "\n");
  1159. (void) fflush(stderr);
  1160. return ret;
  1161. }
  1162. time_t posix_debug_time (time_t *tloc)
  1163. {
  1164. time_t ret;
  1165. int err;
  1166. (void) fprintf(stderr, "entering time(%p)\n", tloc);
  1167. (void) fflush(stderr);
  1168. ret = time(tloc);
  1169. err = errno;
  1170. (void) fprintf(stderr, "exiting time with %ld", (long) ret);
  1171. if (ret == (time_t) -1)
  1172. (void) fprintf(stderr, "; errno: %d", err);
  1173. (void) fprintf(stderr, "\n");
  1174. (void) fflush(stderr);
  1175. return ret;
  1176. }
  1177. clock_t posix_debug_times (struct tms *buffer)
  1178. {
  1179. clock_t ret;
  1180. int err;
  1181. (void) fprintf(stderr, "entering times(%p)\n", buffer);
  1182. (void) fflush(stderr);
  1183. ret = times(buffer);
  1184. err = errno;
  1185. (void) fprintf(stderr, "exiting times with %ld", (long) ret);
  1186. if (ret == (clock_t) -1)
  1187. (void) fprintf(stderr, "; errno: %d", err);
  1188. (void) fprintf(stderr, "\n");
  1189. (void) fflush(stderr);
  1190. return ret;
  1191. }
  1192. char *posix_debug_getenv (const char *name)
  1193. {
  1194. char *ret;
  1195. (void) fprintf(stderr, "entering getenv(%s)\n", canonical_string(name));
  1196. (void) fflush(stderr);
  1197. ret = getenv(name);
  1198. (void) fprintf(stderr, "exiting getenv with %s\n", canonical_string(ret));
  1199. (void) fflush(stderr);
  1200. return ret;
  1201. }
  1202. char *posix_debug_ctermid (char *s)
  1203. {
  1204. char *ret;
  1205. (void) fprintf(stderr, "entering ctermid(%s)\n", canonical_string(s));
  1206. (void) fflush(stderr);
  1207. ret = ctermid(s);
  1208. (void) fprintf(stderr, "exiting ctermid with %s\n", canonical_string(ret));
  1209. (void) fflush(stderr);
  1210. return ret;
  1211. }
  1212. char *posix_debug_ttyname (int fildes)
  1213. {
  1214. char *ret;
  1215. (void) fprintf(stderr, "entering ttyname(%d)\n", fildes);
  1216. (void) fflush(stderr);
  1217. ret = ttyname(fildes);
  1218. (void) fprintf(stderr, "exiting ttyname with %s\n", canonical_string(ret));
  1219. (void) fflush(stderr);
  1220. return ret;
  1221. }
  1222. int posix_debug_isatty (int fildes)
  1223. {
  1224. int ret;
  1225. (void) fprintf(stderr, "entering isatty(%d)\n", fildes);
  1226. (void) fflush(stderr);
  1227. ret = isatty(fildes);
  1228. (void) fprintf(stderr, "exiting isatty with %d\n", ret);
  1229. (void) fflush(stderr);
  1230. return ret;
  1231. }
  1232. long posix_debug_sysconf (int name)
  1233. {
  1234. long ret;
  1235. int err, saved_errno;
  1236. (void) fprintf(stderr, "entering sysconf(%s)\n", scname_string(name));
  1237. (void) fflush(stderr);
  1238. saved_errno = errno;
  1239. ret = sysconf(name);
  1240. err = errno;
  1241. (void) fprintf(stderr, "exiting sysconf with %ld", (long) ret);
  1242. if (ret == (long) -1 && saved_errno != err)
  1243. (void) fprintf(stderr, "; errno: %d", err);
  1244. (void) fprintf(stderr, "\n");
  1245. (void) fflush(stderr);
  1246. return ret;
  1247. }
  1248. /* Section 5: Files and Directories */
  1249. DIR *posix_debug_opendir (const char *dirname)
  1250. {
  1251. DIR *ret;
  1252. int err;
  1253. (void) fprintf(stderr, "entering opendir(%s)\n", canonical_string(dirname));
  1254. (void) fflush(stderr);
  1255. ret = opendir(dirname);
  1256. err = errno;
  1257. (void) fprintf(stderr, "exiting opendir with %p", ret);
  1258. if (ret == NULL)
  1259. (void) fprintf(stderr, "; errno: %d", err);
  1260. (void) fprintf(stderr, "\n");
  1261. (void) fflush(stderr);
  1262. return ret;
  1263. }
  1264. struct dirent *posix_debug_readdir (DIR *dirp)
  1265. {
  1266. struct dirent *ret;
  1267. int err;
  1268. (void) fprintf(stderr, "entering readdir(%p)\n", dirp);
  1269. (void) fflush(stderr);
  1270. ret = readdir(dirp);
  1271. err = errno;
  1272. (void) fprintf(stderr, "exiting readdir with %p", ret);
  1273. if (ret == NULL)
  1274. (void) fprintf(stderr, "; errno: %d", err);
  1275. (void) fprintf(stderr, "\n");
  1276. (void) fflush(stderr);
  1277. return ret;
  1278. }
  1279. void posix_debug_rewinddir (DIR *dirp)
  1280. {
  1281. int err, saved_errno;
  1282. (void) fprintf(stderr, "entering rewinddir(%p)\n", dirp);
  1283. (void) fflush(stderr);
  1284. saved_errno = errno;
  1285. rewinddir(dirp);
  1286. err = errno;
  1287. (void) fprintf(stderr, "exiting rewinddir");
  1288. if (saved_errno != err)
  1289. (void) fprintf(stderr, "; errno: %d\n", err);
  1290. (void) fprintf(stderr, "\n");
  1291. (void) fflush(stderr);
  1292. }
  1293. int posix_debug_closedir (DIR *dirp)
  1294. {
  1295. int ret, err;
  1296. (void) fprintf(stderr, "entering closedir(%p)\n", dirp);
  1297. (void) fflush(stderr);
  1298. ret = closedir(dirp);
  1299. err = errno;
  1300. (void) fprintf(stderr, "exiting closedir with %d", ret);
  1301. if (ret == -1)
  1302. (void) fprintf(stderr, "; errno: %d", err);
  1303. (void) fprintf(stderr, "\n");
  1304. (void) fflush(stderr);
  1305. return ret;
  1306. }
  1307. int posix_debug_chdir (const char *path)
  1308. {
  1309. int ret, err;
  1310. (void) fprintf(stderr, "entering chdir(%s)\n", canonical_string(path));
  1311. (void) fflush(stderr);
  1312. ret = chdir(path);
  1313. err = errno;
  1314. (void) fprintf(stderr, "exiting chdir with %d", ret);
  1315. if (ret == -1)
  1316. (void) fprintf(stderr, "; errno: %d", err);
  1317. (void) fprintf(stderr, "\n");
  1318. (void) fflush(stderr);
  1319. return ret;
  1320. }
  1321. char *posix_debug_getcwd (char *buf, size_t size)
  1322. {
  1323. char *ret;
  1324. int err;
  1325. (void) fprintf(stderr, "entering getcwd(%p, %lu)\n", buf, (unsigned long) size);
  1326. (void) fflush(stderr);
  1327. ret = getcwd(buf, size);
  1328. err = errno;
  1329. (void) fprintf(stderr, "exiting getcwd with %s", canonical_string(ret));
  1330. if (ret == NULL)
  1331. (void) fprintf(stderr, "; errno: %d", err);
  1332. (void) fprintf(stderr, "\n");
  1333. (void) fflush(stderr);
  1334. return ret;
  1335. }
  1336. int posix_debug_open (const char *path, int oflag, ...)
  1337. {
  1338. va_list va;
  1339. int ret, err;
  1340. mode_t mode;
  1341. va_start(va, oflag);
  1342. (void) fprintf(stderr, "entering open(%s, %s", canonical_string(path), oflag_string(oflag));
  1343. if (oflag & O_CREAT)
  1344. {
  1345. mode = va_arg(va, mode_t);
  1346. (void) fprintf(stderr, ", %s", mode_string(mode));
  1347. }
  1348. va_end(va);
  1349. (void) fprintf(stderr, ")\n");
  1350. (void) fflush(stderr);
  1351. if (oflag & O_CREAT)
  1352. ret = open(path, oflag, mode);
  1353. else
  1354. ret = open(path, oflag);
  1355. err = errno;
  1356. (void) fprintf(stderr, "exiting open with %d", ret);
  1357. if (ret == -1)
  1358. (void) fprintf(stderr, "; errno: %d", err);
  1359. (void) fprintf(stderr, "\n");
  1360. (void) fflush(stderr);
  1361. return ret;
  1362. }
  1363. int posix_debug_creat (const char *path, mode_t mode)
  1364. {
  1365. int ret, err;
  1366. (void) fprintf(stderr, "entering creat(%s, %s)\n", canonical_string(path), mode_string(mode));
  1367. (void) fflush(stderr);
  1368. ret = creat(path, mode);
  1369. err = errno;
  1370. (void) fprintf(stderr, "exiting creat with %d", ret);
  1371. if (ret == -1)
  1372. (void) fprintf(stderr, "; errno: %d", err);
  1373. (void) fprintf(stderr, "\n");
  1374. (void) fflush(stderr);
  1375. return ret;
  1376. }
  1377. mode_t posix_debug_umask (mode_t cmask)
  1378. {
  1379. mode_t ret;
  1380. (void) fprintf(stderr, "entering umask(%s)\n", mode_string(cmask));
  1381. (void) fflush(stderr);
  1382. ret = umask(cmask);
  1383. (void) fprintf(stderr, "exiting umask with %s\n", mode_string(ret));
  1384. (void) fflush(stderr);
  1385. return ret;
  1386. }
  1387. int posix_debug_link (const char *existing, const char *new)
  1388. {
  1389. int ret, err;
  1390. (void) fprintf(stderr, "entering link(%s, %s)\n", canonical_string(existing), canonical_string(new));
  1391. (void) fflush(stderr);
  1392. ret = link(existing, new);
  1393. err = errno;
  1394. (void) fprintf(stderr, "exiting link with %d", ret);
  1395. if (ret == -1)
  1396. (void) fprintf(stderr, "; errno: %d", err);
  1397. (void) fprintf(stderr, "\n");
  1398. (void) fflush(stderr);
  1399. return ret;
  1400. }
  1401. int posix_debug_mkdir (const char *path, mode_t mode)
  1402. {
  1403. int ret, err;
  1404. (void) fprintf(stderr, "entering mkdir(%s, %s)\n", canonical_string(path), mode_string(mode));
  1405. (void) fflush(stderr);
  1406. ret = mkdir(path, mode);
  1407. err = errno;
  1408. (void) fprintf(stderr, "exiting mkdir with %d", ret);
  1409. if (ret == -1)
  1410. (void) fprintf(stderr, "; errno: %d", err);
  1411. (void) fprintf(stderr, "\n");
  1412. (void) fflush(stderr);
  1413. return ret;
  1414. }
  1415. int posix_debug_mkfifo (const char *path, mode_t mode)
  1416. {
  1417. int ret, err;
  1418. (void) fprintf(stderr, "entering mkfifo(%s, %s)\n", canonical_string(path), mode_string(mode));
  1419. (void) fflush(stderr);
  1420. ret = mkfifo(path, mode);
  1421. err = errno;
  1422. (void) fprintf(stderr, "exiting mkfifo with %d", ret);
  1423. if (ret == -1)
  1424. (void) fprintf(stderr, "; errno: %d", err);
  1425. (void) fprintf(stderr, "\n");
  1426. (void) fflush(stderr);
  1427. return ret;
  1428. }
  1429. int posix_debug_unlink (const char *path)
  1430. {
  1431. int ret, err;
  1432. (void) fprintf(stderr, "entering unlink(%s)\n", canonical_string(path));
  1433. (void) fflush(stderr);
  1434. ret = unlink(path);
  1435. err = errno;
  1436. (void) fprintf(stderr, "exiting unlink with %d", ret);
  1437. if (ret == -1)
  1438. (void) fprintf(stderr, "; errno: %d", err);
  1439. (void) fprintf(stderr, "\n");
  1440. (void) fflush(stderr);
  1441. return ret;
  1442. }
  1443. int posix_debug_rmdir (const char *path)
  1444. {
  1445. int ret, err;
  1446. (void) fprintf(stderr, "entering rmdir(%s)\n", canonical_string(path));
  1447. (void) fflush(stderr);
  1448. ret = rmdir(path);
  1449. err = errno;
  1450. (void) fprintf(stderr, "exiting rmdir with %d", ret);
  1451. if (ret == -1)
  1452. (void) fprintf(stderr, "; errno: %d", err);
  1453. (void) fprintf(stderr, "\n");
  1454. (void) fflush(stderr);
  1455. return ret;
  1456. }
  1457. int posix_debug_rename (const char *old, const char *new)
  1458. {
  1459. int ret, err;
  1460. (void) fprintf(stderr, "entering rename(%s, %s)\n", canonical_string(old), canonical_string(new));
  1461. (void) fflush(stderr);
  1462. ret = rename(old, new);
  1463. err = errno;
  1464. (void) fprintf(stderr, "exiting rename with %d", ret);
  1465. if (ret == -1)
  1466. (void) fprintf(stderr, "; errno: %d", err);
  1467. (void) fprintf(stderr, "\n");
  1468. (void) fflush(stderr);
  1469. return ret;
  1470. }
  1471. int posix_debug_stat (const char *path, struct stat *buf)
  1472. {
  1473. int ret, err;
  1474. (void) fprintf(stderr, "entering stat(%s, %p)\n", canonical_string(path), buf);
  1475. (void) fflush(stderr);
  1476. ret = stat(path, buf);
  1477. err = errno;
  1478. (void) fprintf(stderr, "exiting stat with %d", ret);
  1479. if (ret == -1)
  1480. (void) fprintf(stderr, "; errno: %d", err);
  1481. (void) fprintf(stderr, "\n");
  1482. (void) fflush(stderr);
  1483. return ret;
  1484. }
  1485. int posix_debug_fstat (int fildes, struct stat *buf)
  1486. {
  1487. int ret, err;
  1488. (void) fprintf(stderr, "entering fstat(%d, %p)\n", fildes, buf);
  1489. (void) fflush(stderr);
  1490. ret = fstat(fildes, buf);
  1491. err = errno;
  1492. (void) fprintf(stderr, "exiting fstat with %d", ret);
  1493. if (ret == -1)
  1494. (void) fprintf(stderr, "; errno: %d", err);
  1495. (void) fprintf(stderr, "\n");
  1496. (void) fflush(stderr);
  1497. return ret;
  1498. }
  1499. int posix_debug_access (const char *path, int amode)
  1500. {
  1501. int ret, err;
  1502. (void) fprintf(stderr, "entering access(%s, %s)\n", canonical_string(path), amode_string(amode));
  1503. (void) fflush(stderr);
  1504. ret = access(path, amode);
  1505. err = errno;
  1506. (void) fprintf(stderr, "exiting access with %d", ret);
  1507. if (ret == -1)
  1508. (void) fprintf(stderr, "; errno: %d", err);
  1509. (void) fprintf(stderr, "\n");
  1510. (void) fflush(stderr);
  1511. return ret;
  1512. }
  1513. int posix_debug_chmod (const char *path, mode_t mode)
  1514. {
  1515. int ret, err;
  1516. (void) fprintf(stderr, "entering chmod(%s, %s)\n", canonical_string(path), mode_string(mode));
  1517. (void) fflush(stderr);
  1518. ret = chmod(path, mode);
  1519. err = errno;
  1520. (void) fprintf(stderr, "exiting chmod with %d", ret);
  1521. if (ret == -1)
  1522. (void) fprintf(stderr, "; errno: %d", err);
  1523. (void) fprintf(stderr, "\n");
  1524. (void) fflush(stderr);
  1525. return ret;
  1526. }
  1527. int posix_debug_chown (const char *path, uid_t owner, gid_t group)
  1528. {
  1529. int ret, err;
  1530. (void) fprintf(stderr, "entering chown(%s, %lu, %lu)\n",
  1531. canonical_string(path), (unsigned long) owner, (unsigned long) group);
  1532. (void) fflush(stderr);
  1533. ret = chown(path, owner, group);
  1534. err = errno;
  1535. (void) fprintf(stderr, "exiting chown with %d", ret);
  1536. if (ret == -1)
  1537. (void) fprintf(stderr, "; errno: %d", err);
  1538. (void) fprintf(stderr, "\n");
  1539. (void) fflush(stderr);
  1540. return ret;
  1541. }
  1542. int posix_debug_utime (const char *path, const struct utimbuf *times)
  1543. {
  1544. int ret, err;
  1545. (void) fprintf(stderr, "entering utime(%s, %p)\n", canonical_string(path), times);
  1546. (void) fflush(stderr);
  1547. ret = utime(path, times);
  1548. err = errno;
  1549. (void) fprintf(stderr, "exiting utime with %d", ret);
  1550. if (ret == -1)
  1551. (void) fprintf(stderr, "; errno: %d", err);
  1552. (void) fprintf(stderr, "\n");
  1553. (void) fflush(stderr);
  1554. return ret;
  1555. }
  1556. long posix_debug_pathconf (const char *path, int name)
  1557. {
  1558. long ret;
  1559. int err, saved_errno;
  1560. (void) fprintf(stderr, "entering pathconf(%s, %s)\n", canonical_string(path), pcname_string(name));
  1561. (void) fflush(stderr);
  1562. saved_errno = errno;
  1563. ret = pathconf(path, name);
  1564. err = errno;
  1565. (void) fprintf(stderr, "exiting pathconf with %ld", (long) ret);
  1566. if (ret == (long) -1 && saved_errno != err)
  1567. (void) fprintf(stderr, "; errno: %d", err);
  1568. (void) fprintf(stderr, "\n");
  1569. (void) fflush(stderr);
  1570. return ret;
  1571. }
  1572. long posix_debug_fpathconf (int fildes, int name)
  1573. {
  1574. long ret;
  1575. int err, saved_errno;
  1576. (void) fprintf(stderr, "entering fpathconf(%d, %s)\n", fildes, pcname_string(name));
  1577. (void) fflush(stderr);
  1578. saved_errno = errno;
  1579. ret = fpathconf(fildes, name);
  1580. err = errno;
  1581. (void) fprintf(stderr, "exiting fpathconf with %ld", (long) ret);
  1582. if (ret == (long) -1 && saved_errno != err)
  1583. (void) fprintf(stderr, "; errno: %d", err);
  1584. (void) fprintf(stderr, "\n");
  1585. (void) fflush(stderr);
  1586. return ret;
  1587. }
  1588. /* Section 6: Input and Output Primitives */
  1589. int posix_debug_pipe (int fildes[2])
  1590. {
  1591. int ret, err;
  1592. (void) fprintf(stderr, "entering pipe(%p)\n", fildes);
  1593. (void) fflush(stderr);
  1594. ret = pipe(fildes);
  1595. err = errno;
  1596. (void) fprintf(stderr, "exiting pipe with %d", ret);
  1597. if (ret == -1)
  1598. (void) fprintf(stderr, "; errno: %d", err);
  1599. (void) fprintf(stderr, "\n");
  1600. (void) fflush(stderr);
  1601. return ret;
  1602. }
  1603. int posix_debug_dup (int fildes)
  1604. {
  1605. int ret, err;
  1606. (void) fprintf(stderr, "entering dup(%d)\n", fildes);
  1607. (void) fflush(stderr);
  1608. ret = dup(fildes);
  1609. err = errno;
  1610. (void) fprintf(stderr, "exiting dup with %d", ret);
  1611. if (ret == -1)
  1612. (void) fprintf(stderr, "; errno: %d", err);
  1613. (void) fprintf(stderr, "\n");
  1614. (void) fflush(stderr);
  1615. return ret;
  1616. }
  1617. int posix_debug_dup2 (int fildes, int fildes2)
  1618. {
  1619. int ret, err;
  1620. (void) fprintf(stderr, "entering dup2(%d, %d)\n", fildes, fildes2);
  1621. (void) fflush(stderr);
  1622. ret = dup2(fildes, fildes2);
  1623. err = errno;
  1624. (void) fprintf(stderr, "exiting dup2 with %d", ret);
  1625. if (ret == -1)
  1626. (void) fprintf(stderr, "; errno: %d", err);
  1627. (void) fprintf(stderr, "\n");
  1628. (void) fflush(stderr);
  1629. return ret;
  1630. }
  1631. int posix_debug_close (int fildes)
  1632. {
  1633. int ret, err;
  1634. (void) fprintf(stderr, "entering close(%d)\n", fildes);
  1635. (void) fflush(stderr);
  1636. ret = close(fildes);
  1637. err = errno;
  1638. (void) fprintf(stderr, "exiting close with %d", ret);
  1639. if (ret == -1)
  1640. (void) fprintf(stderr, "; errno: %d", err);
  1641. (void) fprintf(stderr, "\n");
  1642. (void) fflush(stderr);
  1643. return ret;
  1644. }
  1645. ssize_t posix_debug_read (int fildes, void *buf, size_t nbyte)
  1646. {
  1647. ssize_t ret;
  1648. int err;
  1649. (void) fprintf(stderr, "entering read(%d, %p, %lu)\n", fildes, buf, (unsigned long) nbyte);
  1650. (void) fflush(stderr);
  1651. ret = read(fildes, buf, nbyte);
  1652. err = errno;
  1653. (void) fprintf(stderr, "exiting read with %ld", (long) ret);
  1654. if (ret == (ssize_t) -1)
  1655. (void) fprintf(stderr, "; errno: %d", err);
  1656. (void) fprintf(stderr, "\n");
  1657. (void) fflush(stderr);
  1658. return ret;
  1659. }
  1660. ssize_t posix_debug_write (int fildes, const void *buf, size_t nbyte)
  1661. {
  1662. ssize_t ret;
  1663. int err;
  1664. (void) fprintf(stderr, "entering write(%d, %p, %lu)\n", fildes, buf, (unsigned long) nbyte);
  1665. (void) fflush(stderr);
  1666. ret = write(fildes, buf, nbyte);
  1667. err = errno;
  1668. (void) fprintf(stderr, "exiting write with %ld", (long) ret);
  1669. if (ret == (ssize_t) -1)
  1670. (void) fprintf(stderr, "; errno: %d", err);
  1671. (void) fprintf(stderr, "\n");
  1672. (void) fflush(stderr);
  1673. return ret;
  1674. }
  1675. int posix_debug_fcntl (int fildes, int cmd, ...)
  1676. {
  1677. va_list va;
  1678. int ret, err, iarg;
  1679. struct flock *farg;
  1680. va_start(va, cmd);
  1681. (void) fprintf(stderr, "entering fcntl(%d, %s", fildes, cmd_string(cmd));
  1682. if (cmd == F_DUPFD || cmd == F_SETFD || cmd == F_SETFL)
  1683. {
  1684. iarg = va_arg(va, int);
  1685. (void) fprintf(stderr, ", %d", iarg);
  1686. }
  1687. else if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
  1688. {
  1689. farg = va_arg(va, struct flock *);
  1690. (void) fprintf(stderr, ", %p", farg);
  1691. }
  1692. va_end(va);
  1693. (void) fprintf(stderr, ")\n");
  1694. (void) fflush(stderr);
  1695. if (cmd == F_DUPFD || cmd == F_SETFD || cmd == F_SETFL)
  1696. ret = fcntl(fildes, cmd, iarg);
  1697. else if (cmd == F_GETLK || cmd == F_SETLK || cmd == F_SETLKW)
  1698. ret = fcntl(fildes, cmd, farg);
  1699. else
  1700. ret = fcntl(fildes, cmd);
  1701. err = errno;
  1702. (void) fprintf(stderr, "exiting fcntl with %d", ret);
  1703. if (ret == -1)
  1704. (void) fprintf(stderr, "; errno: %d", err);
  1705. (void) fprintf(stderr, "\n");
  1706. (void) fflush(stderr);
  1707. return ret;
  1708. }
  1709. off_t posix_debug_lseek (int fildes, off_t offset, int whence)
  1710. {
  1711. off_t ret;
  1712. int err;
  1713. (void) fprintf(stderr, "entering lseek(%d, %ld, %s)\n", fildes, (long) offset, whence_string(whence));
  1714. (void) fflush(stderr);
  1715. ret = lseek(fildes, offset, whence);
  1716. err = errno;
  1717. (void) fprintf(stderr, "exiting lseek with %ld", (long) ret);
  1718. if (ret == (off_t) -1)
  1719. (void) fprintf(stderr, "; errno: %d", err);
  1720. (void) fprintf(stderr, "\n");
  1721. (void) fflush(stderr);
  1722. return ret;
  1723. }
  1724. /* Section 7: Device- and Class-Specific Functions */
  1725. speed_t posix_debug_cfgetospeed (const struct termios *termios_p)
  1726. {
  1727. speed_t ret;
  1728. int err, saved_errno;
  1729. (void) fprintf(stderr, "entering cfgetospeed(%p)\n", termios_p);
  1730. (void) fflush(stderr);
  1731. saved_errno = errno;
  1732. ret = cfgetospeed(termios_p);
  1733. err = errno;
  1734. (void) fprintf(stderr, "exiting cfgetospeed with %s", speed_string(ret));
  1735. if (saved_errno != err)
  1736. (void) fprintf(stderr, "; errno: %d", err);
  1737. (void) fprintf(stderr, "\n");
  1738. (void) fflush(stderr);
  1739. return ret;
  1740. }
  1741. int posix_debug_cfsetospeed (struct termios *termios_p, speed_t speed)
  1742. {
  1743. int ret, err;
  1744. (void) fprintf(stderr, "entering cfsetospeed(%p, %s)\n", termios_p, speed_string(speed));
  1745. (void) fflush(stderr);
  1746. ret = cfsetospeed(termios_p, speed);
  1747. err = errno;
  1748. (void) fprintf(stderr, "exiting cfsetospeed with %d", ret);
  1749. if (ret == -1)
  1750. (void) fprintf(stderr, "; errno: %d", err);
  1751. (void) fprintf(stderr, "\n");
  1752. (void) fflush(stderr);
  1753. return ret;
  1754. }
  1755. speed_t posix_debug_cfgetispeed (const struct termios *termios_p)
  1756. {
  1757. speed_t ret;
  1758. int err, saved_errno;
  1759. (void) fprintf(stderr, "entering cfgetispeed(%p)\n", termios_p);
  1760. (void) fflush(stderr);
  1761. saved_errno = errno;
  1762. ret = cfgetispeed(termios_p);
  1763. err = errno;
  1764. (void) fprintf(stderr, "exiting cfgetispeed with %s", speed_string(ret));
  1765. if (saved_errno != err)
  1766. (void) fprintf(stderr, "; errno: %d", err);
  1767. (void) fprintf(stderr, "\n");
  1768. (void) fflush(stderr);
  1769. return ret;
  1770. }
  1771. int posix_debug_cfsetispeed (struct termios *termios_p, speed_t speed)
  1772. {
  1773. int ret, err;
  1774. (void) fprintf(stderr, "entering cfsetispeed(%p, %s)\n", termios_p, speed_string(speed));
  1775. (void) fflush(stderr);
  1776. ret = cfsetispeed(termios_p, speed);
  1777. err = errno;
  1778. (void) fprintf(stderr, "exiting cfsetispeed with %d", ret);
  1779. if (ret == -1)
  1780. (void) fprintf(stderr, "; errno: %d", err);
  1781. (void) fprintf(stderr, "\n");
  1782. (void) fflush(stderr);
  1783. return ret;
  1784. }
  1785. int posix_debug_tcgetattr (int fildes, struct termios *termios_p)
  1786. {
  1787. int ret, err;
  1788. (void) fprintf(stderr, "entering tcgetattr(%d, %p)\n", fildes, termios_p);
  1789. (void) fflush(stderr);
  1790. ret = tcgetattr(fildes, termios_p);
  1791. err = errno;
  1792. (void) fprintf(stderr, "exiting tcgetattr with %d", ret);
  1793. if (ret == -1)
  1794. (void) fprintf(stderr, "; errno: %d", err);
  1795. (void) fprintf(stderr, "\n");
  1796. (void) fflush(stderr);
  1797. return ret;
  1798. }
  1799. int posix_debug_tcsetattr (int fildes, int optional_actions, const struct termios *termios_p)
  1800. {
  1801. int ret, err;
  1802. (void) fprintf(stderr, "entering tcsetattr(%d, %s, %p)\n", fildes, optact_string(optional_actions), termios_p);
  1803. (void) fflush(stderr);
  1804. ret = tcsetattr(fildes, optional_actions, termios_p);
  1805. err = errno;
  1806. (void) fprintf(stderr, "exiting tcsetattr with %d", ret);
  1807. if (ret == -1)
  1808. (void) fprintf(stderr, "; errno: %d", err);
  1809. (void) fprintf(stderr, "\n");
  1810. (void) fflush(stderr);
  1811. return ret;
  1812. }
  1813. int posix_debug_tcsendbreak (int fildes, int duration)
  1814. {
  1815. int ret, err;
  1816. (void) fprintf(stderr, "entering tcsendbreak(%d, %d)\n", fildes, duration);
  1817. (void) fflush(stderr);
  1818. ret = tcsendbreak(fildes, duration);
  1819. err = errno;
  1820. (void) fprintf(stderr, "exiting tcsendbreak with %d", ret);
  1821. if (ret == -1)
  1822. (void) fprintf(stderr, "; errno: %d", err);
  1823. (void) fprintf(stderr, "\n");
  1824. (void) fflush(stderr);
  1825. return ret;
  1826. }
  1827. int posix_debug_tcdrain (int fildes)
  1828. {
  1829. int ret, err;
  1830. (void) fprintf(stderr, "entering tcdrain(%d)\n", fildes);
  1831. (void) fflush(stderr);
  1832. ret = tcdrain(fildes);
  1833. err = errno;
  1834. (void) fprintf(stderr, "exiting tcdrain with %d", ret);
  1835. if (ret == -1)
  1836. (void) fprintf(stderr, "; errno: %d", err);
  1837. (void) fprintf(stderr, "\n");
  1838. (void) fflush(stderr);
  1839. return ret;
  1840. }
  1841. int posix_debug_tcflush (int fildes, int queue_selector)
  1842. {
  1843. int ret, err;
  1844. (void) fprintf(stderr, "entering tcflush(%d, %s)\n", fildes, queue_string(queue_selector));
  1845. (void) fflush(stderr);
  1846. ret = tcflush(fildes, queue_selector);
  1847. err = errno;
  1848. (void) fprintf(stderr, "exiting tcflush with %d", ret);
  1849. if (ret == -1)
  1850. (void) fprintf(stderr, "; errno: %d", err);
  1851. (void) fprintf(stderr, "\n");
  1852. (void) fflush(stderr);
  1853. return ret;
  1854. }
  1855. int posix_debug_tcflow (int fildes, int action)
  1856. {
  1857. int ret, err;
  1858. (void) fprintf(stderr, "entering tcflow(%d, %s)\n", fildes, action_string(action));
  1859. (void) fflush(stderr);
  1860. ret = tcflow(fildes, action);
  1861. err = errno;
  1862. (void) fprintf(stderr, "exiting tcflow with %d", ret);
  1863. if (ret == -1)
  1864. (void) fprintf(stderr, "; errno: %d", err);
  1865. (void) fprintf(stderr, "\n");
  1866. (void) fflush(stderr);
  1867. return ret;
  1868. }
  1869. pid_t posix_debug_tcgetpgrp (int fildes)
  1870. {
  1871. pid_t ret;
  1872. int err;
  1873. (void) fprintf(stderr, "entering tcgetpgrp(%d)\n", fildes);
  1874. (void) fflush(stderr);
  1875. ret = tcgetpgrp(fildes);
  1876. err = errno;
  1877. (void) fprintf(stderr, "exiting tcgetpgrp with %ld", (long) ret);
  1878. if (ret == (pid_t) -1)
  1879. (void) fprintf(stderr, "; errno: %d", err);
  1880. (void) fprintf(stderr, "\n");
  1881. (void) fflush(stderr);
  1882. return ret;
  1883. }
  1884. int posix_debug_tcsetpgrp (int fildes, pid_t pgrp_id)
  1885. {
  1886. int ret, err;
  1887. (void) fprintf(stderr, "entering tcsetpgrp(%d, %ld)\n", fildes, (long) pgrp_id);
  1888. (void) fflush(stderr);
  1889. ret = tcsetpgrp(fildes, pgrp_id);
  1890. err = errno;
  1891. (void) fprintf(stderr, "exiting tcsetpgrp with %d", ret);
  1892. if (ret == -1)
  1893. (void) fprintf(stderr, "; errno: %d", err);
  1894. (void) fprintf(stderr, "\n");
  1895. (void) fflush(stderr);
  1896. return ret;
  1897. }
  1898. /* Section 8.2: C Language Input/Output Functions */
  1899. int posix_debug_fileno (FILE *stream)
  1900. {
  1901. int ret, err;
  1902. (void) fprintf(stderr, "entering fileno(%p)\n", stream);
  1903. (void) fflush(stderr);
  1904. ret = fileno(stream);
  1905. err = errno;
  1906. (void) fprintf(stderr, "exiting fileno with %d", ret);
  1907. if (ret == -1)
  1908. (void) fprintf(stderr, "; errno: %d", err);
  1909. (void) fprintf(stderr, "\n");
  1910. (void) fflush(stderr);
  1911. return ret;
  1912. }
  1913. FILE *posix_debug_fdopen (int fildes, const char *type)
  1914. {
  1915. FILE *ret;
  1916. int err;
  1917. (void) fprintf(stderr, "entering fdopen(%d, %s)\n", fildes, canonical_string(type));
  1918. (void) fflush(stderr);
  1919. ret = fdopen(fildes, type);
  1920. err = errno;
  1921. (void) fprintf(stderr, "exiting fdopen with %p", ret);
  1922. if (ret == NULL)
  1923. (void) fprintf(stderr, "; errno: %d", err);
  1924. (void) fprintf(stderr, "\n");
  1925. (void) fflush(stderr);
  1926. return ret;
  1927. }
  1928. /* Section 8.3: Other C Language Functions */
  1929. void posix_debug_siglongjmp (sigjmp_buf env, int val)
  1930. {
  1931. int err, saved_errno;
  1932. (void) fprintf(stderr, "entering siglongjmp(%p, %d)\n", env, val);
  1933. (void) fflush(stderr);
  1934. saved_errno = errno;
  1935. siglongjmp(env, val);
  1936. err = errno;
  1937. (void) fprintf(stderr, "exiting siglongjmp");
  1938. if (saved_errno != err)
  1939. (void) fprintf(stderr, "; errno: %d\n", err);
  1940. (void) fprintf(stderr, "\n");
  1941. (void) fflush(stderr);
  1942. }
  1943. void posix_debug_tzset (void)
  1944. {
  1945. int err, saved_errno;
  1946. (void) fprintf(stderr, "entering tzset()\n");
  1947. (void) fflush(stderr);
  1948. saved_errno = errno;
  1949. tzset();
  1950. err = errno;
  1951. (void) fprintf(stderr, "exiting tzset");
  1952. if (saved_errno != err)
  1953. (void) fprintf(stderr, "; errno: %d\n", err);
  1954. (void) fprintf(stderr, "\n");
  1955. (void) fflush(stderr);
  1956. }
  1957. /* Section 9: System Databases */
  1958. struct group *posix_debug_getgrgid (gid_t gid)
  1959. {
  1960. struct group *ret;
  1961. int err;
  1962. (void) fprintf(stderr, "entering getgrgid(%lu)\n", (unsigned long) gid);
  1963. (void) fflush(stderr);
  1964. ret = getgrgid(gid);
  1965. err = errno;
  1966. (void) fprintf(stderr, "exiting getgrgid with %p", ret);
  1967. if (ret == NULL)
  1968. (void) fprintf(stderr, "; errno: %d", err);
  1969. (void) fprintf(stderr, "\n");
  1970. (void) fflush(stderr);
  1971. return ret;
  1972. }
  1973. struct group *posix_debug_getgrnam (const char *name)
  1974. {
  1975. struct group *ret;
  1976. int err;
  1977. (void) fprintf(stderr, "entering getgrnam(%s)\n", canonical_string(name));
  1978. (void) fflush(stderr);
  1979. ret = getgrnam(name);
  1980. err = errno;
  1981. (void) fprintf(stderr, "exiting getgrnam with %p", ret);
  1982. if (ret == NULL)
  1983. (void) fprintf(stderr, "; errno: %d", err);
  1984. (void) fprintf(stderr, "\n");
  1985. (void) fflush(stderr);
  1986. return ret;
  1987. }
  1988. struct passwd *posix_debug_getpwuid (uid_t uid)
  1989. {
  1990. struct passwd *ret;
  1991. int err;
  1992. (void) fprintf(stderr, "entering getpwuid(%lu)\n", (unsigned long) uid);
  1993. (void) fflush(stderr);
  1994. ret = getpwuid(uid);
  1995. err = errno;
  1996. (void) fprintf(stderr, "exiting getpwuid with %p", ret);
  1997. if (ret == NULL)
  1998. (void) fprintf(stderr, "; errno: %d", err);
  1999. (void) fprintf(stderr, "\n");
  2000. (void) fflush(stderr);
  2001. return ret;
  2002. }
  2003. struct passwd *posix_debug_getpwnam (const char *name)
  2004. {
  2005. struct passwd *ret;
  2006. int err;
  2007. (void) fprintf(stderr, "entering getpwnam(%s)\n", canonical_string(name));
  2008. (void) fflush(stderr);
  2009. ret = getpwnam(name);
  2010. err = errno;
  2011. (void) fprintf(stderr, "exiting getpwnam with %p", ret);
  2012. if (ret == NULL)
  2013. (void) fprintf(stderr, "; errno: %d", err);
  2014. (void) fprintf(stderr, "\n");
  2015. (void) fflush(stderr);
  2016. return ret;
  2017. }