1/* sysh.unx 2 The header file for the UNIX system dependent routines. 3 4 Copyright (C) 1991, 1992 Ian Lance Taylor 5 6 This file is part of the Taylor UUCP package. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as 10 published by the Free Software Foundation; either version 2 of the 11 License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 22 The author of the program may be contacted at ian@airs.com or 23 c/o AIRS, P.O. Box 520, Waltham, MA 02254. 24 25 $Log: sysh.unx,v $ 26 Revision 1.53 1992/03/30 15:29:58 ian 27 Added HAVE_SVR4_LOCKFILES 28 29 Revision 1.52 1992/03/16 01:23:08 ian 30 Make blocking writes optional 31 32 Revision 1.51 1992/03/15 07:15:42 ian 33 T. William Wells: don't use unblocked writes 34 35 Revision 1.50 1992/03/15 04:51:17 ian 36 Keep an array of signals we've received rather than a single variable 37 38 Revision 1.49 1992/03/15 01:54:46 ian 39 All execs are now done in isspawn, all waits are done in iswait 40 41 Revision 1.48 1992/03/12 21:52:21 ian 42 Corrected readdir prototype 43 44 Revision 1.47 1992/03/11 22:06:37 ian 45 Marty Shannon: added max-uuxqts command 46 47 Revision 1.46 1992/03/11 02:09:57 ian 48 Franc,ois Pinard: retry fork several times before giving up 49 50 Revision 1.45 1992/03/11 00:18:50 ian 51 Save temporary file if file send fails 52 53 Revision 1.44 1992/03/10 17:39:57 ian 54 Some systems don't permit both <termios.h> and <sys/ioctl.h> to be included 55 56 Revision 1.43 1992/03/09 22:07:36 ian 57 Wait for terminal output to drain at various points 58 59 Revision 1.42 1992/03/03 21:01:20 ian 60 Use strict timeout in fsserial_read, eliminate all race conditions 61 62 Revision 1.41 1992/03/02 04:53:07 ian 63 Marc Unangst: added HAVE_SCO_LOCKFILES configuration parameter 64 65 Revision 1.40 1992/02/29 01:06:59 ian 66 Chip Salzenberg: recheck file permissions before sending 67 68 Revision 1.39 1992/02/28 05:06:15 ian 69 T. William Wells: fsysdep_catch must be a macro 70 71 Revision 1.38 1992/02/27 05:40:54 ian 72 T. William Wells: detach from controlling terminal, handle signals safely 73 74 Revision 1.37 1992/02/23 03:26:51 ian 75 Overhaul to use automatic configure shell script 76 77 Revision 1.36 1992/02/20 04:18:59 ian 78 Added uustat 79 80 Revision 1.35 1992/02/09 05:10:50 ian 81 Added HAVE_MKDIR configuration parameter and mkdir emulation 82 83 Revision 1.34 1992/02/09 03:14:48 ian 84 Added HAVE_OLD_DIRECTORIES for systems without readdir routines 85 86 Revision 1.33 1992/02/09 02:41:58 ian 87 Added HAVE_DUP2 configuration parameter and dup2 emulation function 88 89 Revision 1.32 1992/02/08 23:34:41 ian 90 If we have neither getcwd nor getwd, fork /bin/pwd to get the cwd 91 92 Revision 1.31 1992/02/08 20:02:36 ian 93 Added HAVE_SETRET configuration option for systems without setjmp 94 95 Revision 1.30 1992/02/08 03:54:18 ian 96 Include <string.h> only in <uucp.h>, added 1992 copyright 97 98 Revision 1.29 1992/01/15 21:06:11 ian 99 Mike Park: some systems can't include <sys/time.h> and <time.h> together 100 101 Revision 1.28 1992/01/15 19:40:35 ian 102 Mike Park: handle HAVE_UNION_WAIT correctly and completely 103 104 Revision 1.27 1992/01/15 07:06:29 ian 105 Set configuration directory in Makefile rather than sysdep.h 106 107 Revision 1.26 1992/01/14 04:18:47 ian 108 Chip Salzenberg: added HAVE_USLEEP configuration parameter 109 110 Revision 1.25 1992/01/13 19:59:29 ian 111 Define LIBDIR in Makefile rather than in sysh.unx 112 113 Revision 1.24 1992/01/13 05:55:59 ian 114 Touched up a few comments 115 116 Revision 1.23 1992/01/13 05:53:04 ian 117 Mike Park: added HAVE_WAITPID and HAVE_WAIT4 configuration parameters 118 119 Revision 1.22 1992/01/11 17:11:11 ian 120 Hannu Strang: avoid compiler bug by not using -> in address constant 121 122 Revision 1.21 1992/01/04 21:43:24 ian 123 Chip Salzenberg: added ALLOW_FILENAME_ARGUMENTS to permit them 124 125 Revision 1.20 1991/12/29 00:55:23 ian 126 Monty Solomon: added HAVE_UNION_WAIT 127 128 Revision 1.19 1991/12/28 17:08:47 ian 129 John Theus: offer HAVE_GETWD as an alternative to using getcwd 130 131 Revision 1.18 1991/12/28 07:01:15 ian 132 Added HAVE_FTIME configuration option 133 134 Revision 1.17 1991/12/22 22:14:19 ian 135 Monty Solomon: added HAVE_UNISTD_H configuration parameter 136 137 Revision 1.16 1991/12/19 04:25:57 ian 138 Terry Gardner: configuration parameter to not use both NONBLOCK and NDELAY 139 140 Revision 1.15 1991/12/17 07:09:58 ian 141 Record statistics in fractions of a second 142 143 Revision 1.14 1991/12/11 04:21:37 ian 144 Arne Ludwig: merge in Arne Ludwig's patches for V2 and BNU style logging 145 146 Revision 1.13 1991/12/09 19:07:07 ian 147 Richard Todd: add HAVE_V2_LOCKFILES--binary number in lock file 148 149 Revision 1.12 1991/11/30 23:28:26 ian 150 Marty Shannon: some systems need a fake version of the rename system call 151 152 Revision 1.11 1991/11/26 01:45:42 ian 153 Marty Shannon: configuration option to not include <sys/wait.h> 154 155 Revision 1.10 1991/11/24 04:15:13 ian 156 Removed extraneous comment left by last revision 157 158 Revision 1.9 1991/11/21 21:49:38 ian 159 Brian Campbell: define all macros to avoid compiler warnings 160 161 Revision 1.8 1991/11/21 21:07:46 ian 162 Brian Campbell: offer ltrunc as an alternative to ftruncate 163 164 Revision 1.7 1991/11/10 19:24:22 ian 165 Added pffile protocol entry point for file level control 166 167 Revision 1.6 1991/11/08 22:52:34 ian 168 Brian Campbell: only include <sys/time.h> and <sys/ioctl.h> when needed 169 170 Revision 1.5 1991/11/08 22:11:45 ian 171 Brian Campbell: allow sigsetjmp as configuration option 172 173 Revision 1.4 1991/11/07 19:32:28 ian 174 Chip Salzenberg: allow LOCKDIR, and check that locking process exists 175 176 Revision 1.3 1991/09/19 16:15:58 ian 177 Chip Salzenberg: configuration option for permitting execution via sh 178 179 Revision 1.2 1991/09/19 03:06:04 ian 180 Chip Salzenberg: put BNU temporary files in system's directory 181 182 Revision 1.1 1991/09/10 19:45:50 ian 183 Initial revision 184 185 */ 186 187#ifndef SYSH_UNX_H 188 189#define SYSH_UNX_H 190 191/* We're might redefine fsysdep_catch, so make sure we've gotten the 192 prototype already. */ 193 194#ifndef SYSTEM_H 195#include "system.h" 196#endif 197 198/* Make sure the defines do not conflict. These are in this file 199 because they are Unix dependent. */ 200 201#if HAVE_V2_LOCKFILES + HAVE_BNU_LOCKFILES + HAVE_SCO_LOCKFILES + HAVE_SVR4_LOCKFILES != 1 202 #error LOCKFILES define not set or duplicated 203#endif 204 205/* SCO and SVR4 lockfiles are basically just like BNU lockfiles. */ 206#if HAVE_SCO_LOCKFILES || HAVE_SVR4_LOCKFILES 207#undef HAVE_BNU_LOCKFILES 208#define HAVE_BNU_LOCKFILES 1 209#endif 210 211#if HAVE_BSD_TTY + HAVE_SYSV_TERMIO + HAVE_POSIX_TERMIOS != 1 212 #error Terminal driver define not set or duplicated 213#endif 214 215#if SPOOLDIR_V2 + SPOOLDIR_BSD42 + SPOOLDIR_BSD43 + SPOOLDIR_BNU + SPOOLDIR_ULTRIX + SPOOLDIR_TAYLOR != 1 216 #error Spool directory define not set or duplicated 217#endif 218 219/* On Unix, binary files are the same as text files. */ 220#define BINREAD "r" 221#define BINWRITE "w" 222 223/* If we have sigaction, we can force system calls to not be 224 restarted. */ 225#if HAVE_SIGACTION 226#undef HAVE_RESTARTABLE_SYSCALLS 227#define HAVE_RESTARTABLE_SYSCALLS 0 228#endif 229 230/* If we have sigvec and SV_INTERRUPT is defined, we can force system 231 calls to not be restarted (signal.h is included by uucp.h before 232 this point, so SV_INTERRUPT will be defined by now if it it ever 233 is). */ 234#if HAVE_SIGVEC 235#ifdef SV_INTERRUPT 236#undef HAVE_RESTARTABLE_SYSCALLS 237#define HAVE_RESTARTABLE_SYSCALLS 0 238#endif 239#endif 240 241/* We don't handle sigset in combination with restartable system 242 calls, so we check for it although this combination will never 243 happen. */ 244#if ! HAVE_SIGACTION && ! HAVE_SIGVEC && HAVE_SIGSET 245#if HAVE_RESTARTABLE_SYSCALLS 246#undef HAVE_SIGSET 247#define HAVE_SIGSET 0 248#endif 249#endif 250 251/* If we don't have restartable system calls, we can ignore 252 fsysdep_catch, usysdep_start_catch and usysdep_end_catch. 253 Otherwise fsysdep_catch has to do a setjmp. */ 254 255#if ! HAVE_RESTARTABLE_SYSCALLS 256 257#define fsysdep_catch() (TRUE) 258#define usysdep_start_catch() 259#define usysdep_end_catch() 260#define CATCH_PROTECT 261 262#else /* HAVE_RESTARTABLE_SYSCALLS */ 263 264#if HAVE_SETRET && ! HAVE_SIGSETJMP 265#include <setret.h> 266#define setjmp setret 267#define longjmp longret 268#define jmp_buf ret_buf 269#else /* ! HAVE_SETRET || HAVE_SIGSETJMP */ 270#include <setjmp.h> 271#if HAVE_SIGSETJMP 272#undef setjmp 273#undef longjmp 274#undef jmp_buf 275#define setjmp(s) sigsetjmp ((s), TRUE) 276#define longjmp siglongjmp 277#define jmp_buf sigjmp_buf 278#endif /* HAVE_SIGSETJMP */ 279#endif /* ! HAVE_SETRET || HAVE_SIGSETJMP */ 280 281extern volatile sig_atomic_t fSjmp; 282extern volatile jmp_buf sSjmp_buf; 283 284#define fsysdep_catch() (setjmp (sSjmp_buf) == 0) 285 286#define usysdep_start_catch() (fSjmp = TRUE) 287 288#define usysdep_end_catch() (fSjmp = FALSE) 289 290#define CATCH_PROTECT volatile 291 292#endif /* HAVE_RESTARTABLE_SYSCALLS */ 293 294/* Get definitions for the terminal driver. */ 295 296#if HAVE_BSD_TTY 297#include <sgtty.h> 298typedef struct sgttyb sterminal; 299#define fgetterminfo(o, q) (ioctl ((o), TIOCGETP, (q)) == 0) 300#define fsetterminfo(o, q) (ioctl ((o), TIOCSETN, (q)) == 0) 301#define fsetterminfodrain(o, q) (ioctl ((o), TIOCSETP, (q)) == 0) 302#endif /* HAVE_BSD_TTY */ 303 304#if HAVE_SYSV_TERMIO 305#include <termio.h> 306typedef struct termio sterminal; 307#define fgetterminfo(o, q) (ioctl ((o), TCGETA, (q)) == 0) 308#define fsetterminfo(o, q) (ioctl ((o), TCSETA, (q)) == 0) 309#define fsetterminfodrain(o, q) (ioctl ((o), TCSETAW, (q)) == 0) 310#endif /* HAVE_SYSV_TERMIO */ 311 312#if HAVE_POSIX_TERMIOS 313#include <termios.h> 314typedef struct termios sterminal; 315#define fgetterminfo(o, q) (tcgetattr ((o), (q)) == 0) 316#define fsetterminfo(o, q) (tcsetattr ((o), TCSANOW, (q)) == 0) 317#define fsetterminfodrain(o, q) (tcsetattr ((o), TCSADRAIN, (q)) == 0) 318 319/* On some systems it is not possible to include both <sys/ioctl.h> 320 and <termios.h> in the same source files; I don't really know why. 321 On such systems, we pretend that we don't have <sys/ioctl.h>. */ 322#if ! HAVE_TERMIOS_AND_SYS_IOCTL_H 323#undef HAVE_SYS_IOCTL_H 324#define HAVE_SYS_IOCTL_H 0 325#endif 326 327#endif /* HAVE_POSIX_TERMIOS */ 328 329/* The root directory (this is needed by the system independent stuff 330 as the default for local-send). */ 331#define ZROOTDIR "/" 332 333/* The name of the execution directory within the spool directory 334 (this is need by the system independent uuxqt.c). */ 335#define XQTDIR ".Xqtdir" 336 337/* The name of the directory in which we preserve file transfers that 338 failed. */ 339#define PRESERVEDIR ".Preserve" 340 341#if HAVE_TAYLOR_CONFIG 342 343/* The names of the configuration files. These are appended to 344 NEWCONFIGLIB which is defined in Makefile. */ 345#define CONFIGFILE "/config" 346#define SYSFILE "/sys" 347#define PORTFILE "/port" 348#define DIALFILE "/dial" 349#define CALLFILE "/call" 350#define PASSWDFILE "/passwd" 351#define DIALCODEFILE "/dialcode" 352 353#endif /* HAVE_TAYLOR_CONFIG */ 354 355#if HAVE_V2_CONFIG 356 357/* The names of the various V2 configuration files. These are 358 appended to OLDCONFIGLIB which is defined in Makefile. */ 359#define V2_SYSTEMS "/L.sys" 360#define V2_DEVICES "/L-devices" 361#define V2_USERFILE "/USERFILE" 362#define V2_CMDS "/L.cmds" 363#define V2_DIALCODES "/L-dialcodes" 364 365#endif /* HAVE_V2_CONFIG */ 366 367#if HAVE_BNU_CONFIG 368 369/* The names of the BNU configuration files. These are appended to 370 OLDCONFIGLIB which is defined in Makefile. */ 371#define BNU_SYSFILES "/Sysfiles" 372#define BNU_SYSTEMS "/Systems" 373#define BNU_PERMISSIONS "/Permissions" 374#define BNU_DIALERS "/Dialers" 375#define BNU_DEVICES "/Devices" 376#define BNU_PERMISSIONS "/Permissions" 377#define BNU_DIALCODES "/Dialcodes" 378#define BNU_MAXUUXQTS "/Maxuuxqts" 379 380#endif /* HAVE_BNU_CONFIG */ 381 382/* Get some standard definitions. */ 383 384#include <sys/types.h> 385#include <sys/stat.h> 386 387/* Get definitions for the file permission bits. */ 388 389#ifndef S_IRUSR 390 391#define S_IRWXU 0700 392#define S_IRUSR 0400 393#define S_IWUSR 0200 394#define S_IXUSR 0100 395 396#define S_IRWXG 0070 397#define S_IRGRP 0040 398#define S_IWGRP 0020 399#define S_IXGRP 0010 400 401#define S_IRWXO 0007 402#define S_IROTH 0004 403#define S_IWOTH 0002 404#define S_IXOTH 0001 405 406#endif /* ! defined (S_IRUSR) */ 407 408#ifndef S_ISDIR 409#ifdef S_IFDIR 410#define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR) 411#else /* ! defined (S_IFDIR) */ 412#define S_ISDIR(i) (((i) & 0170000) == 040000) 413#endif /* ! defined (S_IFDIR) */ 414#endif /* ! defined (S_ISDIR) */ 415 416/* We create files with these modes (should this be configurable?). */ 417#define IPRIVATE_FILE_MODE (S_IRUSR | S_IWUSR) 418#define IPUBLIC_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) 419 420/* We create directories with this mode (should this be configurable?). */ 421#define IDIRECTORY_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) 422#define IPUBLIC_DIRECTORY_MODE (S_IRWXU | S_IRWXG | S_IRWXO) 423 424#if ! HAVE_OPENDIR 425 426/* Define some structures to use if we don't have opendir, etc. These 427 will only work if we have the old Unix filesystem, with a 2 byte 428 inode and a 14 byte filename. */ 429 430#include <sys/dir.h> 431 432struct dirent 433{ 434 char d_name[DIRSIZ + 1]; 435}; 436 437typedef struct 438{ 439 int o; 440 struct dirent s; 441} DIR; 442 443extern DIR *opendir P((const char *zdir)); 444extern struct dirent *readdir P((DIR *)); 445extern int closedir P((DIR *)); 446 447#endif /* ! HAVE_OPENDIR */ 448 449/* Information we need for a UNIX serial port. */ 450 451struct ssysdep_serial_port 452{ 453 /* File descriptor to read from. */ 454 int oread; 455 /* Whether the read descriptor is blocking. */ 456 boolean fread_blocking; 457 /* File descriptor to write to. */ 458 int owrite; 459 /* Whether the write descriptor is blocking. */ 460 boolean fwrite_blocking; 461 /* Whether setting the read descriptor to blocking affects the write 462 descriptor and vice-versa. */ 463 boolean fblock_both; 464 /* Hold the real read descriptor when using a dialer device. */ 465 int oholdread; 466 /* Hold the real write descriptor when using a dialer device. */ 467 int oholdwrite; 468 /* TRUE if this is a terminal and the remaining fields are valid. */ 469 boolean fterminal; 470 /* Baud rate. */ 471 long ibaud; 472 /* Original terminal settings. */ 473 sterminal sorig; 474 /* New terminal settings (raw mode, etc.). */ 475 sterminal snew; 476}; 477 478/* Information we need for a UNIX stdin port. */ 479 480struct ssysdep_stdin_port 481{ 482 struct ssysdep_serial_port s; 483 boolean fpty; 484}; 485 486/* For debugging it is helpful to know whether we are connected 487 through a pty; the fsserial_read routine uses this information to 488 know whether to sleep or not. */ 489#define SYSDEP_STDIN_CMDS(s) \ 490 { "pty", CMDTABTYPE_BOOLEAN, (pointer) &(s).fpty, NULL } 491 492#define SYSDEP_STDIN_INIT(q) ((q)->fpty = FALSE, (q)->s.oread = -1) 493 494/* Information we need for a UNIX modem port. */ 495 496struct ssysdep_modem_port 497{ 498 struct ssysdep_serial_port s; 499}; 500 501#define SYSDEP_MODEM_INIT(q) ((q)->s.oread = -1) 502 503/* Information we need for a UNIX direct port. */ 504 505struct ssysdep_direct_port 506{ 507 struct ssysdep_serial_port s; 508}; 509 510#define SYSDEP_DIRECT_INIT(q) ((q)->s.oread = -1) 511 512/* Set a signal handler. */ 513extern void usset_signal P((int isig, SIGtype (*pfn) P((int)), 514 boolean fforce, boolean *pfignored)); 515 516/* Default signal handler. This sets the appropriate element of the 517 afSignal array. If system calls are automatically restarted, it 518 may do a longjmp to an fsysdep_catch. */ 519extern SIGtype ussignal P((int isig)); 520 521/* Try to fork, repeating several times. */ 522extern pid_t isfork P((void)); 523 524/* Spawn a job. Returns the process ID of the spawned job or -1 on 525 error. The following macros may be passed in aidescs. */ 526 527/* Set descriptor to /dev/null. */ 528#define SPAWN_NULL (-1) 529/* Set element of aidescs to a pipe for caller to read from. */ 530#define SPAWN_READ_PIPE (-2) 531/* Set element of aidescs to a pipe for caller to write to. */ 532#define SPAWN_WRITE_PIPE (-3) 533 534extern pid_t isspawn P((const char **pazargs, int *aidescs, 535 boolean fkeepuid, boolean fkeepenv, 536 const char *zchdir, boolean fnosigs, 537 boolean fshell, const char *zpath, 538 const char *zuu_machine, 539 const char *zuu_user)); 540 541/* Do a form of popen using isspawn. */ 542extern FILE *espopen P((const char **pazargs, boolean frd, 543 pid_t *pipid)); 544 545/* Wait for a particular process to finish, returning the exit status. 546 The process ID should be pid_t, but we can't put that in a 547 prototype. */ 548extern int iswait P((unsigned long ipid, const char *zreport)); 549 550/* Lock a string. */ 551extern boolean fsdo_lock P((const char *, boolean fspooldir)); 552 553/* Unlock a string. */ 554extern boolean fsdo_unlock P((const char *, boolean fspooldir)); 555 556/* See whether a directory exists. */ 557extern boolean fsdirectory_exists P((const char *)); 558 559/* Expand a leading tilde to the public directory or a user's home 560 directory. Each system may have a different public directory, so 561 the system information must be passed in. */ 562extern const char *zstilde_expand P((const struct ssysteminfo *qsys, 563 const char *zfile)); 564 565/* Check access for a particular user name, or NULL to check access 566 for any user. */ 567extern boolean fsuser_access P((const struct stat *, int imode, 568 const char *zuser)); 569 570/* Copy a string to the common static buffer. */ 571extern const char *zscopy P((const char *z)); 572 573/* Prepend a directory to a file name, returning the common static 574 buffer. */ 575extern const char *zsappend P((const char *zdir, const char *zfile)); 576 577/* Get a temporary file name. */ 578extern const char *zstemp_file P((const struct ssysteminfo *qsys)); 579 580/* Get a jobid from a system and file name. */ 581extern const char *zsfile_to_jobid P((const struct ssysteminfo *qsys, 582 const char *zfile)); 583 584/* Get a file name from a jobid. This also returns the associated system 585 in *pzsystem. */ 586extern const char *zsjobid_to_file P((const char *zid, 587 const char **pzsystem)); 588 589#if SPOOLDIR_ULTRIX 590/* See whether there is a spool directory for a system. */ 591extern boolean fsultrix_has_spool P((const char *zsystem)); 592#endif /* SPOOLDIR_ULTRIX */ 593 594/* The working directory from which the program was run (this is set 595 by usysdep_initialize if called with fgetcwd TRUE). */ 596extern char *zScwd; 597 598/* 599 Local variables: 600 mode:c 601 End: 602 */ 603#endif /* ! defined (SYSH_UNX_H) */ 604