posix.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. /* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
  2. * 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public License
  6. * as published by the Free Software Foundation; either version 3 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301 USA
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. # include <config.h>
  21. #endif
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <errno.h>
  25. #include <uniconv.h>
  26. #ifdef HAVE_SCHED_H
  27. # include <sched.h>
  28. #endif
  29. #ifdef HAVE_STRING_H
  30. #include <string.h>
  31. #endif
  32. #ifdef TIME_WITH_SYS_TIME
  33. # include <sys/time.h>
  34. # include <time.h>
  35. #else
  36. # if HAVE_SYS_TIME_H
  37. # include <sys/time.h>
  38. # else
  39. # include <time.h>
  40. # endif
  41. #endif
  42. #ifdef HAVE_UNISTD_H
  43. #include <unistd.h>
  44. #endif
  45. #ifdef LIBC_H_WITH_UNISTD_H
  46. #include <libc.h>
  47. #endif
  48. #include <sys/types.h>
  49. #include <sys/stat.h>
  50. #include <fcntl.h>
  51. #ifdef HAVE_PWD_H
  52. #include <pwd.h>
  53. #endif
  54. #ifdef HAVE_IO_H
  55. #include <io.h>
  56. #endif
  57. #include "libguile/_scm.h"
  58. #include "libguile/dynwind.h"
  59. #include "libguile/fports.h"
  60. #include "libguile/scmsigs.h"
  61. #include "libguile/feature.h"
  62. #include "libguile/strings.h"
  63. #include "libguile/srfi-13.h"
  64. #include "libguile/srfi-14.h"
  65. #include "libguile/vectors.h"
  66. #include "libguile/values.h"
  67. #include "libguile/validate.h"
  68. #include "libguile/posix.h"
  69. #include "libguile/gettext.h"
  70. #include "libguile/threads.h"
  71. #if HAVE_SYS_WAIT_H
  72. # include <sys/wait.h>
  73. #endif
  74. #ifndef WEXITSTATUS
  75. # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  76. #endif
  77. #ifndef WIFEXITED
  78. # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  79. #endif
  80. #include <signal.h>
  81. #ifdef HAVE_GRP_H
  82. #include <grp.h>
  83. #endif
  84. #ifdef HAVE_SYS_UTSNAME_H
  85. #include <sys/utsname.h>
  86. #endif
  87. #ifdef HAVE_SETLOCALE
  88. #include <locale.h>
  89. #endif
  90. #if (defined HAVE_NEWLOCALE) && (defined HAVE_STRCOLL_L)
  91. # define USE_GNU_LOCALE_API
  92. #endif
  93. #if (defined USE_GNU_LOCALE_API) && (defined HAVE_XLOCALE_H)
  94. # include <xlocale.h>
  95. #endif
  96. #ifdef HAVE_CRYPT_H
  97. # include <crypt.h>
  98. #endif
  99. #ifdef HAVE_NETDB_H
  100. #include <netdb.h> /* for MAXHOSTNAMELEN on Solaris */
  101. #endif
  102. #ifdef HAVE_SYS_PARAM_H
  103. #include <sys/param.h> /* for MAXHOSTNAMELEN */
  104. #endif
  105. #if HAVE_SYS_RESOURCE_H
  106. # include <sys/resource.h>
  107. #endif
  108. #include <sys/file.h> /* from Gnulib */
  109. /* Some Unix systems don't define these. CPP hair is dangerous, but
  110. this seems safe enough... */
  111. #ifndef R_OK
  112. #define R_OK 4
  113. #endif
  114. #ifndef W_OK
  115. #define W_OK 2
  116. #endif
  117. #ifndef X_OK
  118. #define X_OK 1
  119. #endif
  120. #ifndef F_OK
  121. #define F_OK 0
  122. #endif
  123. /* No prototype for this on Solaris 10. The man page says it's in
  124. <unistd.h> ... but it lies. */
  125. #if ! HAVE_DECL_SETHOSTNAME
  126. int sethostname (char *name, size_t namelen);
  127. #endif
  128. #if defined HAVE_GETLOGIN && !HAVE_DECL_GETLOGIN
  129. /* MinGW doesn't supply this decl; see
  130. http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00030.html for more
  131. details. */
  132. char *getlogin (void);
  133. #endif
  134. /* On NextStep, <utime.h> doesn't define struct utime, unless we
  135. #define _POSIX_SOURCE before #including it. I think this is less
  136. of a kludge than defining struct utimbuf ourselves. */
  137. #ifdef UTIMBUF_NEEDS_POSIX
  138. #define _POSIX_SOURCE
  139. #endif
  140. #ifdef HAVE_SYS_UTIME_H
  141. #include <sys/utime.h>
  142. #endif
  143. #ifdef HAVE_UTIME_H
  144. #include <utime.h>
  145. #endif
  146. /* Please don't add any more #includes or #defines here. The hack
  147. above means that _POSIX_SOURCE may be #defined, which will
  148. encourage header files to do strange things.
  149. FIXME: Maybe should undef _POSIX_SOURCE after it's done its job.
  150. FIXME: Probably should do all the includes first, then all the fallback
  151. declarations and defines, in case things are not in the header we
  152. imagine. */
  153. /* Two often used patterns
  154. */
  155. #define WITH_STRING(str,cstr,code) \
  156. do { \
  157. char *cstr = scm_to_locale_string (str); \
  158. code; \
  159. free (cstr); \
  160. } while (0)
  161. #define STRING_SYSCALL(str,cstr,code) \
  162. do { \
  163. int eno; \
  164. char *cstr = scm_to_locale_string (str); \
  165. SCM_SYSCALL (code); \
  166. eno = errno; free (cstr); errno = eno; \
  167. } while (0)
  168. SCM_SYMBOL (sym_read_pipe, "read pipe");
  169. SCM_SYMBOL (sym_write_pipe, "write pipe");
  170. SCM_DEFINE (scm_pipe, "pipe", 0, 0, 0,
  171. (),
  172. "Return a newly created pipe: a pair of ports which are linked\n"
  173. "together on the local machine. The @emph{car} is the input\n"
  174. "port and the @emph{cdr} is the output port. Data written (and\n"
  175. "flushed) to the output port can be read from the input port.\n"
  176. "Pipes are commonly used for communication with a newly forked\n"
  177. "child process. The need to flush the output port can be\n"
  178. "avoided by making it unbuffered using @code{setvbuf}.\n"
  179. "\n"
  180. "Writes occur atomically provided the size of the data in bytes\n"
  181. "is not greater than the value of @code{PIPE_BUF}. Note that\n"
  182. "the output port is likely to block if too much data (typically\n"
  183. "equal to @code{PIPE_BUF}) has been written but not yet read\n"
  184. "from the input port.")
  185. #define FUNC_NAME s_scm_pipe
  186. {
  187. int fd[2], rv;
  188. SCM p_rd, p_wt;
  189. rv = pipe (fd);
  190. if (rv)
  191. SCM_SYSERROR;
  192. p_rd = scm_fdes_to_port (fd[0], "r", sym_read_pipe);
  193. p_wt = scm_fdes_to_port (fd[1], "w", sym_write_pipe);
  194. return scm_cons (p_rd, p_wt);
  195. }
  196. #undef FUNC_NAME
  197. #ifdef HAVE_GETGROUPS
  198. SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
  199. (),
  200. "Return a vector of integers representing the current\n"
  201. "supplementary group IDs.")
  202. #define FUNC_NAME s_scm_getgroups
  203. {
  204. SCM result;
  205. int ngroups;
  206. size_t size;
  207. GETGROUPS_T *groups;
  208. ngroups = getgroups (0, NULL);
  209. if (ngroups < 0)
  210. SCM_SYSERROR;
  211. else if (ngroups == 0)
  212. return scm_c_make_vector (0, SCM_BOOL_F);
  213. size = ngroups * sizeof (GETGROUPS_T);
  214. groups = scm_malloc (size);
  215. ngroups = getgroups (ngroups, groups);
  216. result = scm_c_make_vector (ngroups, SCM_BOOL_F);
  217. while (--ngroups >= 0)
  218. SCM_SIMPLE_VECTOR_SET (result, ngroups, scm_from_ulong (groups[ngroups]));
  219. free (groups);
  220. return result;
  221. }
  222. #undef FUNC_NAME
  223. #endif
  224. #ifdef HAVE_SETGROUPS
  225. SCM_DEFINE (scm_setgroups, "setgroups", 1, 0, 0,
  226. (SCM group_vec),
  227. "Set the current set of supplementary group IDs to the integers\n"
  228. "in the given vector @var{group_vec}. The return value is\n"
  229. "unspecified.\n"
  230. "\n"
  231. "Generally only the superuser can set the process group IDs.")
  232. #define FUNC_NAME s_scm_setgroups
  233. {
  234. size_t ngroups;
  235. size_t size;
  236. size_t i;
  237. int result;
  238. int save_errno;
  239. GETGROUPS_T *groups;
  240. SCM_VALIDATE_VECTOR (SCM_ARG1, group_vec);
  241. ngroups = SCM_SIMPLE_VECTOR_LENGTH (group_vec);
  242. /* validate before allocating, so we don't have to worry about leaks */
  243. for (i = 0; i < ngroups; i++)
  244. {
  245. unsigned long ulong_gid;
  246. GETGROUPS_T gid;
  247. SCM_VALIDATE_ULONG_COPY (1, SCM_SIMPLE_VECTOR_REF (group_vec, i),
  248. ulong_gid);
  249. gid = ulong_gid;
  250. if (gid != ulong_gid)
  251. SCM_OUT_OF_RANGE (1, SCM_SIMPLE_VECTOR_REF (group_vec, i));
  252. }
  253. size = ngroups * sizeof (GETGROUPS_T);
  254. if (size / sizeof (GETGROUPS_T) != ngroups)
  255. SCM_OUT_OF_RANGE (SCM_ARG1, scm_from_int (ngroups));
  256. groups = scm_malloc (size);
  257. for(i = 0; i < ngroups; i++)
  258. groups [i] = SCM_NUM2ULONG (1, SCM_SIMPLE_VECTOR_REF (group_vec, i));
  259. result = setgroups (ngroups, groups);
  260. save_errno = errno; /* don't let free() touch errno */
  261. free (groups);
  262. errno = save_errno;
  263. if (result < 0)
  264. SCM_SYSERROR;
  265. return SCM_UNSPECIFIED;
  266. }
  267. #undef FUNC_NAME
  268. #endif
  269. #ifdef HAVE_GETPWENT
  270. SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
  271. (SCM user),
  272. "Look up an entry in the user database. @var{user} can be an\n"
  273. "integer, a string, or omitted, giving the behaviour of\n"
  274. "@code{getpwuid}, @code{getpwnam} or @code{getpwent}\n"
  275. "respectively.")
  276. #define FUNC_NAME s_scm_getpwuid
  277. {
  278. struct passwd *entry;
  279. SCM result = scm_c_make_vector (7, SCM_UNSPECIFIED);
  280. if (SCM_UNBNDP (user) || scm_is_false (user))
  281. {
  282. SCM_SYSCALL (entry = getpwent ());
  283. if (! entry)
  284. {
  285. return SCM_BOOL_F;
  286. }
  287. }
  288. else if (scm_is_integer (user))
  289. {
  290. entry = getpwuid (scm_to_int (user));
  291. }
  292. else
  293. {
  294. WITH_STRING (user, c_user,
  295. entry = getpwnam (c_user));
  296. }
  297. if (!entry)
  298. SCM_MISC_ERROR ("entry not found", SCM_EOL);
  299. SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->pw_name));
  300. SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->pw_passwd));
  301. SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_ulong (entry->pw_uid));
  302. SCM_SIMPLE_VECTOR_SET(result, 3, scm_from_ulong (entry->pw_gid));
  303. SCM_SIMPLE_VECTOR_SET(result, 4, scm_from_locale_string (entry->pw_gecos));
  304. if (!entry->pw_dir)
  305. SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (""));
  306. else
  307. SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (entry->pw_dir));
  308. if (!entry->pw_shell)
  309. SCM_SIMPLE_VECTOR_SET(result, 6, scm_from_locale_string (""));
  310. else
  311. SCM_SIMPLE_VECTOR_SET(result, 6, scm_from_locale_string (entry->pw_shell));
  312. return result;
  313. }
  314. #undef FUNC_NAME
  315. #endif /* HAVE_GETPWENT */
  316. #ifdef HAVE_SETPWENT
  317. SCM_DEFINE (scm_setpwent, "setpw", 0, 1, 0,
  318. (SCM arg),
  319. "If called with a true argument, initialize or reset the password data\n"
  320. "stream. Otherwise, close the stream. The @code{setpwent} and\n"
  321. "@code{endpwent} procedures are implemented on top of this.")
  322. #define FUNC_NAME s_scm_setpwent
  323. {
  324. if (SCM_UNBNDP (arg) || scm_is_false (arg))
  325. endpwent ();
  326. else
  327. setpwent ();
  328. return SCM_UNSPECIFIED;
  329. }
  330. #undef FUNC_NAME
  331. #endif
  332. #ifdef HAVE_GETGRENT
  333. /* Combines getgrgid and getgrnam. */
  334. SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
  335. (SCM name),
  336. "Look up an entry in the group database. @var{name} can be an\n"
  337. "integer, a string, or omitted, giving the behaviour of\n"
  338. "@code{getgrgid}, @code{getgrnam} or @code{getgrent}\n"
  339. "respectively.")
  340. #define FUNC_NAME s_scm_getgrgid
  341. {
  342. struct group *entry;
  343. SCM result = scm_c_make_vector (4, SCM_UNSPECIFIED);
  344. if (SCM_UNBNDP (name) || scm_is_false (name))
  345. {
  346. SCM_SYSCALL (entry = getgrent ());
  347. if (! entry)
  348. {
  349. return SCM_BOOL_F;
  350. }
  351. }
  352. else if (scm_is_integer (name))
  353. SCM_SYSCALL (entry = getgrgid (scm_to_int (name)));
  354. else
  355. STRING_SYSCALL (name, c_name,
  356. entry = getgrnam (c_name));
  357. if (!entry)
  358. SCM_SYSERROR;
  359. SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->gr_name));
  360. SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->gr_passwd));
  361. SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_ulong (entry->gr_gid));
  362. SCM_SIMPLE_VECTOR_SET(result, 3, scm_makfromstrs (-1, entry->gr_mem));
  363. return result;
  364. }
  365. #undef FUNC_NAME
  366. SCM_DEFINE (scm_setgrent, "setgr", 0, 1, 0,
  367. (SCM arg),
  368. "If called with a true argument, initialize or reset the group data\n"
  369. "stream. Otherwise, close the stream. The @code{setgrent} and\n"
  370. "@code{endgrent} procedures are implemented on top of this.")
  371. #define FUNC_NAME s_scm_setgrent
  372. {
  373. if (SCM_UNBNDP (arg) || scm_is_false (arg))
  374. endgrent ();
  375. else
  376. setgrent ();
  377. return SCM_UNSPECIFIED;
  378. }
  379. #undef FUNC_NAME
  380. #endif /* HAVE_GETGRENT */
  381. #ifdef HAVE_GETRLIMIT
  382. #ifdef RLIMIT_AS
  383. SCM_SYMBOL (sym_as, "as");
  384. #endif
  385. #ifdef RLIMIT_CORE
  386. SCM_SYMBOL (sym_core, "core");
  387. #endif
  388. #ifdef RLIMIT_CPU
  389. SCM_SYMBOL (sym_cpu, "cpu");
  390. #endif
  391. #ifdef RLIMIT_DATA
  392. SCM_SYMBOL (sym_data, "data");
  393. #endif
  394. #ifdef RLIMIT_FSIZE
  395. SCM_SYMBOL (sym_fsize, "fsize");
  396. #endif
  397. #ifdef RLIMIT_MEMLOCK
  398. SCM_SYMBOL (sym_memlock, "memlock");
  399. #endif
  400. #ifdef RLIMIT_MSGQUEUE
  401. SCM_SYMBOL (sym_msgqueue, "msgqueue");
  402. #endif
  403. #ifdef RLIMIT_NICE
  404. SCM_SYMBOL (sym_nice, "nice");
  405. #endif
  406. #ifdef RLIMIT_NOFILE
  407. SCM_SYMBOL (sym_nofile, "nofile");
  408. #endif
  409. #ifdef RLIMIT_NPROC
  410. SCM_SYMBOL (sym_nproc, "nproc");
  411. #endif
  412. #ifdef RLIMIT_RSS
  413. SCM_SYMBOL (sym_rss, "rss");
  414. #endif
  415. #ifdef RLIMIT_RTPRIO
  416. SCM_SYMBOL (sym_rtprio, "rtprio");
  417. #endif
  418. #ifdef RLIMIT_RTPRIO
  419. SCM_SYMBOL (sym_rttime, "rttime");
  420. #endif
  421. #ifdef RLIMIT_SIGPENDING
  422. SCM_SYMBOL (sym_sigpending, "sigpending");
  423. #endif
  424. #ifdef RLIMIT_STACK
  425. SCM_SYMBOL (sym_stack, "stack");
  426. #endif
  427. static int
  428. scm_to_resource (SCM s, const char *func, int pos)
  429. {
  430. if (scm_is_number (s))
  431. return scm_to_int (s);
  432. SCM_ASSERT_TYPE (scm_is_symbol (s), s, pos, func, "symbol");
  433. #ifdef RLIMIT_AS
  434. if (scm_is_eq (s, sym_as))
  435. return RLIMIT_AS;
  436. #endif
  437. #ifdef RLIMIT_CORE
  438. if (scm_is_eq (s, sym_core))
  439. return RLIMIT_CORE;
  440. #endif
  441. #ifdef RLIMIT_CPU
  442. if (scm_is_eq (s, sym_cpu))
  443. return RLIMIT_CPU;
  444. #endif
  445. #ifdef RLIMIT_DATA
  446. if (scm_is_eq (s, sym_data))
  447. return RLIMIT_DATA;
  448. #endif
  449. #ifdef RLIMIT_FSIZE
  450. if (scm_is_eq (s, sym_fsize))
  451. return RLIMIT_FSIZE;
  452. #endif
  453. #ifdef RLIMIT_MEMLOCK
  454. if (scm_is_eq (s, sym_memlock))
  455. return RLIMIT_MEMLOCK;
  456. #endif
  457. #ifdef RLIMIT_MSGQUEUE
  458. if (scm_is_eq (s, sym_msgqueue))
  459. return RLIMIT_MSGQUEUE;
  460. #endif
  461. #ifdef RLIMIT_NICE
  462. if (scm_is_eq (s, sym_nice))
  463. return RLIMIT_NICE;
  464. #endif
  465. #ifdef RLIMIT_NOFILE
  466. if (scm_is_eq (s, sym_nofile))
  467. return RLIMIT_NOFILE;
  468. #endif
  469. #ifdef RLIMIT_NPROC
  470. if (scm_is_eq (s, sym_nproc))
  471. return RLIMIT_NPROC;
  472. #endif
  473. #ifdef RLIMIT_RSS
  474. if (scm_is_eq (s, sym_rss))
  475. return RLIMIT_RSS;
  476. #endif
  477. #ifdef RLIMIT_RTPRIO
  478. if (scm_is_eq (s, sym_rtprio))
  479. return RLIMIT_RTPRIO;
  480. #endif
  481. #ifdef RLIMIT_RTPRIO
  482. if (scm_is_eq (s, sym_rttime))
  483. return RLIMIT_RTPRIO;
  484. #endif
  485. #ifdef RLIMIT_SIGPENDING
  486. if (scm_is_eq (s, sym_sigpending))
  487. return RLIMIT_SIGPENDING;
  488. #endif
  489. #ifdef RLIMIT_STACK
  490. if (scm_is_eq (s, sym_stack))
  491. return RLIMIT_STACK;
  492. #endif
  493. scm_misc_error (func, "invalid rlimit resource ~A", scm_list_1 (s));
  494. return 0;
  495. }
  496. SCM_DEFINE (scm_getrlimit, "getrlimit", 1, 0, 0,
  497. (SCM resource),
  498. "Get a resource limit for this process. @var{resource} identifies the resource,\n"
  499. "either as an integer or as a symbol. For example, @code{(getrlimit 'stack)}\n"
  500. "gets the limits associated with @code{RLIMIT_STACK}.\n\n"
  501. "@code{getrlimit} returns two values, the soft and the hard limit. If no\n"
  502. "limit is set for the resource in question, the returned limit will be @code{#f}.")
  503. #define FUNC_NAME s_scm_getrlimit
  504. {
  505. int iresource;
  506. struct rlimit lim = { 0, 0 };
  507. iresource = scm_to_resource (resource, FUNC_NAME, 1);
  508. if (getrlimit (iresource, &lim) != 0)
  509. scm_syserror (FUNC_NAME);
  510. return scm_values (scm_list_2 ((lim.rlim_cur == RLIM_INFINITY) ? SCM_BOOL_F
  511. : scm_from_long (lim.rlim_cur),
  512. (lim.rlim_max == RLIM_INFINITY) ? SCM_BOOL_F
  513. : scm_from_long (lim.rlim_max)));
  514. }
  515. #undef FUNC_NAME
  516. #ifdef HAVE_SETRLIMIT
  517. SCM_DEFINE (scm_setrlimit, "setrlimit", 3, 0, 0,
  518. (SCM resource, SCM soft, SCM hard),
  519. "Set a resource limit for this process. @var{resource} identifies the resource,\n"
  520. "either as an integer or as a symbol. @var{soft} and @var{hard} should be integers,\n"
  521. "or @code{#f} to indicate no limit (i.e., @code{RLIM_INFINITY}).\n\n"
  522. "For example, @code{(setrlimit 'stack 150000 300000)} sets the @code{RLIMIT_STACK}\n"
  523. "limit to 150 kilobytes, with a hard limit of 300 kB.")
  524. #define FUNC_NAME s_scm_setrlimit
  525. {
  526. int iresource;
  527. struct rlimit lim = { 0, 0 };
  528. iresource = scm_to_resource (resource, FUNC_NAME, 1);
  529. lim.rlim_cur = scm_is_false (soft) ? RLIM_INFINITY : scm_to_long (soft);
  530. lim.rlim_max = scm_is_false (hard) ? RLIM_INFINITY : scm_to_long (hard);
  531. if (setrlimit (iresource, &lim) != 0)
  532. scm_syserror (FUNC_NAME);
  533. return SCM_UNSPECIFIED;
  534. }
  535. #undef FUNC_NAME
  536. #endif /* HAVE_SETRLIMIT */
  537. #endif /* HAVE_GETRLIMIT */
  538. SCM_DEFINE (scm_kill, "kill", 2, 0, 0,
  539. (SCM pid, SCM sig),
  540. "Sends a signal to the specified process or group of processes.\n\n"
  541. "@var{pid} specifies the processes to which the signal is sent:\n\n"
  542. "@table @r\n"
  543. "@item @var{pid} greater than 0\n"
  544. "The process whose identifier is @var{pid}.\n"
  545. "@item @var{pid} equal to 0\n"
  546. "All processes in the current process group.\n"
  547. "@item @var{pid} less than -1\n"
  548. "The process group whose identifier is -@var{pid}\n"
  549. "@item @var{pid} equal to -1\n"
  550. "If the process is privileged, all processes except for some special\n"
  551. "system processes. Otherwise, all processes with the current effective\n"
  552. "user ID.\n"
  553. "@end table\n\n"
  554. "@var{sig} should be specified using a variable corresponding to\n"
  555. "the Unix symbolic name, e.g.,\n\n"
  556. "@defvar SIGHUP\n"
  557. "Hang-up signal.\n"
  558. "@end defvar\n\n"
  559. "@defvar SIGINT\n"
  560. "Interrupt signal.\n"
  561. "@end defvar")
  562. #define FUNC_NAME s_scm_kill
  563. {
  564. /* Signal values are interned in scm_init_posix(). */
  565. #ifdef HAVE_KILL
  566. if (kill (scm_to_int (pid), scm_to_int (sig)) != 0)
  567. SCM_SYSERROR;
  568. #else
  569. /* Mingw has raise(), but not kill(). (Other raw DOS environments might
  570. be similar.) Use raise() when the requested pid is our own process,
  571. otherwise bomb. */
  572. if (scm_to_int (pid) == getpid ())
  573. {
  574. if (raise (scm_to_int (sig)) != 0)
  575. {
  576. err:
  577. SCM_SYSERROR;
  578. }
  579. else
  580. {
  581. errno = ENOSYS;
  582. goto err;
  583. }
  584. }
  585. #endif
  586. return SCM_UNSPECIFIED;
  587. }
  588. #undef FUNC_NAME
  589. #ifdef HAVE_WAITPID
  590. SCM_DEFINE (scm_waitpid, "waitpid", 1, 1, 0,
  591. (SCM pid, SCM options),
  592. "This procedure collects status information from a child process which\n"
  593. "has terminated or (optionally) stopped. Normally it will\n"
  594. "suspend the calling process until this can be done. If more than one\n"
  595. "child process is eligible then one will be chosen by the operating system.\n\n"
  596. "The value of @var{pid} determines the behaviour:\n\n"
  597. "@table @r\n"
  598. "@item @var{pid} greater than 0\n"
  599. "Request status information from the specified child process.\n"
  600. "@item @var{pid} equal to -1 or WAIT_ANY\n"
  601. "Request status information for any child process.\n"
  602. "@item @var{pid} equal to 0 or WAIT_MYPGRP\n"
  603. "Request status information for any child process in the current process\n"
  604. "group.\n"
  605. "@item @var{pid} less than -1\n"
  606. "Request status information for any child process whose process group ID\n"
  607. "is -@var{pid}.\n"
  608. "@end table\n\n"
  609. "The @var{options} argument, if supplied, should be the bitwise OR of the\n"
  610. "values of zero or more of the following variables:\n\n"
  611. "@defvar WNOHANG\n"
  612. "Return immediately even if there are no child processes to be collected.\n"
  613. "@end defvar\n\n"
  614. "@defvar WUNTRACED\n"
  615. "Report status information for stopped processes as well as terminated\n"
  616. "processes.\n"
  617. "@end defvar\n\n"
  618. "The return value is a pair containing:\n\n"
  619. "@enumerate\n"
  620. "@item\n"
  621. "The process ID of the child process, or 0 if @code{WNOHANG} was\n"
  622. "specified and no process was collected.\n"
  623. "@item\n"
  624. "The integer status value.\n"
  625. "@end enumerate")
  626. #define FUNC_NAME s_scm_waitpid
  627. {
  628. int i;
  629. int status;
  630. int ioptions;
  631. if (SCM_UNBNDP (options))
  632. ioptions = 0;
  633. else
  634. {
  635. /* Flags are interned in scm_init_posix. */
  636. ioptions = scm_to_int (options);
  637. }
  638. SCM_SYSCALL (i = waitpid (scm_to_int (pid), &status, ioptions));
  639. if (i == -1)
  640. SCM_SYSERROR;
  641. return scm_cons (scm_from_int (i), scm_from_int (status));
  642. }
  643. #undef FUNC_NAME
  644. #endif /* HAVE_WAITPID */
  645. #ifndef __MINGW32__
  646. SCM_DEFINE (scm_status_exit_val, "status:exit-val", 1, 0, 0,
  647. (SCM status),
  648. "Return the exit status value, as would be set if a process\n"
  649. "ended normally through a call to @code{exit} or @code{_exit},\n"
  650. "if any, otherwise @code{#f}.")
  651. #define FUNC_NAME s_scm_status_exit_val
  652. {
  653. int lstatus;
  654. /* On Ultrix, the WIF... macros assume their argument is an lvalue;
  655. go figure. */
  656. lstatus = scm_to_int (status);
  657. if (WIFEXITED (lstatus))
  658. return (scm_from_int (WEXITSTATUS (lstatus)));
  659. else
  660. return SCM_BOOL_F;
  661. }
  662. #undef FUNC_NAME
  663. SCM_DEFINE (scm_status_term_sig, "status:term-sig", 1, 0, 0,
  664. (SCM status),
  665. "Return the signal number which terminated the process, if any,\n"
  666. "otherwise @code{#f}.")
  667. #define FUNC_NAME s_scm_status_term_sig
  668. {
  669. int lstatus;
  670. lstatus = scm_to_int (status);
  671. if (WIFSIGNALED (lstatus))
  672. return scm_from_int (WTERMSIG (lstatus));
  673. else
  674. return SCM_BOOL_F;
  675. }
  676. #undef FUNC_NAME
  677. SCM_DEFINE (scm_status_stop_sig, "status:stop-sig", 1, 0, 0,
  678. (SCM status),
  679. "Return the signal number which stopped the process, if any,\n"
  680. "otherwise @code{#f}.")
  681. #define FUNC_NAME s_scm_status_stop_sig
  682. {
  683. int lstatus;
  684. lstatus = scm_to_int (status);
  685. if (WIFSTOPPED (lstatus))
  686. return scm_from_int (WSTOPSIG (lstatus));
  687. else
  688. return SCM_BOOL_F;
  689. }
  690. #undef FUNC_NAME
  691. #endif /* __MINGW32__ */
  692. #ifdef HAVE_GETPPID
  693. SCM_DEFINE (scm_getppid, "getppid", 0, 0, 0,
  694. (),
  695. "Return an integer representing the process ID of the parent\n"
  696. "process.")
  697. #define FUNC_NAME s_scm_getppid
  698. {
  699. return scm_from_int (getppid ());
  700. }
  701. #undef FUNC_NAME
  702. #endif /* HAVE_GETPPID */
  703. #ifndef __MINGW32__
  704. SCM_DEFINE (scm_getuid, "getuid", 0, 0, 0,
  705. (),
  706. "Return an integer representing the current real user ID.")
  707. #define FUNC_NAME s_scm_getuid
  708. {
  709. return scm_from_int (getuid ());
  710. }
  711. #undef FUNC_NAME
  712. SCM_DEFINE (scm_getgid, "getgid", 0, 0, 0,
  713. (),
  714. "Return an integer representing the current real group ID.")
  715. #define FUNC_NAME s_scm_getgid
  716. {
  717. return scm_from_int (getgid ());
  718. }
  719. #undef FUNC_NAME
  720. SCM_DEFINE (scm_geteuid, "geteuid", 0, 0, 0,
  721. (),
  722. "Return an integer representing the current effective user ID.\n"
  723. "If the system does not support effective IDs, then the real ID\n"
  724. "is returned. @code{(provided? 'EIDs)} reports whether the\n"
  725. "system supports effective IDs.")
  726. #define FUNC_NAME s_scm_geteuid
  727. {
  728. #ifdef HAVE_GETEUID
  729. return scm_from_int (geteuid ());
  730. #else
  731. return scm_from_int (getuid ());
  732. #endif
  733. }
  734. #undef FUNC_NAME
  735. SCM_DEFINE (scm_getegid, "getegid", 0, 0, 0,
  736. (),
  737. "Return an integer representing the current effective group ID.\n"
  738. "If the system does not support effective IDs, then the real ID\n"
  739. "is returned. @code{(provided? 'EIDs)} reports whether the\n"
  740. "system supports effective IDs.")
  741. #define FUNC_NAME s_scm_getegid
  742. {
  743. #ifdef HAVE_GETEUID
  744. return scm_from_int (getegid ());
  745. #else
  746. return scm_from_int (getgid ());
  747. #endif
  748. }
  749. #undef FUNC_NAME
  750. SCM_DEFINE (scm_setuid, "setuid", 1, 0, 0,
  751. (SCM id),
  752. "Sets both the real and effective user IDs to the integer @var{id}, provided\n"
  753. "the process has appropriate privileges.\n"
  754. "The return value is unspecified.")
  755. #define FUNC_NAME s_scm_setuid
  756. {
  757. if (setuid (scm_to_int (id)) != 0)
  758. SCM_SYSERROR;
  759. return SCM_UNSPECIFIED;
  760. }
  761. #undef FUNC_NAME
  762. SCM_DEFINE (scm_setgid, "setgid", 1, 0, 0,
  763. (SCM id),
  764. "Sets both the real and effective group IDs to the integer @var{id}, provided\n"
  765. "the process has appropriate privileges.\n"
  766. "The return value is unspecified.")
  767. #define FUNC_NAME s_scm_setgid
  768. {
  769. if (setgid (scm_to_int (id)) != 0)
  770. SCM_SYSERROR;
  771. return SCM_UNSPECIFIED;
  772. }
  773. #undef FUNC_NAME
  774. SCM_DEFINE (scm_seteuid, "seteuid", 1, 0, 0,
  775. (SCM id),
  776. "Sets the effective user ID to the integer @var{id}, provided the process\n"
  777. "has appropriate privileges. If effective IDs are not supported, the\n"
  778. "real ID is set instead -- @code{(provided? 'EIDs)} reports whether the\n"
  779. "system supports effective IDs.\n"
  780. "The return value is unspecified.")
  781. #define FUNC_NAME s_scm_seteuid
  782. {
  783. int rv;
  784. #ifdef HAVE_SETEUID
  785. rv = seteuid (scm_to_int (id));
  786. #else
  787. rv = setuid (scm_to_int (id));
  788. #endif
  789. if (rv != 0)
  790. SCM_SYSERROR;
  791. return SCM_UNSPECIFIED;
  792. }
  793. #undef FUNC_NAME
  794. #endif /* __MINGW32__ */
  795. #ifdef HAVE_SETEGID
  796. SCM_DEFINE (scm_setegid, "setegid", 1, 0, 0,
  797. (SCM id),
  798. "Sets the effective group ID to the integer @var{id}, provided the process\n"
  799. "has appropriate privileges. If effective IDs are not supported, the\n"
  800. "real ID is set instead -- @code{(provided? 'EIDs)} reports whether the\n"
  801. "system supports effective IDs.\n"
  802. "The return value is unspecified.")
  803. #define FUNC_NAME s_scm_setegid
  804. {
  805. int rv;
  806. #ifdef HAVE_SETEGID
  807. rv = setegid (scm_to_int (id));
  808. #else
  809. rv = setgid (scm_to_int (id));
  810. #endif
  811. if (rv != 0)
  812. SCM_SYSERROR;
  813. return SCM_UNSPECIFIED;
  814. }
  815. #undef FUNC_NAME
  816. #endif
  817. #ifdef HAVE_GETPGRP
  818. SCM_DEFINE (scm_getpgrp, "getpgrp", 0, 0, 0,
  819. (),
  820. "Return an integer representing the current process group ID.\n"
  821. "This is the POSIX definition, not BSD.")
  822. #define FUNC_NAME s_scm_getpgrp
  823. {
  824. int (*fn)();
  825. fn = (int (*) ()) getpgrp;
  826. return scm_from_int (fn (0));
  827. }
  828. #undef FUNC_NAME
  829. #endif /* HAVE_GETPGRP */
  830. #ifdef HAVE_SETPGID
  831. SCM_DEFINE (scm_setpgid, "setpgid", 2, 0, 0,
  832. (SCM pid, SCM pgid),
  833. "Move the process @var{pid} into the process group @var{pgid}. @var{pid} or\n"
  834. "@var{pgid} must be integers: they can be zero to indicate the ID of the\n"
  835. "current process.\n"
  836. "Fails on systems that do not support job control.\n"
  837. "The return value is unspecified.")
  838. #define FUNC_NAME s_scm_setpgid
  839. {
  840. /* FIXME(?): may be known as setpgrp. */
  841. if (setpgid (scm_to_int (pid), scm_to_int (pgid)) != 0)
  842. SCM_SYSERROR;
  843. return SCM_UNSPECIFIED;
  844. }
  845. #undef FUNC_NAME
  846. #endif /* HAVE_SETPGID */
  847. #ifdef HAVE_SETSID
  848. SCM_DEFINE (scm_setsid, "setsid", 0, 0, 0,
  849. (),
  850. "Creates a new session. The current process becomes the session leader\n"
  851. "and is put in a new process group. The process will be detached\n"
  852. "from its controlling terminal if it has one.\n"
  853. "The return value is an integer representing the new process group ID.")
  854. #define FUNC_NAME s_scm_setsid
  855. {
  856. pid_t sid = setsid ();
  857. if (sid == -1)
  858. SCM_SYSERROR;
  859. return SCM_UNSPECIFIED;
  860. }
  861. #undef FUNC_NAME
  862. #endif /* HAVE_SETSID */
  863. #ifdef HAVE_GETSID
  864. SCM_DEFINE (scm_getsid, "getsid", 1, 0, 0,
  865. (SCM pid),
  866. "Returns the session ID of process @var{pid}. (The session\n"
  867. "ID of a process is the process group ID of its session leader.)")
  868. #define FUNC_NAME s_scm_getsid
  869. {
  870. return scm_from_int (getsid (scm_to_int (pid)));
  871. }
  872. #undef FUNC_NAME
  873. #endif /* HAVE_GETSID */
  874. /* ttyname returns its result in a single static buffer, hence
  875. scm_i_misc_mutex for thread safety. In glibc 2.3.2 two threads
  876. continuously calling ttyname will otherwise get an overwrite quite
  877. easily.
  878. ttyname_r (when available) could be used instead of scm_i_misc_mutex, but
  879. there's probably little to be gained in either speed or parallelism. */
  880. #ifdef HAVE_TTYNAME
  881. SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
  882. (SCM port),
  883. "Return a string with the name of the serial terminal device\n"
  884. "underlying @var{port}.")
  885. #define FUNC_NAME s_scm_ttyname
  886. {
  887. char *result;
  888. int fd, err;
  889. SCM ret = SCM_BOOL_F;
  890. port = SCM_COERCE_OUTPORT (port);
  891. SCM_VALIDATE_OPPORT (1, port);
  892. if (!SCM_FPORTP (port))
  893. return SCM_BOOL_F;
  894. fd = SCM_FPORT_FDES (port);
  895. scm_i_scm_pthread_mutex_lock (&scm_i_misc_mutex);
  896. SCM_SYSCALL (result = ttyname (fd));
  897. err = errno;
  898. if (result != NULL)
  899. result = strdup (result);
  900. scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
  901. if (!result)
  902. {
  903. errno = err;
  904. SCM_SYSERROR;
  905. }
  906. else
  907. ret = scm_take_locale_string (result);
  908. return ret;
  909. }
  910. #undef FUNC_NAME
  911. #endif /* HAVE_TTYNAME */
  912. /* For thread safety "buf" is used instead of NULL for the ctermid static
  913. buffer. Actually it's unlikely the controlling terminal will change
  914. during program execution, and indeed on glibc (2.3.2) it's always just
  915. "/dev/tty", but L_ctermid on the stack is easy and fast and guarantees
  916. safety everywhere. */
  917. #ifdef HAVE_CTERMID
  918. SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
  919. (),
  920. "Return a string containing the file name of the controlling\n"
  921. "terminal for the current process.")
  922. #define FUNC_NAME s_scm_ctermid
  923. {
  924. char buf[L_ctermid];
  925. char *result = ctermid (buf);
  926. if (*result == '\0')
  927. SCM_SYSERROR;
  928. return scm_from_locale_string (result);
  929. }
  930. #undef FUNC_NAME
  931. #endif /* HAVE_CTERMID */
  932. #ifdef HAVE_TCGETPGRP
  933. SCM_DEFINE (scm_tcgetpgrp, "tcgetpgrp", 1, 0, 0,
  934. (SCM port),
  935. "Return the process group ID of the foreground process group\n"
  936. "associated with the terminal open on the file descriptor\n"
  937. "underlying @var{port}.\n"
  938. "\n"
  939. "If there is no foreground process group, the return value is a\n"
  940. "number greater than 1 that does not match the process group ID\n"
  941. "of any existing process group. This can happen if all of the\n"
  942. "processes in the job that was formerly the foreground job have\n"
  943. "terminated, and no other job has yet been moved into the\n"
  944. "foreground.")
  945. #define FUNC_NAME s_scm_tcgetpgrp
  946. {
  947. int fd;
  948. pid_t pgid;
  949. port = SCM_COERCE_OUTPORT (port);
  950. SCM_VALIDATE_OPFPORT (1, port);
  951. fd = SCM_FPORT_FDES (port);
  952. if ((pgid = tcgetpgrp (fd)) == -1)
  953. SCM_SYSERROR;
  954. return scm_from_int (pgid);
  955. }
  956. #undef FUNC_NAME
  957. #endif /* HAVE_TCGETPGRP */
  958. #ifdef HAVE_TCSETPGRP
  959. SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
  960. (SCM port, SCM pgid),
  961. "Set the foreground process group ID for the terminal used by the file\n"
  962. "descriptor underlying @var{port} to the integer @var{pgid}.\n"
  963. "The calling process\n"
  964. "must be a member of the same session as @var{pgid} and must have the same\n"
  965. "controlling terminal. The return value is unspecified.")
  966. #define FUNC_NAME s_scm_tcsetpgrp
  967. {
  968. int fd;
  969. port = SCM_COERCE_OUTPORT (port);
  970. SCM_VALIDATE_OPFPORT (1, port);
  971. fd = SCM_FPORT_FDES (port);
  972. if (tcsetpgrp (fd, scm_to_int (pgid)) == -1)
  973. SCM_SYSERROR;
  974. return SCM_UNSPECIFIED;
  975. }
  976. #undef FUNC_NAME
  977. #endif /* HAVE_TCSETPGRP */
  978. SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
  979. (SCM filename, SCM args),
  980. "Executes the file named by @var{filename} as a new process image.\n"
  981. "The remaining arguments are supplied to the process; from a C program\n"
  982. "they are accessible as the @code{argv} argument to @code{main}.\n"
  983. "Conventionally the first @var{arg} is the same as @var{filename}.\n"
  984. "All arguments must be strings.\n\n"
  985. "If @var{arg} is missing, @var{path} is executed with a null\n"
  986. "argument list, which may have system-dependent side-effects.\n\n"
  987. "This procedure is currently implemented using the @code{execv} system\n"
  988. "call, but we call it @code{execl} because of its Scheme calling interface.")
  989. #define FUNC_NAME s_scm_execl
  990. {
  991. char *exec_file;
  992. char **exec_argv;
  993. scm_dynwind_begin (0);
  994. exec_file = scm_to_locale_string (filename);
  995. scm_dynwind_free (exec_file);
  996. exec_argv = scm_i_allocate_string_pointers (args);
  997. execv (exec_file, exec_argv);
  998. SCM_SYSERROR;
  999. /* not reached. */
  1000. scm_dynwind_end ();
  1001. return SCM_BOOL_F;
  1002. }
  1003. #undef FUNC_NAME
  1004. SCM_DEFINE (scm_execlp, "execlp", 1, 0, 1,
  1005. (SCM filename, SCM args),
  1006. "Similar to @code{execl}, however if\n"
  1007. "@var{filename} does not contain a slash\n"
  1008. "then the file to execute will be located by searching the\n"
  1009. "directories listed in the @code{PATH} environment variable.\n\n"
  1010. "This procedure is currently implemented using the @code{execvp} system\n"
  1011. "call, but we call it @code{execlp} because of its Scheme calling interface.")
  1012. #define FUNC_NAME s_scm_execlp
  1013. {
  1014. char *exec_file;
  1015. char **exec_argv;
  1016. scm_dynwind_begin (0);
  1017. exec_file = scm_to_locale_string (filename);
  1018. scm_dynwind_free (exec_file);
  1019. exec_argv = scm_i_allocate_string_pointers (args);
  1020. execvp (exec_file, exec_argv);
  1021. SCM_SYSERROR;
  1022. /* not reached. */
  1023. scm_dynwind_end ();
  1024. return SCM_BOOL_F;
  1025. }
  1026. #undef FUNC_NAME
  1027. /* OPTIMIZE-ME: scm_execle doesn't need malloced copies of the environment
  1028. list strings the way environ_list_to_c gives. */
  1029. SCM_DEFINE (scm_execle, "execle", 2, 0, 1,
  1030. (SCM filename, SCM env, SCM args),
  1031. "Similar to @code{execl}, but the environment of the new process is\n"
  1032. "specified by @var{env}, which must be a list of strings as returned by the\n"
  1033. "@code{environ} procedure.\n\n"
  1034. "This procedure is currently implemented using the @code{execve} system\n"
  1035. "call, but we call it @code{execle} because of its Scheme calling interface.")
  1036. #define FUNC_NAME s_scm_execle
  1037. {
  1038. char **exec_argv;
  1039. char **exec_env;
  1040. char *exec_file;
  1041. scm_dynwind_begin (0);
  1042. exec_file = scm_to_locale_string (filename);
  1043. scm_dynwind_free (exec_file);
  1044. exec_argv = scm_i_allocate_string_pointers (args);
  1045. exec_env = scm_i_allocate_string_pointers (env);
  1046. execve (exec_file, exec_argv, exec_env);
  1047. SCM_SYSERROR;
  1048. /* not reached. */
  1049. scm_dynwind_end ();
  1050. return SCM_BOOL_F;
  1051. }
  1052. #undef FUNC_NAME
  1053. #ifdef HAVE_FORK
  1054. SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
  1055. (),
  1056. "Creates a new \"child\" process by duplicating the current \"parent\" process.\n"
  1057. "In the child the return value is 0. In the parent the return value is\n"
  1058. "the integer process ID of the child.\n\n"
  1059. "This procedure has been renamed from @code{fork} to avoid a naming conflict\n"
  1060. "with the scsh fork.")
  1061. #define FUNC_NAME s_scm_fork
  1062. {
  1063. int pid;
  1064. scm_i_finalizer_pre_fork ();
  1065. if (scm_ilength (scm_all_threads ()) != 1)
  1066. /* Other threads may be holding on to resources that Guile needs --
  1067. it is not safe to permit one thread to fork while others are
  1068. running.
  1069. In addition, POSIX clearly specifies that if a multi-threaded
  1070. program forks, the child must only call functions that are
  1071. async-signal-safe. We can't guarantee that in general. The best
  1072. we can do is to allow forking only very early, before any call to
  1073. sigaction spawns the signal-handling thread. */
  1074. scm_display
  1075. (scm_from_latin1_string
  1076. ("warning: call to primitive-fork while multiple threads are running;\n"
  1077. " further behavior unspecified. See \"Processes\" in the\n"
  1078. " manual, for more information.\n"),
  1079. scm_current_warning_port ());
  1080. pid = fork ();
  1081. if (pid == -1)
  1082. SCM_SYSERROR;
  1083. return scm_from_int (pid);
  1084. }
  1085. #undef FUNC_NAME
  1086. /* Since Guile uses threads, we have to be very careful to avoid calling
  1087. functions that are not async-signal-safe in the child. That's why
  1088. this function is implemented in C. */
  1089. static SCM
  1090. scm_open_process (SCM mode, SCM prog, SCM args)
  1091. #define FUNC_NAME "open-process"
  1092. {
  1093. long mode_bits;
  1094. int reading, writing;
  1095. int c2p[2]; /* Child to parent. */
  1096. int p2c[2]; /* Parent to child. */
  1097. int in = -1, out = -1, err = -1;
  1098. int pid;
  1099. char *exec_file;
  1100. char **exec_argv;
  1101. int max_fd = 1024;
  1102. exec_file = scm_to_locale_string (prog);
  1103. exec_argv = scm_i_allocate_string_pointers (scm_cons (prog, args));
  1104. mode_bits = scm_i_mode_bits (mode);
  1105. reading = mode_bits & SCM_RDNG;
  1106. writing = mode_bits & SCM_WRTNG;
  1107. if (reading)
  1108. {
  1109. if (pipe (c2p))
  1110. {
  1111. int errno_save = errno;
  1112. free (exec_file);
  1113. errno = errno_save;
  1114. SCM_SYSERROR;
  1115. }
  1116. out = c2p[1];
  1117. }
  1118. if (writing)
  1119. {
  1120. if (pipe (p2c))
  1121. {
  1122. int errno_save = errno;
  1123. free (exec_file);
  1124. if (reading)
  1125. {
  1126. close (c2p[0]);
  1127. close (c2p[1]);
  1128. }
  1129. errno = errno_save;
  1130. SCM_SYSERROR;
  1131. }
  1132. in = p2c[0];
  1133. }
  1134. {
  1135. SCM port;
  1136. if (SCM_OPOUTFPORTP ((port = scm_current_error_port ())))
  1137. err = SCM_FPORT_FDES (port);
  1138. if (out == -1 && SCM_OPOUTFPORTP ((port = scm_current_output_port ())))
  1139. out = SCM_FPORT_FDES (port);
  1140. if (in == -1 && SCM_OPINFPORTP ((port = scm_current_input_port ())))
  1141. in = SCM_FPORT_FDES (port);
  1142. }
  1143. #if defined (HAVE_GETRLIMIT) && defined (RLIMIT_NOFILE)
  1144. {
  1145. struct rlimit lim = { 0, 0 };
  1146. if (getrlimit (RLIMIT_NOFILE, &lim) == 0)
  1147. max_fd = lim.rlim_cur;
  1148. }
  1149. #endif
  1150. pid = fork ();
  1151. if (pid == -1)
  1152. {
  1153. int errno_save = errno;
  1154. free (exec_file);
  1155. if (reading)
  1156. {
  1157. close (c2p[0]);
  1158. close (c2p[1]);
  1159. }
  1160. if (writing)
  1161. {
  1162. close (p2c[0]);
  1163. close (p2c[1]);
  1164. }
  1165. errno = errno_save;
  1166. SCM_SYSERROR;
  1167. }
  1168. if (pid)
  1169. /* Parent. */
  1170. {
  1171. SCM read_port = SCM_BOOL_F, write_port = SCM_BOOL_F;
  1172. /* There is no sense in catching errors on close(). */
  1173. if (reading)
  1174. {
  1175. close (c2p[1]);
  1176. read_port = scm_fdes_to_port (c2p[0], "r", sym_read_pipe);
  1177. scm_setvbuf (read_port, scm_from_int (_IONBF), SCM_UNDEFINED);
  1178. }
  1179. if (writing)
  1180. {
  1181. close (p2c[0]);
  1182. write_port = scm_fdes_to_port (p2c[1], "w", sym_write_pipe);
  1183. scm_setvbuf (write_port, scm_from_int (_IONBF), SCM_UNDEFINED);
  1184. }
  1185. return scm_values
  1186. (scm_list_3 (read_port, write_port, scm_from_int (pid)));
  1187. }
  1188. /* The child. */
  1189. if (reading)
  1190. close (c2p[0]);
  1191. if (writing)
  1192. close (p2c[1]);
  1193. /* Close all file descriptors in ports inherited from the parent
  1194. except for in, out, and err. Heavy-handed, but robust. */
  1195. while (max_fd--)
  1196. if (max_fd != in && max_fd != out && max_fd != err)
  1197. close (max_fd);
  1198. /* Ignore errors on these open() calls. */
  1199. if (in == -1)
  1200. in = open ("/dev/null", O_RDONLY);
  1201. if (out == -1)
  1202. out = open ("/dev/null", O_WRONLY);
  1203. if (err == -1)
  1204. err = open ("/dev/null", O_WRONLY);
  1205. if (in > 0)
  1206. {
  1207. if (out == 0)
  1208. do out = dup (out); while (errno == EINTR);
  1209. if (err == 0)
  1210. do err = dup (err); while (errno == EINTR);
  1211. do dup2 (in, 0); while (errno == EINTR);
  1212. close (in);
  1213. }
  1214. if (out > 1)
  1215. {
  1216. if (err == 1)
  1217. do err = dup (err); while (errno == EINTR);
  1218. do dup2 (out, 1); while (errno == EINTR);
  1219. close (out);
  1220. }
  1221. if (err > 2)
  1222. {
  1223. do dup2 (err, 2); while (errno == EINTR);
  1224. close (err);
  1225. }
  1226. execvp (exec_file, exec_argv);
  1227. /* The exec failed! There is nothing sensible to do. */
  1228. if (err > 0)
  1229. {
  1230. char *msg = strerror (errno);
  1231. fprintf (fdopen (err, "a"), "In execlp of %s: %s\n",
  1232. exec_file, msg);
  1233. }
  1234. _exit (EXIT_FAILURE);
  1235. /* Not reached. */
  1236. return SCM_BOOL_F;
  1237. }
  1238. #undef FUNC_NAME
  1239. #endif /* HAVE_FORK */
  1240. #ifdef __MINGW32__
  1241. # include "win32-uname.h"
  1242. #endif
  1243. #if defined (HAVE_UNAME) || defined (__MINGW32__)
  1244. SCM_DEFINE (scm_uname, "uname", 0, 0, 0,
  1245. (),
  1246. "Return an object with some information about the computer\n"
  1247. "system the program is running on.")
  1248. #define FUNC_NAME s_scm_uname
  1249. {
  1250. struct utsname buf;
  1251. SCM result = scm_c_make_vector (5, SCM_UNSPECIFIED);
  1252. if (uname (&buf) < 0)
  1253. SCM_SYSERROR;
  1254. SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (buf.sysname));
  1255. SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (buf.nodename));
  1256. SCM_SIMPLE_VECTOR_SET(result, 2, scm_from_locale_string (buf.release));
  1257. SCM_SIMPLE_VECTOR_SET(result, 3, scm_from_locale_string (buf.version));
  1258. SCM_SIMPLE_VECTOR_SET(result, 4, scm_from_locale_string (buf.machine));
  1259. /*
  1260. a linux special?
  1261. SCM_SIMPLE_VECTOR_SET(result, 5, scm_from_locale_string (buf.domainname));
  1262. */
  1263. return result;
  1264. }
  1265. #undef FUNC_NAME
  1266. #endif /* HAVE_UNAME */
  1267. SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
  1268. (SCM env),
  1269. "If @var{env} is omitted, return the current environment (in the\n"
  1270. "Unix sense) as a list of strings. Otherwise set the current\n"
  1271. "environment, which is also the default environment for child\n"
  1272. "processes, to the supplied list of strings. Each member of\n"
  1273. "@var{env} should be of the form @code{NAME=VALUE} and values of\n"
  1274. "@code{NAME} should not be duplicated. If @var{env} is supplied\n"
  1275. "then the return value is unspecified.")
  1276. #define FUNC_NAME s_scm_environ
  1277. {
  1278. if (SCM_UNBNDP (env))
  1279. return scm_makfromstrs (-1, environ);
  1280. else
  1281. {
  1282. environ = scm_i_allocate_string_pointers (env);
  1283. return SCM_UNSPECIFIED;
  1284. }
  1285. }
  1286. #undef FUNC_NAME
  1287. #ifdef L_tmpnam
  1288. SCM_DEFINE (scm_tmpnam, "tmpnam", 0, 0, 0,
  1289. (),
  1290. "Return a name in the file system that does not match any\n"
  1291. "existing file. However there is no guarantee that another\n"
  1292. "process will not create the file after @code{tmpnam} is called.\n"
  1293. "Care should be taken if opening the file, e.g., use the\n"
  1294. "@code{O_EXCL} open flag or use @code{mkstemp!} instead.")
  1295. #define FUNC_NAME s_scm_tmpnam
  1296. {
  1297. char name[L_tmpnam];
  1298. char *rv;
  1299. SCM_SYSCALL (rv = tmpnam (name));
  1300. if (rv == NULL)
  1301. /* not SCM_SYSERROR since errno probably not set. */
  1302. SCM_MISC_ERROR ("tmpnam failed", SCM_EOL);
  1303. return scm_from_locale_string (name);
  1304. }
  1305. #undef FUNC_NAME
  1306. #endif
  1307. SCM_DEFINE (scm_tmpfile, "tmpfile", 0, 0, 0,
  1308. (void),
  1309. "Return an input/output port to a unique temporary file\n"
  1310. "named using the path prefix @code{P_tmpdir} defined in\n"
  1311. "@file{stdio.h}.\n"
  1312. "The file is automatically deleted when the port is closed\n"
  1313. "or the program terminates.")
  1314. #define FUNC_NAME s_scm_tmpfile
  1315. {
  1316. FILE *rv;
  1317. int fd;
  1318. if (! (rv = tmpfile ()))
  1319. SCM_SYSERROR;
  1320. #ifndef __MINGW32__
  1321. fd = dup (fileno (rv));
  1322. fclose (rv);
  1323. #else
  1324. fd = fileno (rv);
  1325. /* FIXME: leaking the file, it will never be closed! */
  1326. #endif
  1327. return scm_fdes_to_port (fd, "w+", SCM_BOOL_F);
  1328. }
  1329. #undef FUNC_NAME
  1330. SCM_DEFINE (scm_utime, "utime", 1, 5, 0,
  1331. (SCM pathname, SCM actime, SCM modtime, SCM actimens, SCM modtimens,
  1332. SCM flags),
  1333. "@code{utime} sets the access and modification times for the\n"
  1334. "file named by @var{pathname}. If @var{actime} or @var{modtime} is\n"
  1335. "not supplied, then the current time is used. @var{actime} and\n"
  1336. "@var{modtime} must be integer time values as returned by the\n"
  1337. "@code{current-time} procedure.\n\n"
  1338. "The optional @var{actimens} and @var{modtimens} are nanoseconds\n"
  1339. "to add @var{actime} and @var{modtime}. Nanosecond precision is\n"
  1340. "only supported on some combinations of file systems and operating\n"
  1341. "systems.\n"
  1342. "@lisp\n"
  1343. "(utime \"foo\" (- (current-time) 3600))\n"
  1344. "@end lisp\n"
  1345. "will set the access time to one hour in the past and the\n"
  1346. "modification time to the current time.")
  1347. #define FUNC_NAME s_scm_utime
  1348. {
  1349. int rv;
  1350. time_t atim_sec, mtim_sec;
  1351. long atim_nsec, mtim_nsec;
  1352. int f;
  1353. if (SCM_UNBNDP (actime))
  1354. {
  1355. #ifdef HAVE_UTIMENSAT
  1356. atim_sec = 0;
  1357. atim_nsec = UTIME_NOW;
  1358. #else
  1359. SCM_SYSCALL (time (&atim_sec));
  1360. atim_nsec = 0;
  1361. #endif
  1362. }
  1363. else
  1364. {
  1365. atim_sec = SCM_NUM2ULONG (2, actime);
  1366. if (SCM_UNBNDP (actimens))
  1367. atim_nsec = 0;
  1368. else
  1369. atim_nsec = SCM_NUM2LONG (4, actimens);
  1370. }
  1371. if (SCM_UNBNDP (modtime))
  1372. {
  1373. #ifdef HAVE_UTIMENSAT
  1374. mtim_sec = 0;
  1375. mtim_nsec = UTIME_NOW;
  1376. #else
  1377. SCM_SYSCALL (time (&mtim_sec));
  1378. mtim_nsec = 0;
  1379. #endif
  1380. }
  1381. else
  1382. {
  1383. mtim_sec = SCM_NUM2ULONG (3, modtime);
  1384. if (SCM_UNBNDP (modtimens))
  1385. mtim_nsec = 0;
  1386. else
  1387. mtim_nsec = SCM_NUM2LONG (5, modtimens);
  1388. }
  1389. if (SCM_UNBNDP (flags))
  1390. f = 0;
  1391. else
  1392. f = SCM_NUM2INT (6, flags);
  1393. #ifdef HAVE_UTIMENSAT
  1394. {
  1395. struct timespec times[2];
  1396. times[0].tv_sec = atim_sec;
  1397. times[0].tv_nsec = atim_nsec;
  1398. times[1].tv_sec = mtim_sec;
  1399. times[1].tv_nsec = mtim_nsec;
  1400. STRING_SYSCALL (pathname, c_pathname,
  1401. rv = utimensat (AT_FDCWD, c_pathname, times, f));
  1402. }
  1403. #else
  1404. {
  1405. struct utimbuf utm;
  1406. utm.actime = atim_sec;
  1407. utm.modtime = mtim_sec;
  1408. /* Silence warnings. */
  1409. (void) atim_nsec;
  1410. (void) mtim_nsec;
  1411. if (f != 0)
  1412. scm_out_of_range(FUNC_NAME, flags);
  1413. STRING_SYSCALL (pathname, c_pathname,
  1414. rv = utime (c_pathname, &utm));
  1415. }
  1416. #endif
  1417. if (rv != 0)
  1418. SCM_SYSERROR;
  1419. return SCM_UNSPECIFIED;
  1420. }
  1421. #undef FUNC_NAME
  1422. SCM_DEFINE (scm_getpid, "getpid", 0, 0, 0,
  1423. (),
  1424. "Return an integer representing the current process ID.")
  1425. #define FUNC_NAME s_scm_getpid
  1426. {
  1427. return scm_from_ulong (getpid ());
  1428. }
  1429. #undef FUNC_NAME
  1430. SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
  1431. (SCM str),
  1432. "Modifies the environment of the current process, which is also\n"
  1433. "the default environment inherited by child processes. If\n"
  1434. "@var{str} is of the form @code{NAME=VALUE} then it will be\n"
  1435. "written directly into the environment, replacing any existing\n"
  1436. "environment string with name matching @code{NAME}. If\n"
  1437. "@var{str} does not contain an equal sign, then any existing\n"
  1438. "string with name matching @var{str} will be removed.\n"
  1439. "\n"
  1440. "The return value is unspecified.")
  1441. #define FUNC_NAME s_scm_putenv
  1442. {
  1443. int rv;
  1444. char *c_str = scm_to_locale_string (str);
  1445. /* Leave C_STR in the environment. */
  1446. /* Gnulib's `putenv' module honors the semantics described above. */
  1447. rv = putenv (c_str);
  1448. if (rv < 0)
  1449. SCM_SYSERROR;
  1450. return SCM_UNSPECIFIED;
  1451. }
  1452. #undef FUNC_NAME
  1453. /* This mutex is used to serialize invocations of `setlocale ()' on non-GNU
  1454. systems (i.e., systems where a reentrant locale API is not available). It
  1455. is also acquired before calls to `nl_langinfo ()'. See `i18n.c' for
  1456. details. */
  1457. scm_i_pthread_mutex_t scm_i_locale_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER;
  1458. #ifdef HAVE_SETLOCALE
  1459. SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
  1460. (SCM category, SCM locale),
  1461. "If @var{locale} is omitted, return the current value of the\n"
  1462. "specified locale category as a system-dependent string.\n"
  1463. "@var{category} should be specified using the values\n"
  1464. "@code{LC_COLLATE}, @code{LC_ALL} etc.\n"
  1465. "\n"
  1466. "Otherwise the specified locale category is set to the string\n"
  1467. "@var{locale} and the new value is returned as a\n"
  1468. "system-dependent string. If @var{locale} is an empty string,\n"
  1469. "the locale will be set using environment variables.\n"
  1470. "\n"
  1471. "When the locale is changed, the character encoding of the new\n"
  1472. "locale (UTF-8, ISO-8859-1, etc.) is used for the current\n"
  1473. "input, output, and error ports\n")
  1474. #define FUNC_NAME s_scm_setlocale
  1475. {
  1476. int c_category;
  1477. char *clocale;
  1478. char *rv;
  1479. const char *enc;
  1480. scm_dynwind_begin (0);
  1481. if (SCM_UNBNDP (locale))
  1482. {
  1483. clocale = NULL;
  1484. }
  1485. else
  1486. {
  1487. clocale = scm_to_locale_string (locale);
  1488. scm_dynwind_free (clocale);
  1489. }
  1490. c_category = scm_i_to_lc_category (category, 1);
  1491. scm_i_pthread_mutex_lock (&scm_i_locale_mutex);
  1492. rv = setlocale (c_category, clocale);
  1493. scm_i_pthread_mutex_unlock (&scm_i_locale_mutex);
  1494. if (rv == NULL)
  1495. {
  1496. /* POSIX and C99 don't say anything about setlocale setting errno, so
  1497. force a sensible value here. glibc leaves ENOENT, which would be
  1498. fine, but it's not a documented feature. */
  1499. errno = EINVAL;
  1500. SCM_SYSERROR;
  1501. }
  1502. enc = locale_charset ();
  1503. /* Set the default encoding for new ports. */
  1504. scm_i_set_default_port_encoding (enc);
  1505. /* Set the encoding for the stdio ports. */
  1506. scm_i_set_port_encoding_x (scm_current_input_port (), enc);
  1507. scm_i_set_port_encoding_x (scm_current_output_port (), enc);
  1508. scm_i_set_port_encoding_x (scm_current_error_port (), enc);
  1509. scm_dynwind_end ();
  1510. return scm_from_locale_string (rv);
  1511. }
  1512. #undef FUNC_NAME
  1513. #endif /* HAVE_SETLOCALE */
  1514. #ifdef HAVE_MKNOD
  1515. SCM_DEFINE (scm_mknod, "mknod", 4, 0, 0,
  1516. (SCM path, SCM type, SCM perms, SCM dev),
  1517. "Creates a new special file, such as a file corresponding to a device.\n"
  1518. "@var{path} specifies the name of the file. @var{type} should\n"
  1519. "be one of the following symbols:\n"
  1520. "regular, directory, symlink, block-special, char-special,\n"
  1521. "fifo, or socket. @var{perms} (an integer) specifies the file permissions.\n"
  1522. "@var{dev} (an integer) specifies which device the special file refers\n"
  1523. "to. Its exact interpretation depends on the kind of special file\n"
  1524. "being created.\n\n"
  1525. "E.g.,\n"
  1526. "@lisp\n"
  1527. "(mknod \"/dev/fd0\" 'block-special #o660 (+ (* 2 256) 2))\n"
  1528. "@end lisp\n\n"
  1529. "The return value is unspecified.")
  1530. #define FUNC_NAME s_scm_mknod
  1531. {
  1532. int val;
  1533. const char *p;
  1534. int ctype = 0;
  1535. SCM_VALIDATE_STRING (1, path);
  1536. SCM_VALIDATE_SYMBOL (2, type);
  1537. p = scm_i_symbol_chars (type);
  1538. if (strcmp (p, "regular") == 0)
  1539. ctype = S_IFREG;
  1540. else if (strcmp (p, "directory") == 0)
  1541. ctype = S_IFDIR;
  1542. #ifdef S_IFLNK
  1543. /* systems without symlinks probably don't have S_IFLNK defined */
  1544. else if (strcmp (p, "symlink") == 0)
  1545. ctype = S_IFLNK;
  1546. #endif
  1547. else if (strcmp (p, "block-special") == 0)
  1548. ctype = S_IFBLK;
  1549. else if (strcmp (p, "char-special") == 0)
  1550. ctype = S_IFCHR;
  1551. else if (strcmp (p, "fifo") == 0)
  1552. ctype = S_IFIFO;
  1553. #ifdef S_IFSOCK
  1554. else if (strcmp (p, "socket") == 0)
  1555. ctype = S_IFSOCK;
  1556. #endif
  1557. else
  1558. SCM_OUT_OF_RANGE (2, type);
  1559. STRING_SYSCALL (path, c_path,
  1560. val = mknod (c_path,
  1561. ctype | scm_to_int (perms),
  1562. scm_to_int (dev)));
  1563. if (val != 0)
  1564. SCM_SYSERROR;
  1565. return SCM_UNSPECIFIED;
  1566. }
  1567. #undef FUNC_NAME
  1568. #endif /* HAVE_MKNOD */
  1569. #ifdef HAVE_NICE
  1570. SCM_DEFINE (scm_nice, "nice", 1, 0, 0,
  1571. (SCM incr),
  1572. "Increment the priority of the current process by @var{incr}. A higher\n"
  1573. "priority value means that the process runs less often.\n"
  1574. "The return value is unspecified.")
  1575. #define FUNC_NAME s_scm_nice
  1576. {
  1577. /* nice() returns "prio-NZERO" on success or -1 on error, but -1 can arise
  1578. from "prio-NZERO", so an error must be detected from errno changed */
  1579. errno = 0;
  1580. nice (scm_to_int (incr));
  1581. if (errno != 0)
  1582. SCM_SYSERROR;
  1583. return SCM_UNSPECIFIED;
  1584. }
  1585. #undef FUNC_NAME
  1586. #endif /* HAVE_NICE */
  1587. #ifdef HAVE_SYNC
  1588. SCM_DEFINE (scm_sync, "sync", 0, 0, 0,
  1589. (),
  1590. "Flush the operating system disk buffers.\n"
  1591. "The return value is unspecified.")
  1592. #define FUNC_NAME s_scm_sync
  1593. {
  1594. sync();
  1595. return SCM_UNSPECIFIED;
  1596. }
  1597. #undef FUNC_NAME
  1598. #endif /* HAVE_SYNC */
  1599. /* crypt() returns a pointer to a static buffer, so we use scm_i_misc_mutex
  1600. to avoid another thread overwriting it. A test program running crypt
  1601. continuously in two threads can be quickly seen tripping this problem.
  1602. crypt() is pretty slow normally, so a mutex shouldn't add much overhead.
  1603. glibc has a thread-safe crypt_r, but (in version 2.3.2) it runs a lot
  1604. slower (about 5x) than plain crypt if you pass an uninitialized data
  1605. block each time. Presumably there's some one-time setups. The best way
  1606. to use crypt_r for parallel execution in multiple threads would probably
  1607. be to maintain a little pool of initialized crypt_data structures, take
  1608. one and use it, then return it to the pool. That pool could be garbage
  1609. collected so it didn't add permanently to memory use if only a few crypt
  1610. calls are made. But we expect crypt will be used rarely, and even more
  1611. rarely will there be any desire for lots of parallel execution on
  1612. multiple cpus. So for now we don't bother with anything fancy, just
  1613. ensure it works. */
  1614. #ifdef HAVE_CRYPT
  1615. SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0,
  1616. (SCM key, SCM salt),
  1617. "Encrypt @var{key} using @var{salt} as the salt value to the\n"
  1618. "crypt(3) library call.")
  1619. #define FUNC_NAME s_scm_crypt
  1620. {
  1621. SCM ret;
  1622. char *c_key, *c_salt, *c_ret;
  1623. scm_dynwind_begin (0);
  1624. scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
  1625. c_key = scm_to_locale_string (key);
  1626. scm_dynwind_free (c_key);
  1627. c_salt = scm_to_locale_string (salt);
  1628. scm_dynwind_free (c_salt);
  1629. /* The Linux crypt(3) man page says crypt will return NULL and set errno
  1630. on error. (Eg. ENOSYS if legal restrictions mean it cannot be
  1631. implemented). */
  1632. c_ret = crypt (c_key, c_salt);
  1633. if (c_ret == NULL)
  1634. SCM_SYSERROR;
  1635. ret = scm_from_locale_string (c_ret);
  1636. scm_dynwind_end ();
  1637. return ret;
  1638. }
  1639. #undef FUNC_NAME
  1640. #endif /* HAVE_CRYPT */
  1641. #if HAVE_CHROOT
  1642. SCM_DEFINE (scm_chroot, "chroot", 1, 0, 0,
  1643. (SCM path),
  1644. "Change the root directory to that specified in @var{path}.\n"
  1645. "This directory will be used for path names beginning with\n"
  1646. "@file{/}. The root directory is inherited by all children\n"
  1647. "of the current process. Only the superuser may change the\n"
  1648. "root directory.")
  1649. #define FUNC_NAME s_scm_chroot
  1650. {
  1651. int rv;
  1652. WITH_STRING (path, c_path,
  1653. rv = chroot (c_path));
  1654. if (rv == -1)
  1655. SCM_SYSERROR;
  1656. return SCM_UNSPECIFIED;
  1657. }
  1658. #undef FUNC_NAME
  1659. #endif /* HAVE_CHROOT */
  1660. SCM_DEFINE (scm_getlogin, "getlogin", 0, 0, 0,
  1661. (void),
  1662. "Return a string containing the name of the user logged in on\n"
  1663. "the controlling terminal of the process, or @code{#f} if this\n"
  1664. "information cannot be obtained.")
  1665. #define FUNC_NAME s_scm_getlogin
  1666. {
  1667. char * p;
  1668. p = getlogin ();
  1669. if (!p || !*p)
  1670. return SCM_BOOL_F;
  1671. return scm_from_locale_string (p);
  1672. }
  1673. #undef FUNC_NAME
  1674. #if HAVE_GETPRIORITY
  1675. SCM_DEFINE (scm_getpriority, "getpriority", 2, 0, 0,
  1676. (SCM which, SCM who),
  1677. "Return the scheduling priority of the process, process group\n"
  1678. "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
  1679. "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
  1680. "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
  1681. "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
  1682. "process group identifier for @code{PRIO_PGRP}, and a user\n"
  1683. "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
  1684. "denotes the current process, process group, or user. Return\n"
  1685. "the highest priority (lowest numerical value) of any of the\n"
  1686. "specified processes.")
  1687. #define FUNC_NAME s_scm_getpriority
  1688. {
  1689. int cwhich, cwho, ret;
  1690. cwhich = scm_to_int (which);
  1691. cwho = scm_to_int (who);
  1692. /* We have to clear errno and examine it later, because -1 is a
  1693. legal return value for getpriority(). */
  1694. errno = 0;
  1695. ret = getpriority (cwhich, cwho);
  1696. if (errno != 0)
  1697. SCM_SYSERROR;
  1698. return scm_from_int (ret);
  1699. }
  1700. #undef FUNC_NAME
  1701. #endif /* HAVE_GETPRIORITY */
  1702. #if HAVE_SETPRIORITY
  1703. SCM_DEFINE (scm_setpriority, "setpriority", 3, 0, 0,
  1704. (SCM which, SCM who, SCM prio),
  1705. "Set the scheduling priority of the process, process group\n"
  1706. "or user, as indicated by @var{which} and @var{who}. @var{which}\n"
  1707. "is one of the variables @code{PRIO_PROCESS}, @code{PRIO_PGRP}\n"
  1708. "or @code{PRIO_USER}, and @var{who} is interpreted relative to\n"
  1709. "@var{which} (a process identifier for @code{PRIO_PROCESS},\n"
  1710. "process group identifier for @code{PRIO_PGRP}, and a user\n"
  1711. "identifier for @code{PRIO_USER}. A zero value of @var{who}\n"
  1712. "denotes the current process, process group, or user.\n"
  1713. "@var{prio} is a value in the range -20 and 20, the default\n"
  1714. "priority is 0; lower priorities cause more favorable\n"
  1715. "scheduling. Sets the priority of all of the specified\n"
  1716. "processes. Only the super-user may lower priorities.\n"
  1717. "The return value is not specified.")
  1718. #define FUNC_NAME s_scm_setpriority
  1719. {
  1720. int cwhich, cwho, cprio;
  1721. cwhich = scm_to_int (which);
  1722. cwho = scm_to_int (who);
  1723. cprio = scm_to_int (prio);
  1724. if (setpriority (cwhich, cwho, cprio) == -1)
  1725. SCM_SYSERROR;
  1726. return SCM_UNSPECIFIED;
  1727. }
  1728. #undef FUNC_NAME
  1729. #endif /* HAVE_SETPRIORITY */
  1730. #ifdef HAVE_SCHED_GETAFFINITY
  1731. static SCM
  1732. cpu_set_to_bitvector (const cpu_set_t *cs)
  1733. {
  1734. SCM bv;
  1735. size_t cpu;
  1736. bv = scm_c_make_bitvector (sizeof (*cs), SCM_BOOL_F);
  1737. for (cpu = 0; cpu < sizeof (*cs); cpu++)
  1738. {
  1739. if (CPU_ISSET (cpu, cs))
  1740. /* XXX: This is inefficient but avoids code duplication. */
  1741. scm_c_bitvector_set_x (bv, cpu, SCM_BOOL_T);
  1742. }
  1743. return bv;
  1744. }
  1745. SCM_DEFINE (scm_getaffinity, "getaffinity", 1, 0, 0,
  1746. (SCM pid),
  1747. "Return a bitvector representing the CPU affinity mask for\n"
  1748. "process @var{pid}. Each CPU the process has affinity with\n"
  1749. "has its corresponding bit set in the returned bitvector.\n"
  1750. "The number of bits set is a good estimate of how many CPUs\n"
  1751. "Guile can use without stepping on other processes' toes.\n\n"
  1752. "Currently this procedure is only defined on GNU variants\n"
  1753. "(@pxref{CPU Affinity, @code{sched_getaffinity},, libc, The\n"
  1754. "GNU C Library Reference Manual}).\n")
  1755. #define FUNC_NAME s_scm_getaffinity
  1756. {
  1757. int err;
  1758. cpu_set_t cs;
  1759. CPU_ZERO (&cs);
  1760. err = sched_getaffinity (scm_to_int (pid), sizeof (cs), &cs);
  1761. if (err)
  1762. SCM_SYSERROR;
  1763. return cpu_set_to_bitvector (&cs);
  1764. }
  1765. #undef FUNC_NAME
  1766. #endif /* HAVE_SCHED_GETAFFINITY */
  1767. #ifdef HAVE_SCHED_SETAFFINITY
  1768. SCM_DEFINE (scm_setaffinity, "setaffinity", 2, 0, 0,
  1769. (SCM pid, SCM mask),
  1770. "Install the CPU affinity mask @var{mask}, a bitvector, for\n"
  1771. "the process or thread with ID @var{pid}. The return value\n"
  1772. "is unspecified.\n\n"
  1773. "Currently this procedure is only defined on GNU variants\n"
  1774. "(@pxref{CPU Affinity, @code{sched_setaffinity},, libc, The\n"
  1775. "GNU C Library Reference Manual}).\n")
  1776. #define FUNC_NAME s_scm_setaffinity
  1777. {
  1778. cpu_set_t cs;
  1779. scm_t_array_handle handle;
  1780. const scm_t_uint32 *c_mask;
  1781. size_t len, off, cpu;
  1782. ssize_t inc;
  1783. int err;
  1784. c_mask = scm_bitvector_elements (mask, &handle, &off, &len, &inc);
  1785. CPU_ZERO (&cs);
  1786. for (cpu = 0; cpu < len; cpu++)
  1787. {
  1788. size_t idx;
  1789. idx = cpu * inc + off;
  1790. if (c_mask[idx / 32] & (1UL << (idx % 32)))
  1791. CPU_SET (cpu, &cs);
  1792. }
  1793. err = sched_setaffinity (scm_to_int (pid), sizeof (cs), &cs);
  1794. if (err)
  1795. SCM_SYSERROR;
  1796. return SCM_UNSPECIFIED;
  1797. }
  1798. #undef FUNC_NAME
  1799. #endif /* HAVE_SCHED_SETAFFINITY */
  1800. #if HAVE_GETPASS
  1801. SCM_DEFINE (scm_getpass, "getpass", 1, 0, 0,
  1802. (SCM prompt),
  1803. "Display @var{prompt} to the standard error output and read\n"
  1804. "a password from @file{/dev/tty}. If this file is not\n"
  1805. "accessible, it reads from standard input. The password may be\n"
  1806. "up to 127 characters in length. Additional characters and the\n"
  1807. "terminating newline character are discarded. While reading\n"
  1808. "the password, echoing and the generation of signals by special\n"
  1809. "characters is disabled.")
  1810. #define FUNC_NAME s_scm_getpass
  1811. {
  1812. char * p;
  1813. SCM passwd;
  1814. SCM_VALIDATE_STRING (1, prompt);
  1815. WITH_STRING (prompt, c_prompt,
  1816. p = getpass(c_prompt));
  1817. passwd = scm_from_locale_string (p);
  1818. /* Clear out the password in the static buffer. */
  1819. memset (p, 0, strlen (p));
  1820. return passwd;
  1821. }
  1822. #undef FUNC_NAME
  1823. #endif /* HAVE_GETPASS */
  1824. SCM_DEFINE (scm_flock, "flock", 2, 0, 0,
  1825. (SCM file, SCM operation),
  1826. "Apply or remove an advisory lock on an open file.\n"
  1827. "@var{operation} specifies the action to be done:\n"
  1828. "\n"
  1829. "@defvar LOCK_SH\n"
  1830. "Shared lock. More than one process may hold a shared lock\n"
  1831. "for a given file at a given time.\n"
  1832. "@end defvar\n"
  1833. "@defvar LOCK_EX\n"
  1834. "Exclusive lock. Only one process may hold an exclusive lock\n"
  1835. "for a given file at a given time.\n"
  1836. "@end defvar\n"
  1837. "@defvar LOCK_UN\n"
  1838. "Unlock the file.\n"
  1839. "@end defvar\n"
  1840. "@defvar LOCK_NB\n"
  1841. "Don't block when locking. This is combined with one of the\n"
  1842. "other operations using @code{logior}. If @code{flock} would\n"
  1843. "block an @code{EWOULDBLOCK} error is thrown.\n"
  1844. "@end defvar\n"
  1845. "\n"
  1846. "The return value is not specified. @var{file} may be an open\n"
  1847. "file descriptor or an open file descriptor port.\n"
  1848. "\n"
  1849. "Note that @code{flock} does not lock files across NFS.")
  1850. #define FUNC_NAME s_scm_flock
  1851. {
  1852. int fdes;
  1853. if (scm_is_integer (file))
  1854. fdes = scm_to_int (file);
  1855. else
  1856. {
  1857. SCM_VALIDATE_OPFPORT (2, file);
  1858. fdes = SCM_FPORT_FDES (file);
  1859. }
  1860. if (flock (fdes, scm_to_int (operation)) == -1)
  1861. SCM_SYSERROR;
  1862. return SCM_UNSPECIFIED;
  1863. }
  1864. #undef FUNC_NAME
  1865. #if HAVE_SETHOSTNAME
  1866. SCM_DEFINE (scm_sethostname, "sethostname", 1, 0, 0,
  1867. (SCM name),
  1868. "Set the host name of the current processor to @var{name}. May\n"
  1869. "only be used by the superuser. The return value is not\n"
  1870. "specified.")
  1871. #define FUNC_NAME s_scm_sethostname
  1872. {
  1873. int rv;
  1874. WITH_STRING (name, c_name,
  1875. rv = sethostname (c_name, strlen(c_name)));
  1876. if (rv == -1)
  1877. SCM_SYSERROR;
  1878. return SCM_UNSPECIFIED;
  1879. }
  1880. #undef FUNC_NAME
  1881. #endif /* HAVE_SETHOSTNAME */
  1882. #if HAVE_GETHOSTNAME
  1883. SCM_DEFINE (scm_gethostname, "gethostname", 0, 0, 0,
  1884. (void),
  1885. "Return the host name of the current processor.")
  1886. #define FUNC_NAME s_scm_gethostname
  1887. {
  1888. #ifdef MAXHOSTNAMELEN
  1889. /* Various systems define MAXHOSTNAMELEN (including Solaris in fact).
  1890. * On GNU/Linux this doesn't include the terminating '\0', hence "+ 1". */
  1891. const int len = MAXHOSTNAMELEN + 1;
  1892. char *const p = scm_malloc (len);
  1893. const int res = gethostname (p, len);
  1894. scm_dynwind_begin (0);
  1895. scm_dynwind_unwind_handler (free, p, 0);
  1896. #else
  1897. /* Default 256 is for Solaris, under Linux ENAMETOOLONG is returned if not
  1898. * large enough. SUSv2 specifies 255 maximum too, apparently. */
  1899. int len = 256;
  1900. int res;
  1901. char *p;
  1902. # if HAVE_SYSCONF && defined (_SC_HOST_NAME_MAX)
  1903. /* POSIX specifies the HOST_NAME_MAX system parameter for the max size,
  1904. * which may reflect a particular kernel configuration.
  1905. * Must watch out for this existing but giving -1, as happens for instance
  1906. * in gnu/linux glibc 2.3.2. */
  1907. {
  1908. const long int n = sysconf (_SC_HOST_NAME_MAX);
  1909. if (n != -1L)
  1910. len = n;
  1911. }
  1912. # endif
  1913. p = scm_malloc (len);
  1914. scm_dynwind_begin (0);
  1915. scm_dynwind_unwind_handler (free, p, 0);
  1916. res = gethostname (p, len);
  1917. while (res == -1 && errno == ENAMETOOLONG)
  1918. {
  1919. len *= 2;
  1920. /* scm_realloc may throw an exception. */
  1921. p = scm_realloc (p, len);
  1922. res = gethostname (p, len);
  1923. }
  1924. #endif
  1925. if (res == -1)
  1926. {
  1927. const int save_errno = errno;
  1928. /* No guile exceptions can occur before we have freed p's memory. */
  1929. scm_dynwind_end ();
  1930. free (p);
  1931. errno = save_errno;
  1932. SCM_SYSERROR;
  1933. }
  1934. else
  1935. {
  1936. /* scm_from_locale_string may throw an exception. */
  1937. const SCM name = scm_from_locale_string (p);
  1938. /* No guile exceptions can occur before we have freed p's memory. */
  1939. scm_dynwind_end ();
  1940. free (p);
  1941. return name;
  1942. }
  1943. }
  1944. #undef FUNC_NAME
  1945. #endif /* HAVE_GETHOSTNAME */
  1946. #ifdef HAVE_FORK
  1947. static void
  1948. scm_init_popen (void)
  1949. {
  1950. scm_c_define_gsubr ("open-process", 2, 0, 1, scm_open_process);
  1951. }
  1952. #endif
  1953. void
  1954. scm_init_posix ()
  1955. {
  1956. scm_add_feature ("posix");
  1957. #ifdef HAVE_GETEUID
  1958. scm_add_feature ("EIDs");
  1959. #endif
  1960. #ifdef WAIT_ANY
  1961. scm_c_define ("WAIT_ANY", scm_from_int (WAIT_ANY));
  1962. #endif
  1963. #ifdef WAIT_MYPGRP
  1964. scm_c_define ("WAIT_MYPGRP", scm_from_int (WAIT_MYPGRP));
  1965. #endif
  1966. #ifdef WNOHANG
  1967. scm_c_define ("WNOHANG", scm_from_int (WNOHANG));
  1968. #endif
  1969. #ifdef WUNTRACED
  1970. scm_c_define ("WUNTRACED", scm_from_int (WUNTRACED));
  1971. #endif
  1972. #ifdef LC_COLLATE
  1973. scm_c_define ("LC_COLLATE", scm_from_int (LC_COLLATE));
  1974. #endif
  1975. #ifdef LC_CTYPE
  1976. scm_c_define ("LC_CTYPE", scm_from_int (LC_CTYPE));
  1977. #endif
  1978. #ifdef LC_MONETARY
  1979. scm_c_define ("LC_MONETARY", scm_from_int (LC_MONETARY));
  1980. #endif
  1981. #ifdef LC_NUMERIC
  1982. scm_c_define ("LC_NUMERIC", scm_from_int (LC_NUMERIC));
  1983. #endif
  1984. #ifdef LC_TIME
  1985. scm_c_define ("LC_TIME", scm_from_int (LC_TIME));
  1986. #endif
  1987. #ifdef LC_MESSAGES
  1988. scm_c_define ("LC_MESSAGES", scm_from_int (LC_MESSAGES));
  1989. #endif
  1990. #ifdef LC_ALL
  1991. scm_c_define ("LC_ALL", scm_from_int (LC_ALL));
  1992. #endif
  1993. #ifdef LC_PAPER
  1994. scm_c_define ("LC_PAPER", scm_from_int (LC_PAPER));
  1995. #endif
  1996. #ifdef LC_NAME
  1997. scm_c_define ("LC_NAME", scm_from_int (LC_NAME));
  1998. #endif
  1999. #ifdef LC_ADDRESS
  2000. scm_c_define ("LC_ADDRESS", scm_from_int (LC_ADDRESS));
  2001. #endif
  2002. #ifdef LC_TELEPHONE
  2003. scm_c_define ("LC_TELEPHONE", scm_from_int (LC_TELEPHONE));
  2004. #endif
  2005. #ifdef LC_MEASUREMENT
  2006. scm_c_define ("LC_MEASUREMENT", scm_from_int (LC_MEASUREMENT));
  2007. #endif
  2008. #ifdef LC_IDENTIFICATION
  2009. scm_c_define ("LC_IDENTIFICATION", scm_from_int (LC_IDENTIFICATION));
  2010. #endif
  2011. #ifdef PIPE_BUF
  2012. scm_c_define ("PIPE_BUF", scm_from_long (PIPE_BUF));
  2013. #endif
  2014. #ifdef PRIO_PROCESS
  2015. scm_c_define ("PRIO_PROCESS", scm_from_int (PRIO_PROCESS));
  2016. #endif
  2017. #ifdef PRIO_PGRP
  2018. scm_c_define ("PRIO_PGRP", scm_from_int (PRIO_PGRP));
  2019. #endif
  2020. #ifdef PRIO_USER
  2021. scm_c_define ("PRIO_USER", scm_from_int (PRIO_USER));
  2022. #endif
  2023. #ifdef LOCK_SH
  2024. scm_c_define ("LOCK_SH", scm_from_int (LOCK_SH));
  2025. #endif
  2026. #ifdef LOCK_EX
  2027. scm_c_define ("LOCK_EX", scm_from_int (LOCK_EX));
  2028. #endif
  2029. #ifdef LOCK_UN
  2030. scm_c_define ("LOCK_UN", scm_from_int (LOCK_UN));
  2031. #endif
  2032. #ifdef LOCK_NB
  2033. scm_c_define ("LOCK_NB", scm_from_int (LOCK_NB));
  2034. #endif
  2035. #include "libguile/cpp-SIG.c"
  2036. #include "libguile/posix.x"
  2037. #ifdef HAVE_FORK
  2038. scm_add_feature ("fork");
  2039. scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
  2040. "scm_init_popen",
  2041. (scm_t_extension_init_func) scm_init_popen,
  2042. NULL);
  2043. #endif /* HAVE_FORK */
  2044. }
  2045. /*
  2046. Local Variables:
  2047. c-file-style: "gnu"
  2048. End:
  2049. */