122698Sdist /* 234920Sbostic * Copyright (c) 1983 Eric P. Allman 333728Sbostic * Copyright (c) 1988 Regents of the University of California. 433728Sbostic * All rights reserved. 533728Sbostic * 642825Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822698Sdist 922698Sdist #ifndef lint 10*58701Seric static char sccsid[] = "@(#)conf.c 6.37 (Berkeley) 03/17/93"; 1133728Sbostic #endif /* not lint */ 1222698Sdist 1314881Seric # include <sys/ioctl.h> 1458082Seric # include <sys/param.h> 1558153Seric # include <signal.h> 1636928Sbostic # include <pwd.h> 173309Seric # include "sendmail.h" 1840980Sbostic # include "pathnames.h" 19404Seric 20294Seric /* 213309Seric ** CONF.C -- Sendmail Configuration Tables. 22294Seric ** 23294Seric ** Defines the configuration of this installation. 24294Seric ** 251388Seric ** Configuration Variables: 262897Seric ** HdrInfo -- a table describing well-known header fields. 272897Seric ** Each entry has the field name and some flags, 284147Seric ** which are described in sendmail.h. 294093Seric ** 304093Seric ** Notes: 314093Seric ** I have tried to put almost all the reasonable 324093Seric ** configuration information into the configuration 334093Seric ** file read at runtime. My intent is that anything 344093Seric ** here is a function of the version of UNIX you 354093Seric ** are running, or is really static -- for example 364093Seric ** the headers are a superset of widely used 374093Seric ** protocols. If you find yourself playing with 384093Seric ** this file too much, you may be making a mistake! 39294Seric */ 40294Seric 41294Seric 42294Seric 43294Seric 444437Seric /* 452897Seric ** Header info table 463057Seric ** Final (null) entry contains the flags used for any other field. 474147Seric ** 484147Seric ** Not all of these are actually handled specially by sendmail 494147Seric ** at this time. They are included as placeholders, to let 504147Seric ** you know that "someday" I intend to have sendmail do 514147Seric ** something with them. 522897Seric */ 532897Seric 542897Seric struct hdrinfo HdrInfo[] = 552897Seric { 568060Seric /* originator fields, most to least significant */ 5711417Seric "resent-sender", H_FROM|H_RESENT, 5811417Seric "resent-from", H_FROM|H_RESENT, 5925686Seric "resent-reply-to", H_FROM|H_RESENT, 609055Seric "sender", H_FROM, 619055Seric "from", H_FROM, 6225686Seric "reply-to", H_FROM, 639055Seric "full-name", H_ACHECK, 6457359Seric "return-receipt-to", H_FROM /* |H_RECEIPTTO */, 6557359Seric "errors-to", H_FROM|H_ERRORSTO, 668060Seric /* destination fields */ 679055Seric "to", H_RCPT, 6811417Seric "resent-to", H_RCPT|H_RESENT, 699055Seric "cc", H_RCPT, 7011417Seric "resent-cc", H_RCPT|H_RESENT, 719055Seric "bcc", H_RCPT|H_ACHECK, 7211417Seric "resent-bcc", H_RCPT|H_ACHECK|H_RESENT, 7356215Seric "apparently-to", H_RCPT, 748060Seric /* message identification and control */ 7511417Seric "message-id", 0, 7611417Seric "resent-message-id", H_RESENT, 779055Seric "message", H_EOH, 789055Seric "text", H_EOH, 7911417Seric /* date fields */ 8011417Seric "date", 0, 8111417Seric "resent-date", H_RESENT, 828060Seric /* trace fields */ 839055Seric "received", H_TRACE|H_FORCE, 849055Seric "via", H_TRACE|H_FORCE, 859055Seric "mail-from", H_TRACE|H_FORCE, 868060Seric 879055Seric NULL, 0, 882897Seric }; 894166Seric 904166Seric 914166Seric 924282Seric /* 934282Seric ** Location of system files/databases/etc. 944282Seric */ 954282Seric 9640980Sbostic char *ConfFile = _PATH_SENDMAILCF; /* runtime configuration */ 9740980Sbostic char *FreezeFile = _PATH_SENDMAILFC; /* frozen version of above */ 9858082Seric char *PidFile = _PATH_SENDMAILPID; /* stores daemon proc id */ 999039Seric 1009064Seric 1019064Seric 1029039Seric /* 10358082Seric ** Privacy values 10458082Seric */ 10558082Seric 10658082Seric struct prival PrivacyValues[] = 10758082Seric { 10858082Seric "public", PRIV_PUBLIC, 10958082Seric "needmailhelo", PRIV_NEEDMAILHELO, 11058114Seric "needexpnhelo", PRIV_NEEDEXPNHELO, 11158082Seric "needvrfyhelo", PRIV_NEEDVRFYHELO, 11258082Seric "noexpn", PRIV_NOEXPN, 11358082Seric "novrfy", PRIV_NOVRFY, 11458249Seric "restrictmailq", PRIV_RESTRMAILQ, 11558082Seric "goaway", PRIV_GOAWAY, 11658082Seric NULL, PRIV_PUBLIC, 11758082Seric }; 11858082Seric 11958082Seric 12058082Seric 12158082Seric /* 12224943Seric ** Miscellaneous stuff. 1239039Seric */ 1249039Seric 12524943Seric int DtableSize = 50; /* max open files; reset in 4.2bsd */ 12624943Seric /* 12724943Seric ** SETDEFAULTS -- set default values 12824943Seric ** 12924943Seric ** Because of the way freezing is done, these must be initialized 13024943Seric ** using direct code. 13124943Seric ** 13224943Seric ** Parameters: 13324943Seric ** none. 13424943Seric ** 13524943Seric ** Returns: 13624943Seric ** none. 13724943Seric ** 13824943Seric ** Side Effects: 13924943Seric ** Initializes a bunch of global variables to their 14024943Seric ** default values. 14124943Seric */ 14224943Seric 14324943Seric setdefaults() 14424943Seric { 14557438Seric SpaceSub = ' '; /* option B */ 14657438Seric QueueLA = 8; /* option x */ 14757438Seric RefuseLA = 12; /* option X */ 14857438Seric WkRecipFact = 30000L; /* option y */ 14957438Seric WkClassFact = 1800L; /* option z */ 15057438Seric WkTimeFact = 90000L; /* option Z */ 15157438Seric QueueFactor = WkRecipFact * 20; /* option q */ 15257142Seric FileMode = (getuid() != geteuid()) ? 0644 : 0600; 15357438Seric /* option F */ 15457438Seric DefUid = 1; /* option u */ 15557438Seric DefGid = 1; /* option g */ 15657438Seric CheckpointInterval = 10; /* option C */ 15757438Seric MaxHopCount = 25; /* option h */ 15857438Seric SendMode = SM_FORK; /* option d */ 15957438Seric ErrorMode = EM_PRINT; /* option e */ 16057438Seric EightBit = FALSE; /* option 8 */ 16157438Seric MaxMciCache = 1; /* option k */ 16257438Seric MciCacheTimeout = 300; /* option K */ 16357438Seric LogLevel = 9; /* option L */ 16458112Seric settimeouts(NULL); /* option r */ 16558112Seric TimeOut = 5 * 24 * 60 * 60; /* option T */ 16640973Sbostic setdefuser(); 16753654Seric setupmaps(); 16857402Seric setupmailers(); 16924943Seric } 170294Seric 17140973Sbostic 1724326Seric /* 17340973Sbostic ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 17440973Sbostic */ 17540973Sbostic 17640973Sbostic setdefuser() 17740973Sbostic { 17840973Sbostic struct passwd *defpwent; 17957386Seric static char defuserbuf[40]; 18040973Sbostic 18157386Seric DefUser = defuserbuf; 18240973Sbostic if ((defpwent = getpwuid(DefUid)) != NULL) 18357386Seric strcpy(defuserbuf, defpwent->pw_name); 18440973Sbostic else 18557386Seric strcpy(defuserbuf, "nobody"); 18640973Sbostic } 18753654Seric /* 18853654Seric ** SETUPMAPS -- set up map classes 18953654Seric ** 19053654Seric ** Since these are compiled in, they cannot be in the config file. 19153654Seric ** 19253654Seric */ 19340973Sbostic 19453654Seric setupmaps() 19553654Seric { 19653654Seric register STAB *s; 19756836Seric extern bool host_map_init(); 19853654Seric extern char *maphostname(); 19940973Sbostic 20053654Seric /* set up host name lookup map */ 20153654Seric s = stab("host", ST_MAPCLASS, ST_ENTER); 20256836Seric s->s_mapclass.map_init = host_map_init; 20353654Seric s->s_mapclass.map_lookup = maphostname; 20453654Seric 20553654Seric /* 20653654Seric ** Set up other map classes. 20753654Seric */ 20853654Seric 20953654Seric # ifdef DBM_MAP 21053654Seric /* dbm file access */ 21153654Seric { 21256836Seric extern bool dbm_map_init(); 21353654Seric extern char *dbm_map_lookup(); 21453654Seric 21553654Seric s = stab("dbm", ST_MAPCLASS, ST_ENTER); 21653654Seric s->s_mapclass.map_init = dbm_map_init; 21753654Seric s->s_mapclass.map_lookup = dbm_map_lookup; 21853654Seric } 21953654Seric # endif 22053654Seric 22153654Seric # ifdef BTREE_MAP 22253654Seric /* new database file access -- btree files */ 22353654Seric { 22456823Seric extern bool bt_map_init(); 22556823Seric extern char *db_map_lookup(); 22653654Seric 22753654Seric s = stab("btree", ST_MAPCLASS, ST_ENTER); 22853654Seric s->s_mapclass.map_init = bt_map_init; 22956823Seric s->s_mapclass.map_lookup = db_map_lookup; 23053654Seric } 23153654Seric # endif 23253654Seric 23353654Seric # ifdef HASH_MAP 23453654Seric /* new database file access -- hash files */ 23553654Seric { 23656823Seric extern bool hash_map_init(); 23756823Seric extern char *db_map_lookup(); 23853654Seric 23953654Seric s = stab("hash", ST_MAPCLASS, ST_ENTER); 24053654Seric s->s_mapclass.map_init = hash_map_init; 24156823Seric s->s_mapclass.map_lookup = db_map_lookup; 24253654Seric } 24353654Seric # endif 24453654Seric 24557208Seric # ifdef NIS_MAP 24657208Seric /* NIS map access */ 24757208Seric { 24857208Seric extern bool nis_map_init(); 24957208Seric extern char *nis_map_lookup(); 25057208Seric 25157208Seric s = stab("nis", ST_MAPCLASS, ST_ENTER); 25257208Seric s->s_mapclass.map_init = nis_map_init; 25357208Seric s->s_mapclass.map_lookup = nis_map_lookup; 25457208Seric } 25557208Seric # endif 25657208Seric 25753654Seric # ifdef USERDB_MAP 25853654Seric /* user database */ 25953654Seric { 26056836Seric extern bool udb_map_init(); 26153654Seric extern char *udb_map_lookup(); 26253654Seric 26353654Seric s = stab("udb", ST_MAPCLASS, ST_ENTER); 26453654Seric s->s_mapclass.map_init = udb_map_init; 26553654Seric s->s_mapclass.map_lookup = udb_map_lookup; 26653654Seric } 26753654Seric # endif 26853654Seric } 26953654Seric /* 27056836Seric ** HOST_MAP_INIT -- initialize host class structures 27156836Seric */ 27256836Seric 27356836Seric bool 27456836Seric host_map_init(map, mapname, args) 27556836Seric MAP *map; 27656836Seric char *mapname; 27756836Seric char *args; 27856836Seric { 27956836Seric register char *p = args; 28056836Seric 28156836Seric for (;;) 28256836Seric { 28358050Seric while (isascii(*p) && isspace(*p)) 28456836Seric p++; 28556836Seric if (*p != '-') 28656836Seric break; 28756836Seric switch (*++p) 28856836Seric { 28956836Seric case 'a': 29056836Seric map->map_app = ++p; 29156836Seric break; 29256836Seric } 29358050Seric while (*p != '\0' && !(isascii(*p) && isspace(*p))) 29456836Seric p++; 29556836Seric if (*p != '\0') 29656836Seric *p++ = '\0'; 29756836Seric } 29856836Seric if (map->map_app != NULL) 29956836Seric map->map_app = newstr(map->map_app); 30056836Seric return TRUE; 30156836Seric } 30257402Seric /* 30357402Seric ** SETUPMAILERS -- initialize default mailers 30457402Seric */ 30556836Seric 30657402Seric setupmailers() 30757402Seric { 30857402Seric char buf[100]; 30957402Seric 31057403Seric strcpy(buf, "prog, P=/bin/sh, F=lsD, A=sh -c $u"); 31157403Seric makemailer(buf); 31257403Seric 31357402Seric strcpy(buf, "*file*, P=/dev/null, F=lsDEu, A=FILE"); 31457402Seric makemailer(buf); 31557402Seric 31657402Seric strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 31757402Seric makemailer(buf); 31857402Seric } 31956836Seric /* 3204326Seric ** GETRUID -- get real user id (V7) 3214326Seric */ 3224326Seric 3234326Seric getruid() 3244326Seric { 3259274Seric if (OpMode == MD_DAEMON) 3264536Seric return (RealUid); 3274536Seric else 3284536Seric return (getuid()); 3294326Seric } 3304326Seric 3314326Seric 3324326Seric /* 3334326Seric ** GETRGID -- get real group id (V7). 3344326Seric */ 3354326Seric 3364326Seric getrgid() 3374326Seric { 3389274Seric if (OpMode == MD_DAEMON) 3394536Seric return (RealGid); 3404536Seric else 3414536Seric return (getgid()); 3424326Seric } 34353654Seric /* 3449369Seric ** USERNAME -- return the user id of the logged in user. 3459369Seric ** 3469369Seric ** Parameters: 3479369Seric ** none. 3489369Seric ** 3499369Seric ** Returns: 3509369Seric ** The login name of the logged in user. 3519369Seric ** 3529369Seric ** Side Effects: 3539369Seric ** none. 3549369Seric ** 3559369Seric ** Notes: 3569369Seric ** The return value is statically allocated. 3579369Seric */ 3589369Seric 3599369Seric char * 3609369Seric username() 3619369Seric { 36217469Seric static char *myname = NULL; 3639369Seric extern char *getlogin(); 36419904Smiriam register struct passwd *pw; 3659369Seric 36617469Seric /* cache the result */ 36717469Seric if (myname == NULL) 36817469Seric { 36917469Seric myname = getlogin(); 37017469Seric if (myname == NULL || myname[0] == '\0') 37117469Seric { 37217469Seric 37317469Seric pw = getpwuid(getruid()); 37417469Seric if (pw != NULL) 37540993Sbostic myname = newstr(pw->pw_name); 37617469Seric } 37719904Smiriam else 37819904Smiriam { 37919873Smiriam 38040993Sbostic myname = newstr(myname); 38140993Sbostic if ((pw = getpwnam(myname)) == NULL || 38240993Sbostic getuid() != pw->pw_uid) 38319904Smiriam { 38419873Smiriam pw = getpwuid(getuid()); 38524945Seric if (pw != NULL) 38640993Sbostic myname = newstr(pw->pw_name); 38719873Smiriam } 38819873Smiriam } 38917469Seric if (myname == NULL || myname[0] == '\0') 39017469Seric { 39158151Seric syserr("554 Who are you?"); 39217469Seric myname = "postmaster"; 39317469Seric } 39417469Seric } 39517469Seric 39617469Seric return (myname); 3979369Seric } 3989369Seric /* 3994190Seric ** TTYPATH -- Get the path of the user's tty 400294Seric ** 401294Seric ** Returns the pathname of the user's tty. Returns NULL if 402294Seric ** the user is not logged in or if s/he has write permission 403294Seric ** denied. 404294Seric ** 405294Seric ** Parameters: 406294Seric ** none 407294Seric ** 408294Seric ** Returns: 409294Seric ** pathname of the user's tty. 410294Seric ** NULL if not logged in or write permission denied. 411294Seric ** 412294Seric ** Side Effects: 413294Seric ** none. 414294Seric ** 415294Seric ** WARNING: 416294Seric ** Return value is in a local buffer. 417294Seric ** 418294Seric ** Called By: 419294Seric ** savemail 420294Seric */ 421294Seric 422294Seric # include <sys/stat.h> 423294Seric 424294Seric char * 425294Seric ttypath() 426294Seric { 427294Seric struct stat stbuf; 428294Seric register char *pathn; 429294Seric extern char *ttyname(); 4304081Seric extern char *getlogin(); 431294Seric 432294Seric /* compute the pathname of the controlling tty */ 4339369Seric if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 4349369Seric (pathn = ttyname(0)) == NULL) 435294Seric { 436294Seric errno = 0; 437294Seric return (NULL); 438294Seric } 439294Seric 440294Seric /* see if we have write permission */ 4412967Seric if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 442294Seric { 443294Seric errno = 0; 444294Seric return (NULL); 445294Seric } 446294Seric 447294Seric /* see if the user is logged in */ 448294Seric if (getlogin() == NULL) 449294Seric return (NULL); 450294Seric 451294Seric /* looks good */ 452294Seric return (pathn); 453294Seric } 4542967Seric /* 4552967Seric ** CHECKCOMPAT -- check for From and To person compatible. 4562967Seric ** 4572967Seric ** This routine can be supplied on a per-installation basis 4582967Seric ** to determine whether a person is allowed to send a message. 4592967Seric ** This allows restriction of certain types of internet 4602967Seric ** forwarding or registration of users. 4612967Seric ** 4622967Seric ** If the hosts are found to be incompatible, an error 46357454Seric ** message should be given using "usrerr" and 0 should 4642967Seric ** be returned. 4652967Seric ** 4664288Seric ** 'NoReturn' can be set to suppress the return-to-sender 4674288Seric ** function; this should be done on huge messages. 4684288Seric ** 4692967Seric ** Parameters: 4702967Seric ** to -- the person being sent to. 4712967Seric ** 4722967Seric ** Returns: 47357459Seric ** an exit status 4742967Seric ** 4752967Seric ** Side Effects: 4762967Seric ** none (unless you include the usrerr stuff) 4772967Seric */ 4782967Seric 47955012Seric checkcompat(to, e) 4802967Seric register ADDRESS *to; 48155012Seric register ENVELOPE *e; 4822967Seric { 48312133Seric # ifdef lint 48412133Seric if (to == NULL) 48512133Seric to++; 48612133Seric # endif lint 48710698Seric # ifdef EXAMPLE_CODE 48810698Seric /* this code is intended as an example only */ 4894437Seric register STAB *s; 4904437Seric 4914437Seric s = stab("arpa", ST_MAILER, ST_FIND); 49255012Seric if (s != NULL && e->e_from.q_mailer != LocalMailer && 4939369Seric to->q_mailer == s->s_mailer) 4944437Seric { 49558151Seric usrerr("553 No ARPA mail through this machine: see your system administration"); 49610698Seric /* NoReturn = TRUE; to supress return copy */ 49757459Seric return (EX_UNAVAILABLE); 4984437Seric } 49956795Seric # endif /* EXAMPLE_CODE */ 50057459Seric return (EX_OK); 5012967Seric } 5029369Seric /* 5039369Seric ** HOLDSIGS -- arrange to hold all signals 5049369Seric ** 5059369Seric ** Parameters: 5069369Seric ** none. 5079369Seric ** 5089369Seric ** Returns: 5099369Seric ** none. 5109369Seric ** 5119369Seric ** Side Effects: 5129369Seric ** Arranges that signals are held. 5139369Seric */ 5149369Seric 5159369Seric holdsigs() 5169369Seric { 5179369Seric } 5189369Seric /* 5199369Seric ** RLSESIGS -- arrange to release all signals 5209369Seric ** 5219369Seric ** This undoes the effect of holdsigs. 5229369Seric ** 5239369Seric ** Parameters: 5249369Seric ** none. 5259369Seric ** 5269369Seric ** Returns: 5279369Seric ** none. 5289369Seric ** 5299369Seric ** Side Effects: 5309369Seric ** Arranges that signals are released. 5319369Seric */ 5329369Seric 5339369Seric rlsesigs() 5349369Seric { 5359369Seric } 53614872Seric /* 53714872Seric ** GETLA -- get the current load average 53814872Seric ** 53914881Seric ** This code stolen from la.c. 54014881Seric ** 54114872Seric ** Parameters: 54214872Seric ** none. 54314872Seric ** 54414872Seric ** Returns: 54514872Seric ** The current load average as an integer. 54614872Seric ** 54714872Seric ** Side Effects: 54814872Seric ** none. 54914872Seric */ 55014872Seric 55151920Seric /* try to guess what style of load average we have */ 55251920Seric #define LA_ZERO 1 /* always return load average as zero */ 55351920Seric #define LA_INT 2 /* read kmem for avenrun; interpret as int */ 55451920Seric #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 55551920Seric #define LA_SUBR 4 /* call getloadavg */ 55614872Seric 55751920Seric #ifndef LA_TYPE 55851920Seric # if defined(sun) 55951920Seric # define LA_TYPE LA_INT 56051920Seric # endif 56157977Seric # if defined(mips) || defined(__alpha) 56257977Seric /* Ultrix or OSF/1 or RISC/os */ 56351920Seric # define LA_TYPE LA_INT 56451920Seric # define LA_AVENRUN "avenrun" 56551920Seric # endif 56651920Seric # if defined(hpux) 56751920Seric # define LA_TYPE LA_FLOAT 56851920Seric # endif 56951920Seric 57051920Seric # ifndef LA_TYPE 57157736Seric # if defined(SYSTEM5) 57257736Seric # define LA_TYPE LA_INT 57357736Seric # define LA_AVENRUN "avenrun" 57457736Seric # else 57557736Seric # if defined(BSD) 57657736Seric # define LA_TYPE LA_SUBR 57757736Seric # else 57857736Seric # define LA_TYPE LA_ZERO 57957736Seric # endif 58057736Seric # endif 58151920Seric # endif 58251920Seric #endif 58351920Seric 58451920Seric #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) 58551920Seric 58614872Seric #include <nlist.h> 58714872Seric 58851920Seric #ifndef LA_AVENRUN 58951920Seric #define LA_AVENRUN "_avenrun" 59051920Seric #endif 59151920Seric 59251920Seric /* _PATH_UNIX should be defined in <paths.h> */ 59351920Seric #ifndef _PATH_UNIX 59451920Seric # if defined(hpux) 59551920Seric # define _PATH_UNIX "/hp-ux" 59651920Seric # endif 59751920Seric # if defined(mips) && !defined(ultrix) 59851920Seric /* powerful RISC/os */ 59951920Seric # define _PATH_UNIX "/unix" 60051920Seric # endif 60157736Seric # if defined(SYSTEM5) 60257977Seric # ifndef _PATH_UNIX 60357977Seric # define _PATH_UNIX "/unix" 60457977Seric # endif 60557736Seric # endif 60651920Seric # ifndef _PATH_UNIX 60751920Seric # define _PATH_UNIX "/vmunix" 60851920Seric # endif 60951920Seric #endif 61051920Seric 61114872Seric struct nlist Nl[] = 61214872Seric { 61351920Seric { LA_AVENRUN }, 61414872Seric #define X_AVENRUN 0 61514872Seric { 0 }, 61614872Seric }; 61714872Seric 61857736Seric #if defined(unixpc) 61957736Seric # define FSHIFT 5 62057736Seric #endif 62157736Seric 62257977Seric #if defined(__alpha) 62357977Seric # define FSHIFT 10 62457977Seric #endif 62557977Seric 62651920Seric #if (LA_TYPE == LA_INT) && !defined(FSHIFT) 62751920Seric # define FSHIFT 8 62857736Seric #endif 62957736Seric #if (LA_TYPE == LA_INT) && !defined(FSCALE) 63051920Seric # define FSCALE (1 << FSHIFT) 63151920Seric #endif 63240930Srick 63314872Seric getla() 63414872Seric { 63514872Seric static int kmem = -1; 63651920Seric #if LA_TYPE == LA_INT 63724943Seric long avenrun[3]; 63851920Seric #else 63951920Seric double avenrun[3]; 64051920Seric #endif 64125615Seric extern off_t lseek(); 64257736Seric extern char *errstring(); 64357736Seric extern int errno; 64414872Seric 64514872Seric if (kmem < 0) 64614872Seric { 64724945Seric kmem = open("/dev/kmem", 0, 0); 64814872Seric if (kmem < 0) 64957736Seric { 65057736Seric if (tTd(3, 1)) 65157736Seric printf("getla: open(/dev/kmem): %s\n", 65257736Seric errstring(errno)); 65314872Seric return (-1); 65457736Seric } 65551920Seric (void) fcntl(kmem, F_SETFD, 1); 65657736Seric if (nlist(_PATH_UNIX, Nl) < 0) 65757736Seric { 65857736Seric if (tTd(3, 1)) 65957736Seric printf("getla: nlist(%s): %s\n", _PATH_UNIX, 66057736Seric errstring(errno)); 66114872Seric return (-1); 66257736Seric } 66314872Seric } 66457736Seric if (tTd(3, 20)) 66557736Seric printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 66624945Seric if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 || 66723118Seric read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 66819967Seric { 66919967Seric /* thank you Ian */ 67057736Seric if (tTd(3, 1)) 67157736Seric printf("getla: lseek or read: %s\n", errstring(errno)); 67219967Seric return (-1); 67319967Seric } 67451920Seric #if LA_TYPE == LA_INT 67557736Seric if (tTd(3, 5)) 67657736Seric { 67757736Seric printf("getla: avenrun = %d", avenrun[0]); 67857736Seric if (tTd(3, 15)) 67957736Seric printf(", %d, %d", avenrun[1], avenrun[2]); 68057736Seric printf("\n"); 68157736Seric } 68257736Seric if (tTd(3, 1)) 68357736Seric printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68424943Seric return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 68551920Seric #else 68657736Seric if (tTd(3, 5)) 68757736Seric { 68857736Seric printf("getla: avenrun = %g", avenrun[0]); 68957736Seric if (tTd(3, 15)) 69057736Seric printf(", %g, %g", avenrun[1], avenrun[2]); 69157736Seric printf("\n"); 69257736Seric } 69357736Seric if (tTd(3, 1)) 69457736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 69551920Seric return ((int) (avenrun[0] + 0.5)); 69651920Seric #endif 69714872Seric } 69814872Seric 69951773Seric #else 70051920Seric #if LA_TYPE == LA_SUBR 70151773Seric 70251773Seric getla() 70351773Seric { 70451920Seric double avenrun[3]; 70551920Seric 70651920Seric if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 70757736Seric { 70857736Seric if (tTd(3, 1)) 70957736Seric perror("getla: getloadavg failed:"); 71051920Seric return (-1); 71157736Seric } 71257736Seric if (tTd(3, 1)) 71357736Seric printf("getla: %d\n", (int) (avenrun[0] +0.5)); 71451920Seric return ((int) (avenrun[0] + 0.5)); 71551773Seric } 71651773Seric 71751773Seric #else 71851773Seric 71951773Seric getla() 72051773Seric { 72157736Seric if (tTd(3, 1)) 72257736Seric printf("getla: ZERO\n"); 72351920Seric return (0); 72451773Seric } 72551773Seric 72651773Seric #endif 72751773Seric #endif 72824943Seric /* 72924943Seric ** SHOULDQUEUE -- should this message be queued or sent? 73024943Seric ** 73124943Seric ** Compares the message cost to the load average to decide. 73224943Seric ** 73324943Seric ** Parameters: 73424943Seric ** pri -- the priority of the message in question. 73557438Seric ** ctime -- the message creation time. 73624943Seric ** 73724943Seric ** Returns: 73824943Seric ** TRUE -- if this message should be queued up for the 73924943Seric ** time being. 74024943Seric ** FALSE -- if the load is low enough to send this message. 74124943Seric ** 74224943Seric ** Side Effects: 74324943Seric ** none. 74424943Seric */ 74524943Seric 74624943Seric bool 74757438Seric shouldqueue(pri, ctime) 74824943Seric long pri; 74957438Seric time_t ctime; 75024943Seric { 75151920Seric if (CurrentLA < QueueLA) 75224943Seric return (FALSE); 75358132Seric if (CurrentLA >= RefuseLA) 75458132Seric return (TRUE); 75551920Seric return (pri > (QueueFactor / (CurrentLA - QueueLA + 1))); 75624943Seric } 75724943Seric /* 75853037Seric ** REFUSECONNECTIONS -- decide if connections should be refused 75953037Seric ** 76053037Seric ** Parameters: 76153037Seric ** none. 76253037Seric ** 76353037Seric ** Returns: 76453037Seric ** TRUE if incoming SMTP connections should be refused 76553037Seric ** (for now). 76653037Seric ** FALSE if we should accept new work. 76753037Seric ** 76853037Seric ** Side Effects: 76953037Seric ** none. 77053037Seric */ 77153037Seric 77253037Seric bool 77353037Seric refuseconnections() 77453037Seric { 77553037Seric /* this is probably too simplistic */ 77658132Seric return (CurrentLA >= RefuseLA); 77753037Seric } 77853037Seric /* 77924943Seric ** SETPROCTITLE -- set process title for ps 78024943Seric ** 78124943Seric ** Parameters: 78258674Seric ** fmt -- a printf style format string. 78358674Seric ** a, b, c -- possible parameters to fmt. 78424943Seric ** 78524943Seric ** Returns: 78624943Seric ** none. 78724943Seric ** 78824943Seric ** Side Effects: 78924943Seric ** Clobbers argv of our main procedure so ps(1) will 79024943Seric ** display the title. 79124943Seric */ 79224943Seric 79358689Seric #ifdef SETPROCTITLE 79458689Seric # ifdef __hpux 79558689Seric # include <sys/pstat.h> 79658689Seric # endif 79758689Seric #endif 79858689Seric 79924943Seric /*VARARGS1*/ 80057642Seric #ifdef __STDC__ 80157642Seric setproctitle(char *fmt, ...) 80257642Seric #else 80357642Seric setproctitle(fmt, va_alist) 80424943Seric char *fmt; 80557642Seric va_dcl 80657642Seric #endif 80724943Seric { 80824943Seric # ifdef SETPROCTITLE 80924943Seric register char *p; 81025049Seric register int i; 81158674Seric char buf[MAXLINE]; 81256852Seric VA_LOCAL_DECL 81358689Seric # ifdef __hpux 81458689Seric union pstun pst; 81558689Seric # endif 81624943Seric extern char **Argv; 81724943Seric extern char *LastArgv; 81824943Seric 81958674Seric p = buf; 82024943Seric 82158674Seric /* print sendmail: heading for grep */ 82258674Seric (void) strcpy(p, "sendmail: "); 82358674Seric p += strlen(p); 82424943Seric 82558674Seric /* print the argument string */ 82658674Seric VA_START(fmt); 82758674Seric (void) vsprintf(p, fmt, ap); 82856852Seric VA_END; 82954996Seric 83058674Seric i = strlen(buf); 83158689Seric 83258689Seric # ifdef __hpux 83358689Seric pst.pst_command = buf; 83458689Seric pstat(PSTAT_SETCMD, pst, i, 0, 0); 83558689Seric # else 83658689Seric 83754996Seric if (i > LastArgv - Argv[0] - 2) 83825049Seric { 83954996Seric i = LastArgv - Argv[0] - 2; 84058674Seric buf[i] = '\0'; 84125049Seric } 84258674Seric (void) strcpy(Argv[0], buf); 84354997Seric p = &Argv[0][i]; 84424943Seric while (p < LastArgv) 84524943Seric *p++ = ' '; 84658689Seric # endif 84756795Seric # endif /* SETPROCTITLE */ 84824943Seric } 84925698Seric /* 85025698Seric ** REAPCHILD -- pick up the body of my child, lest it become a zombie 85125698Seric ** 85225698Seric ** Parameters: 85325698Seric ** none. 85425698Seric ** 85525698Seric ** Returns: 85625698Seric ** none. 85725698Seric ** 85825698Seric ** Side Effects: 85925698Seric ** Picks up extant zombies. 86025698Seric */ 86125698Seric 86225698Seric # include <sys/wait.h> 86325698Seric 86446928Sbostic void 86525698Seric reapchild() 86625698Seric { 86725698Seric # ifdef WNOHANG 86825698Seric union wait status; 86925698Seric 87046928Sbostic while (wait3((int *)&status, WNOHANG, (struct rusage *) NULL) > 0) 87125698Seric continue; 87256795Seric # else /* WNOHANG */ 87325698Seric auto int status; 87425698Seric 87546928Sbostic while (wait((int *)&status) > 0) 87625698Seric continue; 87756795Seric # endif /* WNOHANG */ 87858061Seric # ifdef SYSTEM5 87958061Seric (void) signal(SIGCHLD, reapchild); 88058061Seric # endif 88125698Seric } 88255418Seric /* 88355418Seric ** UNSETENV -- remove a variable from the environment 88455418Seric ** 88555418Seric ** Not needed on newer systems. 88655418Seric ** 88755418Seric ** Parameters: 88855418Seric ** name -- the string name of the environment variable to be 88955418Seric ** deleted from the current environment. 89055418Seric ** 89155418Seric ** Returns: 89255418Seric ** none. 89355418Seric ** 89455418Seric ** Globals: 89555418Seric ** environ -- a pointer to the current environment. 89655418Seric ** 89755418Seric ** Side Effects: 89855418Seric ** Modifies environ. 89955418Seric */ 90055418Seric 90155418Seric #ifdef UNSETENV 90255418Seric 90355418Seric void 90455418Seric unsetenv(name) 90555418Seric char *name; 90655418Seric { 90755418Seric extern char **environ; 90855418Seric register char **pp; 90955418Seric int len = strlen(name); 91055418Seric 91155418Seric for (pp = environ; *pp != NULL; pp++) 91255418Seric { 91355418Seric if (strncmp(name, *pp, len) == 0 && 91455418Seric ((*pp)[len] == '=' || (*pp)[len] == '\0')) 91555418Seric break; 91655418Seric } 91755418Seric 91855418Seric for (; *pp != NULL; pp++) 91955418Seric *pp = pp[1]; 92055418Seric } 92155418Seric 92255418Seric #endif /* UNSETENV */ 92356215Seric /* 92456215Seric ** GETDTABLESIZE -- return number of file descriptors 92556215Seric ** 92656215Seric ** Only on non-BSD systems 92756215Seric ** 92856215Seric ** Parameters: 92956215Seric ** none 93056215Seric ** 93156215Seric ** Returns: 93256215Seric ** size of file descriptor table 93356215Seric ** 93456215Seric ** Side Effects: 93556215Seric ** none 93656215Seric */ 93756215Seric 93856215Seric #ifdef SYSTEM5 93956215Seric 94056215Seric int 94156215Seric getdtablesize() 94256215Seric { 94358689Seric # ifdef _SC_OPEN_MAX 94458689Seric return sysconf(_SC_OPEN_MAX); 94558689Seric # else 94656215Seric return NOFILE; 94758689Seric # endif 94856215Seric } 94956215Seric 95056215Seric #endif 95157631Seric /* 95257631Seric ** UNAME -- get the UUCP name of this system. 95357631Seric */ 95457631Seric 95557943Seric #ifndef HASUNAME 95657631Seric 95757631Seric int 95857631Seric uname(name) 95957631Seric struct utsname *name; 96057631Seric { 96157631Seric FILE *file; 96257631Seric char *n; 96357631Seric 96457631Seric name->nodename[0] = '\0'; 96557631Seric 96657661Seric /* try /etc/whoami -- one line with the node name */ 96757631Seric if ((file = fopen("/etc/whoami", "r")) != NULL) 96857631Seric { 96957661Seric (void) fgets(name->nodename, NODE_LENGTH + 1, file); 97057631Seric (void) fclose(file); 97157661Seric n = strchr(name->nodename, '\n'); 97257631Seric if (n != NULL) 97357631Seric *n = '\0'; 97457631Seric if (name->nodename[0] != '\0') 97557631Seric return (0); 97657631Seric } 97757631Seric 97857661Seric /* try /usr/include/whoami.h -- has a #define somewhere */ 97957631Seric if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 98057631Seric { 98157631Seric char buf[MAXLINE]; 98257631Seric 98357631Seric while (fgets(buf, MAXLINE, file) != NULL) 98457631Seric if (sscanf(buf, "#define sysname \"%*[^\"]\"", 98557631Seric NODE_LENGTH, name->nodename) > 0) 98657631Seric break; 98757631Seric (void) fclose(file); 98857631Seric if (name->nodename[0] != '\0') 98957631Seric return (0); 99057631Seric } 99157631Seric 99257631Seric #ifdef TRUST_POPEN 99357631Seric /* 99457631Seric ** Popen is known to have security holes. 99557631Seric */ 99657631Seric 99757661Seric /* try uuname -l to return local name */ 99857631Seric if ((file = popen("uuname -l", "r")) != NULL) 99957631Seric { 100057661Seric (void) fgets(name, NODE_LENGTH + 1, file); 100157631Seric (void) pclose(file); 100257661Seric n = strchr(name, '\n'); 100357631Seric if (n != NULL) 100457631Seric *n = '\0'; 100557661Seric if (name->nodename[0] != '\0') 100657631Seric return (0); 100757631Seric } 100857631Seric #endif 100957631Seric 101057631Seric return (-1); 101157631Seric } 101257943Seric #endif /* HASUNAME */ 101358068Seric /* 101458068Seric ** INITGROUPS -- initialize groups 101558068Seric ** 101658068Seric ** Stub implementation for System V style systems 101758068Seric */ 101858068Seric 101958068Seric #ifndef HASINITGROUPS 102058068Seric # if !defined(SYSTEM5) || defined(hpux) 102158068Seric # define HASINITGROUPS 102258068Seric # endif 102358068Seric #endif 102458068Seric 102558068Seric #ifndef HASINITGROUPS 102658068Seric 102758068Seric initgroups(name, basegid) 102858068Seric char *name; 102958068Seric int basegid; 103058068Seric { 103158068Seric return 0; 103258068Seric } 103358068Seric 103458068Seric #endif 103558082Seric /* 103658082Seric ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 103758082Seric ** 103858082Seric ** Only implemented if you have statfs. 103958082Seric ** 104058082Seric ** Parameters: 104158333Seric ** msize -- the size to check against. If zero, we don't yet 104258333Seric ** know how big the message will be, so just check for 104358333Seric ** a "reasonable" amount. 104458082Seric ** 104558082Seric ** Returns: 104658082Seric ** TRUE if there is enough space. 104758082Seric ** FALSE otherwise. 104858082Seric */ 104958082Seric 105058082Seric #ifndef HASSTATFS 105158082Seric # if defined(BSD4_4) || defined(__osf__) 105258082Seric # define HASSTATFS 105358082Seric # endif 105458082Seric #endif 105558082Seric 105658082Seric #ifdef HASSTATFS 105758157Seric # undef HASUSTAT 105858157Seric #endif 105958157Seric 106058157Seric #if defined(HASUSTAT) 106158157Seric # include <sys/stat.h> 106258157Seric # include <ustat.h> 106358157Seric #endif 106458157Seric 106558157Seric #ifdef HASSTATFS 106658133Seric # if defined(sgi) || defined(apollo) 106758133Seric # include <sys/statfs.h> 106858133Seric # else 106958133Seric # if defined(sun) || defined(hpux) 107058133Seric # include <sys/vfs.h> 107158133Seric # else 107258157Seric # include <sys/mount.h> 107358133Seric # endif 107458133Seric # endif 107558082Seric #endif 107658082Seric 107758082Seric bool 107858333Seric enoughspace(msize) 107958333Seric long msize; 108058082Seric { 108158160Seric #if defined(HASSTATFS) || defined(HASUSTAT) 108258157Seric # if defined(HASUSTAT) 108358153Seric struct ustat fs; 108458153Seric struct stat statbuf; 108558366Seric # define FSBLOCKSIZE DEV_BSIZE 108658157Seric # define f_bavail f_tfree 108758157Seric # else 108858157Seric # if defined(ultrix) 108958157Seric struct fs_data fs; 109058157Seric # define f_bavail fd_bfreen 109158366Seric # define FSBLOCKSIZE fs.fd_bsize 109258153Seric # else 109358082Seric struct statfs fs; 109458366Seric # define FSBLOCKSIZE fs.f_bsize 109558153Seric # endif 109658133Seric # endif 109758333Seric long blocksneeded; 109858082Seric extern int errno; 109958082Seric extern char *errstring(); 110058082Seric 110158333Seric if (MinBlocksFree <= 0 && msize <= 0) 110258082Seric { 110358082Seric if (tTd(4, 80)) 110458133Seric printf("enoughspace: no threshold\n"); 110558133Seric return TRUE; 110658133Seric } 110758333Seric 110858157Seric # if defined(HASUSTAT) 110958157Seric if (stat(QueueDir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 111058157Seric # else 111158157Seric # if defined(sgi) || defined(apollo) 111258133Seric if (statfs(QueueDir, &fs, sizeof fs, 0) == 0) 111358157Seric # else 111458157Seric # if defined(ultrix) 111558133Seric if (statfs(QueueDir, &fs) > 0) 111658153Seric # else 111758133Seric if (statfs(QueueDir, &fs) == 0) 111858153Seric # endif 111958133Seric # endif 112058133Seric # endif 112158133Seric { 112258133Seric if (tTd(4, 80)) 112358333Seric printf("enoughspace: bavail=%ld, need=%ld\n", 112458333Seric fs.f_bavail, msize); 112558333Seric 112658333Seric /* convert msize to block count */ 112758366Seric msize = msize / FSBLOCKSIZE + 1; 112858333Seric if (MinBlocksFree >= 0) 112958333Seric msize += MinBlocksFree; 113058333Seric 113158333Seric if (fs.f_bavail < msize) 113258090Seric { 113358090Seric #ifdef LOG 113458090Seric if (LogLevel > 0) 113558090Seric syslog(LOG_ALERT, "%s: low on space (have %ld, need %ld)", 113658333Seric QueueDir, fs.f_bavail, msize); 113758090Seric #endif 113858082Seric return FALSE; 113958090Seric } 114058082Seric } 114158082Seric else if (tTd(4, 80)) 114258333Seric printf("enoughspace failure: min=%ld, need=%ld: %s\n", 114358333Seric MinBlocksFree, msize, errstring(errno)); 114458082Seric #endif 114558082Seric return TRUE; 114658082Seric } 114758542Seric /* 114858542Seric ** TRANSIENTERROR -- tell if an error code indicates a transient failure 114958542Seric ** 115058542Seric ** This looks at an errno value and tells if this is likely to 115158542Seric ** go away if retried later. 115258542Seric ** 115358542Seric ** Parameters: 115458542Seric ** err -- the errno code to classify. 115558542Seric ** 115658542Seric ** Returns: 115758542Seric ** TRUE if this is probably transient. 115858542Seric ** FALSE otherwise. 115958542Seric */ 116058542Seric 116158542Seric bool 116258542Seric transienterror(err) 116358542Seric int err; 116458542Seric { 116558542Seric switch (err) 116658542Seric { 116758542Seric case EIO: /* I/O error */ 116858542Seric case ENXIO: /* Device not configured */ 116958542Seric case EAGAIN: /* Resource temporarily unavailable */ 117058542Seric case ENOMEM: /* Cannot allocate memory */ 117158542Seric case ENODEV: /* Operation not supported by device */ 117258542Seric case ENFILE: /* Too many open files in system */ 117358542Seric case EMFILE: /* Too many open files */ 117458542Seric case ENOSPC: /* No space left on device */ 117558542Seric #ifdef ETIMEDOUT 117658542Seric case ETIMEDOUT: /* Connection timed out */ 117758542Seric #endif 117858542Seric #ifdef ESTALE 117958542Seric case ESTALE: /* Stale NFS file handle */ 118058542Seric #endif 118158542Seric #ifdef ENETDOWN 118258542Seric case ENETDOWN: /* Network is down */ 118358542Seric #endif 118458542Seric #ifdef ENETUNREACH 118558542Seric case ENETUNREACH: /* Network is unreachable */ 118658542Seric #endif 118758542Seric #ifdef ENETRESET 118858542Seric case ENETRESET: /* Network dropped connection on reset */ 118958542Seric #endif 119058542Seric #ifdef ECONNABORTED 119158542Seric case ECONNABORTED: /* Software caused connection abort */ 119258542Seric #endif 119358542Seric #ifdef ECONNRESET 119458542Seric case ECONNRESET: /* Connection reset by peer */ 119558542Seric #endif 119658542Seric #ifdef ENOBUFS 119758542Seric case ENOBUFS: /* No buffer space available */ 119858542Seric #endif 119958542Seric #ifdef ESHUTDOWN 120058542Seric case ESHUTDOWN: /* Can't send after socket shutdown */ 120158542Seric #endif 120258542Seric #ifdef ECONNREFUSED 120358542Seric case ECONNREFUSED: /* Connection refused */ 120458542Seric #endif 120558542Seric #ifdef EHOSTDOWN 120658542Seric case EHOSTDOWN: /* Host is down */ 120758542Seric #endif 120858542Seric #ifdef EHOSTUNREACH 120958542Seric case EHOSTUNREACH: /* No route to host */ 121058542Seric #endif 121158542Seric #ifdef EDQUOT 121258542Seric case EDQUOT: /* Disc quota exceeded */ 121358542Seric #endif 121458542Seric #ifdef EPROCLIM 121558542Seric case EPROCLIM: /* Too many processes */ 121658542Seric #endif 121758542Seric #ifdef EUSERS 121858542Seric case EUSERS: /* Too many users */ 121958542Seric #endif 122058542Seric #ifdef EDEADLK 122158542Seric case EDEADLK: /* Resource deadlock avoided */ 122258542Seric #endif 122358542Seric #ifdef EISCONN 122458542Seric case EISCONN: /* Socket already connected */ 122558542Seric #endif 122658542Seric #ifdef EINPROGRESS 122758542Seric case EINPROGRESS: /* Operation now in progress */ 122858542Seric #endif 122958542Seric #ifdef EALREADY 123058542Seric case EALREADY: /* Operation already in progress */ 123158542Seric #endif 123258542Seric #ifdef EADDRINUSE 123358542Seric case EADDRINUSE: /* Address already in use */ 123458542Seric #endif 123558542Seric #ifdef EADDRNOTAVAIL 123658542Seric case EADDRNOTAVAIL: /* Can't assign requested address */ 123758542Seric #endif 123858542Seric #ifdef ENOSR 123958542Seric case ENOSR: /* Out of streams resources */ 124058542Seric #endif 124158542Seric return TRUE; 124258542Seric } 124358542Seric 124458542Seric /* nope, must be permanent */ 124558542Seric return FALSE; 124658542Seric } 124758689Seric /* 124858689Seric ** LOCKFILE -- lock a file using flock or (shudder) lockf 124958689Seric ** 125058689Seric ** Parameters: 125158689Seric ** fd -- the file descriptor of the file. 125258689Seric ** filename -- the file name (for error messages). 125358689Seric ** type -- type of the lock. Bits can be: 125458689Seric ** LOCK_EX -- exclusive lock. 125558689Seric ** LOCK_NB -- non-blocking. 125658689Seric ** 125758689Seric ** Returns: 125858689Seric ** TRUE if the lock was acquired. 125958689Seric ** FALSE otherwise. 126058689Seric */ 126158689Seric 126258689Seric bool 126358689Seric lockfile(fd, filename, type) 126458689Seric int fd; 126558689Seric char *filename; 126658689Seric int type; 126758689Seric { 126858689Seric # ifdef LOCKF 126958689Seric int action; 127058689Seric struct flock lfd; 127158689Seric 1272*58701Seric if (bitset(LOCK_EX, type)) 127358689Seric lfd.l_type = F_WRLCK; 127458689Seric else 127558689Seric lfd.l_type = F_RDLCK; 127658689Seric 127758689Seric if (bitset(LOCK_NB, type)) 127858689Seric action = F_SETLK; 127958689Seric else 128058689Seric action = F_SETLKW; 128158689Seric 128258689Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 128358689Seric 128458689Seric if (fcntl(fd, action, &lfd) >= 0) 128558689Seric return TRUE; 128658689Seric 128758689Seric if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 128858689Seric syserr("cannot lockf(%s)", filename); 128958689Seric # else 129058689Seric if (flock(fd, type) >= 0) 129158689Seric return TRUE; 129258689Seric 129358689Seric if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 129458689Seric syserr("cannot flock(%s)", filename); 129558689Seric # endif 129658689Seric return FALSE; 129758689Seric } 1298