$search
00001 /* 00002 * lposix.c 00003 * POSIX library for Lua 5.1. 00004 * Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> 00005 * 07 Apr 2006 23:17:49 00006 * Clean up and bug fixes by Leo Razoumov <slonik.az@gmail.com> 2006-10-11 <!LR> 00007 * Based on original by Claudio Terra for Lua 3.x. 00008 * With contributions by Roberto Ierusalimschy. 00009 */ 00010 00011 #include <sys/stat.h> 00012 #include <sys/times.h> 00013 #include <sys/types.h> 00014 #include <sys/utsname.h> 00015 #include <sys/wait.h> 00016 #include <sys/resource.h> 00017 #include <sys/time.h> 00018 00019 #include <dirent.h> 00020 #include <errno.h> 00021 #include <fcntl.h> 00022 #include <glob.h> 00023 #include <grp.h> 00024 #include <libgen.h> 00025 #include <limits.h> 00026 #include <poll.h> 00027 #include <pwd.h> 00028 #include <signal.h> 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #include <string.h> 00032 #include <syslog.h> 00033 #include <time.h> 00034 #include <unistd.h> 00035 #include <utime.h> 00036 00037 #ifndef VERSION 00038 # define VERSION "unknown" 00039 #endif 00040 00041 #define MYNAME "posix" 00042 #define MYVERSION MYNAME " library for " LUA_VERSION " / " VERSION 00043 00044 #ifndef ENABLE_SYSLOG 00045 #define ENABLE_SYSLOG 1 00046 #endif 00047 00048 #include "lua.h" 00049 #include "lualib.h" 00050 #include "lauxlib.h" 00051 00052 #include "modemuncher.c" 00053 00054 /* compatibility with Lua 5.0 */ 00055 #ifndef LUA_VERSION_NUM 00056 static int luaL_checkoption (lua_State *L, int narg, const char *def, 00057 const char *const lst[]) { 00058 const char *name = (def) ? luaL_optstring(L, narg, def) : 00059 luaL_checkstring(L, narg); 00060 int i = luaL_findstring(name, lst); 00061 if (i == -1) 00062 luaL_argerror(L, narg, lua_pushfstring(L, "invalid option '%s'", name)); 00063 return i; 00064 } 00065 #define lua_pushinteger lua_pushnumber 00066 #define lua_createtable(L,a,r) lua_newtable(L) 00067 #define LUA_FILEHANDLE "FILE*" 00068 00069 #define lua_setfield(l,i,k) 00070 #define lua_getfield(l,i,k) 00071 00072 #endif 00073 00074 static const struct { char c; mode_t b; } M[] = 00075 { 00076 {'r', S_IRUSR}, {'w', S_IWUSR}, {'x', S_IXUSR}, 00077 {'r', S_IRGRP}, {'w', S_IWGRP}, {'x', S_IXGRP}, 00078 {'r', S_IROTH}, {'w', S_IWOTH}, {'x', S_IXOTH}, 00079 }; 00080 00081 00082 static void pushmode(lua_State *L, mode_t mode) 00083 { 00084 char m[9]; 00085 int i; 00086 for (i=0; i<9; i++) m[i]= (mode & M[i].b) ? M[i].c : '-'; 00087 if (mode & S_ISUID) m[2]= (mode & S_IXUSR) ? 's' : 'S'; 00088 if (mode & S_ISGID) m[5]= (mode & S_IXGRP) ? 's' : 'S'; 00089 lua_pushlstring(L, m, 9); 00090 } 00091 00092 typedef void (*Selector)(lua_State *L, int i, const void *data); 00093 00094 static int doselection(lua_State *L, int i, int n, 00095 const char *const S[], 00096 Selector F, 00097 const void *data) 00098 { 00099 if (lua_isnone(L, i) || lua_istable(L, i)) 00100 { 00101 int j; 00102 if (lua_isnone(L, i)) lua_createtable(L,0,n); else lua_settop(L, i); 00103 for (j=0; S[j]!=NULL; j++) 00104 { 00105 lua_pushstring(L, S[j]); 00106 F(L, j, data); 00107 lua_settable(L, -3); 00108 } 00109 return 1; 00110 } 00111 else 00112 { 00113 int k,n=lua_gettop(L); 00114 for (k=i; k<=n; k++) 00115 { 00116 int j=luaL_checkoption(L, k, NULL, S); 00117 F(L, j, data); 00118 lua_replace(L, k); 00119 } 00120 return n-i+1; 00121 } 00122 } 00123 #define doselection(L,i,S,F,d) (doselection)(L,i,sizeof(S)/sizeof(*S)-1,S,F,d) 00124 00125 static int pusherror(lua_State *L, const char *info) 00126 { 00127 lua_pushnil(L); 00128 if (info==NULL) 00129 lua_pushstring(L, strerror(errno)); 00130 else 00131 lua_pushfstring(L, "%s: %s", info, strerror(errno)); 00132 lua_pushinteger(L, errno); 00133 return 3; 00134 } 00135 00136 static int pushresult(lua_State *L, int i, const char *info) 00137 { 00138 if (i==-1) return pusherror(L, info); 00139 lua_pushinteger(L, i); 00140 return 1; 00141 } 00142 00143 static void badoption(lua_State *L, int i, const char *what, int option) 00144 { 00145 luaL_argerror(L, 2, 00146 lua_pushfstring(L, "unknown %s option '%c'", what, option)); 00147 } 00148 00149 static uid_t mygetuid(lua_State *L, int i) 00150 { 00151 if (lua_isnone(L, i)) 00152 return -1; 00153 else if (lua_isnumber(L, i)) 00154 return (uid_t) lua_tonumber(L, i); 00155 else if (lua_isstring(L, i)) 00156 { 00157 struct passwd *p=getpwnam(lua_tostring(L, i)); 00158 return (p==NULL) ? (uid_t)-1 : p->pw_uid; 00159 } 00160 else 00161 return luaL_typerror(L, i, "string or number"); 00162 } 00163 00164 static gid_t mygetgid(lua_State *L, int i) 00165 { 00166 if (lua_isnone(L, i)) 00167 return -1; 00168 else if (lua_isnumber(L, i)) 00169 return (gid_t) lua_tonumber(L, i); 00170 else if (lua_isstring(L, i)) 00171 { 00172 struct group *g=getgrnam(lua_tostring(L, i)); 00173 return (g==NULL) ? (uid_t)-1 : g->gr_gid; 00174 } 00175 else 00176 return luaL_typerror(L, i, "string or number"); 00177 } 00178 00179 00180 static int Perrno(lua_State *L) 00181 { 00182 int n = luaL_optint(L, 1, errno); 00183 lua_pushstring(L, strerror(n)); 00184 lua_pushinteger(L, n); 00185 return 2; 00186 } 00187 00188 00189 static int Pbasename(lua_State *L) 00190 { 00191 char b[PATH_MAX]; 00192 size_t len; 00193 const char *path = luaL_checklstring(L, 1, &len); 00194 if (len>=sizeof(b)) luaL_argerror(L, 1, "too long"); 00195 lua_pushstring(L, basename(strcpy(b,path))); 00196 return 1; 00197 } 00198 00199 00200 static int Pdirname(lua_State *L) 00201 { 00202 char b[PATH_MAX]; 00203 size_t len; 00204 const char *path = luaL_checklstring(L, 1, &len); 00205 if (len>=sizeof(b)) luaL_argerror(L, 1, "too long"); 00206 lua_pushstring(L, dirname(strcpy(b,path))); 00207 return 1; 00208 } 00209 00210 00211 static int Pdir(lua_State *L) 00212 { 00213 const char *path = luaL_optstring(L, 1, "."); 00214 DIR *d = opendir(path); 00215 if (d == NULL) 00216 return pusherror(L, path); 00217 else 00218 { 00219 int i; 00220 struct dirent *entry; 00221 lua_newtable(L); 00222 for (i=1; (entry = readdir(d)) != NULL; i++) 00223 { 00224 lua_pushstring(L, entry->d_name); 00225 lua_rawseti(L, -2, i); 00226 } 00227 closedir(d); 00228 lua_pushinteger(L, i-1); 00229 return 2; 00230 } 00231 } 00232 00233 static int Pglob(lua_State *L) 00234 { 00235 const char *pattern = luaL_optstring(L, 1, "*"); 00236 glob_t globres; 00237 00238 if (glob(pattern, 0, NULL, &globres)) 00239 return pusherror(L, pattern); 00240 else 00241 { 00242 unsigned int i; 00243 lua_newtable(L); 00244 for (i=1; i<=globres.gl_pathc; i++) { 00245 lua_pushstring(L, globres.gl_pathv[i-1]); 00246 lua_rawseti(L, -2, i); 00247 } 00248 globfree(&globres); 00249 return 1; 00250 } 00251 } 00252 00253 static int aux_files(lua_State *L) 00254 { 00255 DIR **p = (DIR **)lua_touserdata(L, lua_upvalueindex(1)); 00256 DIR *d = *p; 00257 struct dirent *entry; 00258 if (d == NULL) return 0; 00259 entry = readdir(d); 00260 if (entry == NULL) 00261 { 00262 closedir(d); 00263 *p=NULL; 00264 return 0; 00265 } 00266 else 00267 { 00268 lua_pushstring(L, entry->d_name); 00269 return 1; 00270 } 00271 } 00272 00273 static int dir_gc (lua_State *L) 00274 { 00275 DIR *d = *(DIR **)lua_touserdata(L, 1); 00276 if (d!=NULL) closedir(d); 00277 return 0; 00278 } 00279 00280 static int Pfiles(lua_State *L) 00281 { 00282 const char *path = luaL_optstring(L, 1, "."); 00283 DIR **d = (DIR **)lua_newuserdata(L, sizeof(DIR *)); 00284 if (luaL_newmetatable(L, MYNAME " dir handle")) 00285 { 00286 lua_pushliteral(L, "__gc"); 00287 lua_pushcfunction(L, dir_gc); 00288 lua_settable(L, -3); 00289 } 00290 lua_setmetatable(L, -2); 00291 *d = opendir(path); 00292 if (*d == NULL) return pusherror(L, path); 00293 lua_pushcclosure(L, aux_files, 1); 00294 return 1; 00295 } 00296 00297 00298 static int Pgetcwd(lua_State *L) 00299 { 00300 char b[PATH_MAX]; 00301 if (getcwd(b, sizeof(b)) == NULL) return pusherror(L, "."); 00302 lua_pushstring(L, b); 00303 return 1; 00304 } 00305 00306 00307 static int Pmkdir(lua_State *L) 00308 { 00309 const char *path = luaL_checkstring(L, 1); 00310 return pushresult(L, mkdir(path, 0777), path); 00311 } 00312 00313 00314 static int Pchdir(lua_State *L) 00315 { 00316 const char *path = luaL_checkstring(L, 1); 00317 return pushresult(L, chdir(path), path); 00318 } 00319 00320 static int Prmdir(lua_State *L) 00321 { 00322 const char *path = luaL_checkstring(L, 1); 00323 return pushresult(L, rmdir(path), path); 00324 } 00325 00326 00327 static int Punlink(lua_State *L) 00328 { 00329 const char *path = luaL_checkstring(L, 1); 00330 return pushresult(L, unlink(path), path); 00331 } 00332 00333 static int Plink(lua_State *L) 00334 { 00335 const char *oldpath = luaL_checkstring(L, 1); 00336 const char *newpath = luaL_checkstring(L, 2); 00337 return pushresult(L, 00338 (lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL); 00339 } 00340 00341 00342 static int Preadlink(lua_State *L) 00343 { 00344 char b[PATH_MAX]; 00345 const char *path = luaL_checkstring(L, 1); 00346 int n = readlink(path, b, sizeof(b)); 00347 if (n==-1) return pusherror(L, path); 00348 lua_pushlstring(L, b, n); 00349 return 1; 00350 } 00351 00352 00353 static int Paccess(lua_State *L) 00354 { 00355 int mode=F_OK; 00356 const char *path=luaL_checkstring(L, 1); 00357 const char *s; 00358 for (s=luaL_optstring(L, 2, "f"); *s!=0 ; s++) 00359 switch (*s) 00360 { 00361 case ' ': break; 00362 case 'r': mode |= R_OK; break; 00363 case 'w': mode |= W_OK; break; 00364 case 'x': mode |= X_OK; break; 00365 case 'f': mode |= F_OK; break; 00366 default: badoption(L, 2, "mode", *s); break; 00367 } 00368 return pushresult(L, access(path, mode), path); 00369 } 00370 00371 00372 static int myfclose (lua_State *L) { 00373 FILE **p = (FILE **)lua_touserdata(L, 1); 00374 int rc = fclose(*p); 00375 if (rc == 0) *p = NULL; 00376 return pushresult(L, rc, NULL); 00377 } 00378 00379 static int pushfile (lua_State *L, int id, const char *mode) { 00380 FILE **f = (FILE **)lua_newuserdata(L, sizeof(FILE *)); 00381 *f = NULL; 00382 luaL_getmetatable(L, LUA_FILEHANDLE); 00383 lua_setmetatable(L, -2); 00384 lua_getfield(L, LUA_REGISTRYINDEX, "POSIX_PIPEFILE"); 00385 if (lua_isnil(L, -1)) { 00386 lua_pop(L, 1); 00387 lua_newtable(L); 00388 lua_pushvalue(L, -1); 00389 lua_pushcfunction(L, myfclose); 00390 lua_setfield(L, -2, "__close"); 00391 lua_setfield(L, LUA_REGISTRYINDEX, "POSIX_PIPEFILE"); 00392 } 00393 lua_setfenv(L, -2); 00394 *f = fdopen(id, mode); 00395 return (*f != NULL); 00396 } 00397 00398 static int Ppipe(lua_State *L) 00399 { 00400 int fd[2]; 00401 if (pipe(fd)==-1) return pusherror(L, NULL); 00402 if (!pushfile(L, fd[0], "r") || !pushfile(L, fd[1], "w")) 00403 return pusherror(L, "pipe"); 00404 return 2; 00405 } 00406 00407 00408 static int Pfileno(lua_State *L) 00409 { 00410 FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); 00411 return pushresult(L, fileno(f), NULL); 00412 } 00413 00414 00415 static int Pfdopen(lua_State *L) 00416 { 00417 int fd = luaL_checkint(L, 1); 00418 const char *mode = luaL_checkstring(L, 2); 00419 if (!pushfile(L, fd, mode)) 00420 return pusherror(L, "fdpoen"); 00421 return 1; 00422 } 00423 00424 00425 /* helper func for Pdup */ 00426 static const char *filemode(int fd) 00427 { 00428 const char *m; 00429 int mode = fcntl(fd, F_GETFL); 00430 if (mode < 0) 00431 return NULL; 00432 switch (mode & O_ACCMODE) { 00433 case O_RDONLY: m = "r"; break; 00434 case O_WRONLY: m = "w"; break; 00435 default: m = "rw"; break; 00436 } 00437 return m; 00438 } 00439 00440 static int Pdup(lua_State *L) 00441 { 00442 FILE **oldf = (FILE**)luaL_checkudata(L, 1, LUA_FILEHANDLE); 00443 FILE **newf = (FILE **)lua_touserdata(L, 2); 00444 int fd; 00445 const char *msg = "dup2"; 00446 fflush(*newf); 00447 if (newf == NULL) { 00448 fd = dup(fileno(*oldf)); 00449 msg = "dup"; 00450 } else { 00451 fflush(*newf); 00452 fd = dup2(fileno(*oldf), fileno(*newf)); 00453 } 00454 00455 if ((fd < 0) || !pushfile(L, fd, filemode(fd))) 00456 return pusherror(L, msg); 00457 return 1; 00458 } 00459 00460 00461 static int Pmkfifo(lua_State *L) 00462 { 00463 const char *path = luaL_checkstring(L, 1); 00464 return pushresult(L, mkfifo(path, 0777), path); 00465 } 00466 00467 00468 static int runexec(lua_State *L, int use_shell) 00469 { 00470 const char *path = luaL_checkstring(L, 1); 00471 int i,n=lua_gettop(L); 00472 char **argv = lua_newuserdata(L,(n+1)*sizeof(char*)); 00473 argv[0] = (char*)path; 00474 for (i=1; i<n; i++) argv[i] = (char*)luaL_checkstring(L, i+1); 00475 argv[n] = NULL; 00476 if (use_shell) { 00477 execvp(path, argv); 00478 } else { 00479 execv(path, argv); 00480 } 00481 return pusherror(L, path); 00482 } 00483 00484 00485 static int Pexec(lua_State *L) 00486 { 00487 return runexec(L, 0); 00488 } 00489 00490 00491 static int Pexecp(lua_State *L) 00492 { 00493 return runexec(L, 1); 00494 } 00495 00496 00497 static int Pfork(lua_State *L) 00498 { 00499 return pushresult(L, fork(), NULL); 00500 } 00501 00502 /* from http://lua-users.org/lists/lua-l/2007-11/msg00346.html */ 00503 static int Ppoll(lua_State *L) 00504 { 00505 struct pollfd fds; 00506 FILE* file = *(FILE**)luaL_checkudata(L,1,LUA_FILEHANDLE); 00507 int timeout = luaL_checkint(L,2); 00508 fds.fd = fileno(file); 00509 fds.events = POLLIN; 00510 return pushresult(L, poll(&fds,1,timeout), NULL); 00511 } 00512 00513 static int Pwait(lua_State *L) 00514 { 00515 int status; 00516 pid_t pid = luaL_optint(L, 1, -1); 00517 pid = waitpid(pid, &status, 0); 00518 if (pid == -1) return pusherror(L, NULL); 00519 lua_pushinteger(L, pid); 00520 if (WIFEXITED(status)) 00521 { 00522 lua_pushliteral(L,"exited"); 00523 lua_pushinteger(L, WEXITSTATUS(status)); 00524 return 3; 00525 } 00526 else if (WIFSIGNALED(status)) 00527 { 00528 lua_pushliteral(L,"killed"); 00529 lua_pushinteger(L, WTERMSIG(status)); 00530 return 3; 00531 } 00532 else if (WIFSTOPPED(status)) 00533 { 00534 lua_pushliteral(L,"stopped"); 00535 lua_pushinteger(L, WSTOPSIG(status)); 00536 return 3; 00537 } 00538 return 1; 00539 } 00540 00541 00542 static int Pkill(lua_State *L) 00543 { 00544 pid_t pid = luaL_checkint(L, 1); 00545 int sig = luaL_optint(L, 2, SIGTERM); 00546 return pushresult(L, kill(pid, sig), NULL); 00547 } 00548 00549 static int Psetpid(lua_State *L) 00550 { 00551 const char *what=luaL_checkstring(L, 1); 00552 switch (*what) 00553 { 00554 case 'U': 00555 return pushresult(L, seteuid(mygetuid(L, 2)), NULL); 00556 case 'u': 00557 return pushresult(L, setuid(mygetuid(L, 2)), NULL); 00558 case 'G': 00559 return pushresult(L, setegid(mygetgid(L, 2)), NULL); 00560 case 'g': 00561 return pushresult(L, setgid(mygetgid(L, 2)), NULL); 00562 case 's': 00563 return pushresult(L, setsid(), NULL); 00564 case 'p': 00565 { 00566 pid_t pid = luaL_checkint(L, 2); 00567 pid_t pgid = luaL_checkint(L, 3); 00568 return pushresult(L, setpgid(pid,pgid), NULL); 00569 } 00570 default: 00571 badoption(L, 2, "id", *what); 00572 return 0; 00573 } 00574 } 00575 00576 00577 static int Psleep(lua_State *L) 00578 { 00579 unsigned int seconds = luaL_checkint(L, 1); 00580 lua_pushinteger(L, sleep(seconds)); 00581 return 1; 00582 } 00583 00584 00585 static int Psetenv(lua_State *L) 00586 { 00587 const char *name=luaL_checkstring(L, 1); 00588 const char *value=luaL_optstring(L, 2, NULL); 00589 if (value==NULL) 00590 { 00591 unsetenv(name); 00592 return pushresult(L, 0, NULL); 00593 } 00594 else 00595 { 00596 int overwrite=lua_isnoneornil(L, 3) || lua_toboolean(L, 3); 00597 return pushresult(L, setenv(name,value,overwrite), NULL); 00598 } 00599 } 00600 00601 00602 static int Pgetenv(lua_State *L) 00603 { 00604 if (lua_isnone(L, 1)) 00605 { 00606 extern char **environ; 00607 char **e; 00608 lua_newtable(L); 00609 for (e=environ; *e!=NULL; e++) 00610 { 00611 char *s=*e; 00612 char *eq=strchr(s, '='); 00613 if (eq==NULL) /* will this ever happen? */ 00614 { 00615 lua_pushstring(L,s); 00616 lua_pushboolean(L,1); 00617 } 00618 else 00619 { 00620 lua_pushlstring(L,s,eq-s); 00621 lua_pushstring(L,eq+1); 00622 } 00623 lua_settable(L,-3); 00624 } 00625 } 00626 else 00627 lua_pushstring(L, getenv(luaL_checkstring(L, 1))); 00628 return 1; 00629 } 00630 00631 static int Pumask(lua_State *L) 00632 {/* <!LR> from old lposix-5.0 version */ 00633 char m[10]; 00634 mode_t mode; 00635 umask(mode=umask(0)); 00636 mode=(~mode)&0777; 00637 if (!lua_isnone(L, 1)) 00638 { 00639 if (mode_munch(&mode, luaL_checkstring(L, 1))) 00640 { 00641 lua_pushnil(L); 00642 return 1; 00643 } 00644 mode&=0777; 00645 umask(~mode); 00646 } 00647 modechopper(mode, m); 00648 lua_pushstring(L, m); 00649 return 1; 00650 } 00651 00652 00653 static int Pchmod(lua_State *L) 00654 { 00655 mode_t mode; 00656 struct stat s; 00657 const char *path = luaL_checkstring(L, 1); 00658 const char *modestr = luaL_checkstring(L, 2); 00659 if (stat(path, &s)) return pusherror(L, path); 00660 mode = s.st_mode; 00661 if (mode_munch(&mode, modestr)) luaL_argerror(L, 2, "bad mode"); 00662 return pushresult(L, chmod(path, mode), path); 00663 } 00664 00665 00666 static int Pchown(lua_State *L) 00667 { 00668 const char *path = luaL_checkstring(L, 1); 00669 uid_t uid = mygetuid(L, 2); 00670 gid_t gid = mygetgid(L, 3); 00671 return pushresult(L, chown(path, uid, gid), path); 00672 } 00673 00674 00675 static int Putime(lua_State *L) 00676 { 00677 struct utimbuf times; 00678 time_t currtime = time(NULL); 00679 const char *path = luaL_checkstring(L, 1); 00680 times.modtime = luaL_optnumber(L, 2, currtime); 00681 times.actime = luaL_optnumber(L, 3, currtime); 00682 return pushresult(L, utime(path, ×), path); 00683 } 00684 00685 00686 static void FgetID(lua_State *L, int i, const void *data) 00687 { 00688 switch (i) 00689 { 00690 case 0: lua_pushinteger(L, getegid()); break; 00691 case 1: lua_pushinteger(L, geteuid()); break; 00692 case 2: lua_pushinteger(L, getgid()); break; 00693 case 3: lua_pushinteger(L, getuid()); break; 00694 case 4: lua_pushinteger(L, getpgrp()); break; 00695 case 5: lua_pushinteger(L, getpid()); break; 00696 case 6: lua_pushinteger(L, getppid()); break; 00697 } 00698 } 00699 00700 static const char *const SgetID[] = 00701 { 00702 "egid", "euid", "gid", "uid", "pgrp", "pid", "ppid", NULL 00703 }; 00704 00705 static int Pgetpid(lua_State *L) 00706 { 00707 return doselection(L, 1, SgetID, FgetID, NULL); 00708 } 00709 00710 00711 static int Phostid(lua_State *L) 00712 { 00713 char b[32]; 00714 sprintf(b,"%ld",gethostid()); 00715 lua_pushstring(L, b); 00716 return 1; 00717 } 00718 00719 00720 static int Pttyname(lua_State *L) 00721 { 00722 int fd=luaL_optint(L, 1, 0); 00723 lua_pushstring(L, ttyname(fd)); 00724 return 1; 00725 } 00726 00727 00728 static int Pctermid(lua_State *L) 00729 { 00730 char b[L_ctermid]; 00731 lua_pushstring(L, ctermid(b)); 00732 return 1; 00733 } 00734 00735 00736 static int Pgetlogin(lua_State *L) 00737 { 00738 lua_pushstring(L, getlogin()); 00739 return 1; 00740 } 00741 00742 00743 static void Fgetpasswd(lua_State *L, int i, const void *data) 00744 { 00745 const struct passwd *p=data; 00746 switch (i) 00747 { 00748 case 0: lua_pushstring(L, p->pw_name); break; 00749 case 1: lua_pushinteger(L, p->pw_uid); break; 00750 case 2: lua_pushinteger(L, p->pw_gid); break; 00751 case 3: lua_pushstring(L, p->pw_dir); break; 00752 case 4: lua_pushstring(L, p->pw_shell); break; 00753 /* not strictly POSIX */ 00754 case 5: lua_pushstring(L, p->pw_gecos); break; 00755 case 6: lua_pushstring(L, p->pw_passwd); break; 00756 } 00757 } 00758 00759 static const char *const Sgetpasswd[] = 00760 { 00761 "name", "uid", "gid", "dir", "shell", "gecos", "passwd", NULL 00762 }; 00763 00764 00765 static int Pgetpasswd(lua_State *L) 00766 { 00767 struct passwd *p=NULL; 00768 if (lua_isnoneornil(L, 1)) 00769 p = getpwuid(geteuid()); 00770 else if (lua_isnumber(L, 1)) 00771 p = getpwuid((uid_t)lua_tonumber(L, 1)); 00772 else if (lua_isstring(L, 1)) 00773 p = getpwnam(lua_tostring(L, 1)); 00774 else 00775 luaL_typerror(L, 1, "string or number"); 00776 if (p==NULL) 00777 lua_pushnil(L); 00778 else 00779 return doselection(L, 2, Sgetpasswd, Fgetpasswd, p); 00780 return 1; 00781 } 00782 00783 00784 static int Pgetgroup(lua_State *L) 00785 { 00786 struct group *g=NULL; 00787 if (lua_isnumber(L, 1)) 00788 g = getgrgid((gid_t)lua_tonumber(L, 1)); 00789 else if (lua_isstring(L, 1)) 00790 g = getgrnam(lua_tostring(L, 1)); 00791 else 00792 luaL_typerror(L, 1, "string or number"); 00793 if (g==NULL) 00794 lua_pushnil(L); 00795 else 00796 { 00797 int i; 00798 lua_newtable(L); 00799 lua_pushliteral(L, "name"); 00800 lua_pushstring(L, g->gr_name); 00801 lua_settable(L, -3); 00802 lua_pushliteral(L, "gid"); 00803 lua_pushinteger(L, g->gr_gid); 00804 lua_settable(L, -3); 00805 for (i=0; g->gr_mem[i]!=NULL; i++) 00806 { 00807 lua_pushstring(L, g->gr_mem[i]); 00808 lua_rawseti(L, -2, i); 00809 } 00810 } 00811 return 1; 00812 } 00813 00814 00815 struct mytimes 00816 { 00817 struct tms t; 00818 clock_t elapsed; 00819 }; 00820 00821 /* #define pushtime(L,x) lua_pushnumber(L,((lua_Number)x)/CLOCKS_PER_SEC) */ 00822 #define pushtime(L,x) lua_pushnumber(L, ((lua_Number)x)/clk_tck) 00823 00824 static void Ftimes(lua_State *L, int i, const void *data) 00825 { 00826 static long clk_tck = 0; 00827 const struct mytimes *t=data; 00828 00829 if( !clk_tck){ clk_tck= sysconf(_SC_CLK_TCK);} 00830 switch (i) 00831 { 00832 case 0: pushtime(L, t->t.tms_utime); break; 00833 case 1: pushtime(L, t->t.tms_stime); break; 00834 case 2: pushtime(L, t->t.tms_cutime); break; 00835 case 3: pushtime(L, t->t.tms_cstime); break; 00836 case 4: pushtime(L, t->elapsed); break; 00837 } 00838 } 00839 00840 static const char *const Stimes[] = 00841 { 00842 "utime", "stime", "cutime", "cstime", "elapsed", NULL 00843 }; 00844 00845 static int Ptimes(lua_State *L) 00846 { 00847 struct mytimes t; 00848 t.elapsed = times(&t.t); 00849 return doselection(L, 1, Stimes, Ftimes, &t); 00850 } 00851 00852 00853 static const char *filetype(mode_t m) 00854 { 00855 if (S_ISREG(m)) return "regular"; 00856 else if (S_ISLNK(m)) return "link"; 00857 else if (S_ISDIR(m)) return "directory"; 00858 else if (S_ISCHR(m)) return "character device"; 00859 else if (S_ISBLK(m)) return "block device"; 00860 else if (S_ISFIFO(m)) return "fifo"; 00861 else if (S_ISSOCK(m)) return "socket"; 00862 else return "?"; 00863 } 00864 00865 static void Fstat(lua_State *L, int i, const void *data) 00866 { 00867 const struct stat *s=data; 00868 switch (i) 00869 { 00870 case 0: pushmode(L, s->st_mode); break; 00871 case 1: lua_pushinteger(L, s->st_ino); break; 00872 case 2: lua_pushinteger(L, s->st_dev); break; 00873 case 3: lua_pushinteger(L, s->st_nlink); break; 00874 case 4: lua_pushinteger(L, s->st_uid); break; 00875 case 5: lua_pushinteger(L, s->st_gid); break; 00876 case 6: lua_pushinteger(L, s->st_size); break; 00877 case 7: lua_pushinteger(L, s->st_atime); break; 00878 case 8: lua_pushinteger(L, s->st_mtime); break; 00879 case 9: lua_pushinteger(L, s->st_ctime); break; 00880 case 10:lua_pushstring(L, filetype(s->st_mode)); break; 00881 } 00882 } 00883 00884 static const char *const Sstat[] = 00885 { 00886 "mode", "ino", "dev", "nlink", "uid", "gid", 00887 "size", "atime", "mtime", "ctime", "type", 00888 NULL 00889 }; 00890 00891 static int Pstat(lua_State *L) 00892 { 00893 struct stat s; 00894 const char *path=luaL_checkstring(L, 1); 00895 if (lstat(path,&s)==-1) return pusherror(L, path); 00896 return doselection(L, 2, Sstat, Fstat, &s); 00897 } 00898 00899 00900 static int Puname(lua_State *L) 00901 { 00902 struct utsname u; 00903 luaL_Buffer b; 00904 const char *s; 00905 if (uname(&u)==-1) return pusherror(L, NULL); 00906 luaL_buffinit(L, &b); 00907 for (s=luaL_optstring(L, 1, "%s %n %r %v %m"); *s; s++) 00908 if (*s!='%') 00909 luaL_putchar(&b, *s); 00910 else switch (*++s) 00911 { 00912 case '%': luaL_putchar(&b, *s); break; 00913 case 'm': luaL_addstring(&b,u.machine); break; 00914 case 'n': luaL_addstring(&b,u.nodename); break; 00915 case 'r': luaL_addstring(&b,u.release); break; 00916 case 's': luaL_addstring(&b,u.sysname); break; 00917 case 'v': luaL_addstring(&b,u.version); break; 00918 default: badoption(L, 2, "format", *s); break; 00919 } 00920 luaL_pushresult(&b); 00921 return 1; 00922 } 00923 00924 00925 static const int Kpathconf[] = 00926 { 00927 _PC_LINK_MAX, _PC_MAX_CANON, _PC_MAX_INPUT, _PC_NAME_MAX, _PC_PATH_MAX, 00928 _PC_PIPE_BUF, _PC_CHOWN_RESTRICTED, _PC_NO_TRUNC, _PC_VDISABLE, 00929 -1 00930 }; 00931 00932 static void Fpathconf(lua_State *L, int i, const void *data) 00933 { 00934 const char *path=data; 00935 lua_pushinteger(L, pathconf(path, Kpathconf[i])); 00936 } 00937 00938 static const char *const Spathconf[] = 00939 { 00940 "link_max", "max_canon", "max_input", "name_max", "path_max", 00941 "pipe_buf", "chown_restricted", "no_trunc", "vdisable", 00942 NULL 00943 }; 00944 00945 static int Ppathconf(lua_State *L) 00946 { 00947 const char *path = luaL_optstring(L, 1, "."); 00948 return doselection(L, 2, Spathconf, Fpathconf, path); 00949 } 00950 00951 00952 static const int Ksysconf[] = 00953 { 00954 _SC_ARG_MAX, _SC_CHILD_MAX, _SC_CLK_TCK, _SC_NGROUPS_MAX, _SC_STREAM_MAX, 00955 _SC_TZNAME_MAX, _SC_OPEN_MAX, _SC_JOB_CONTROL, _SC_SAVED_IDS, _SC_VERSION, 00956 -1 00957 }; 00958 00959 static void Fsysconf(lua_State *L, int i, const void *data) 00960 { 00961 lua_pushinteger(L, sysconf(Ksysconf[i])); 00962 } 00963 00964 static const char *const Ssysconf[] = 00965 { 00966 "arg_max", "child_max", "clk_tck", "ngroups_max", "stream_max", 00967 "tzname_max", "open_max", "job_control", "saved_ids", "version", 00968 NULL 00969 }; 00970 00971 static int Psysconf(lua_State *L) 00972 { 00973 return doselection(L, 1, Ssysconf, Fsysconf, NULL); 00974 } 00975 00976 #if ENABLE_SYSLOG 00977 /* syslog funcs */ 00978 static int Popenlog(lua_State *L) 00979 { 00980 const char *ident = luaL_checkstring(L, 1); 00981 int option = 0; 00982 int facility = luaL_optint(L, 3, LOG_USER); 00983 const char *s = luaL_optstring(L, 2, ""); 00984 while (*s) { 00985 switch (*s) { 00986 case ' ': break; 00987 case 'c': option |= LOG_CONS; break; 00988 case 'n': option |= LOG_NDELAY; break; 00989 case 'e': option |= LOG_PERROR; break; 00990 case 'p': option |= LOG_PID; break; 00991 default: badoption(L, 2, "option", *s); break; 00992 } 00993 s++; 00994 } 00995 openlog(ident, option, facility); 00996 return 0; 00997 } 00998 00999 01000 static int Psyslog(lua_State *L) 01001 { 01002 int priority = luaL_checkint(L, 1); 01003 const char *msg = luaL_checkstring(L, 2); 01004 syslog(priority, "%s", msg); 01005 return 0; 01006 } 01007 01008 01009 static int Pcloselog(lua_State *L) 01010 { 01011 closelog(); 01012 return 0; 01013 } 01014 01015 static int Psetlogmask(lua_State* L) 01016 { 01017 int argno = lua_gettop(L); 01018 int mask = 0; 01019 int i; 01020 01021 for (i=1; i <= argno; i++){ 01022 mask |= LOG_MASK(luaL_checkint(L,i)); 01023 } 01024 01025 return pushresult(L, setlogmask(mask),"setlogmask"); 01026 } 01027 #endif 01028 01029 /* 01030 * XXX: GNU and BSD handle the forward declaration of crypt() in different 01031 * and annoying ways (especially GNU). Declare it here just to make sure 01032 * that it's there 01033 */ 01034 char *crypt(const char *, const char *); 01035 01036 static int Pcrypt(lua_State *L) 01037 { 01038 const char *str, *salt; 01039 char *res; 01040 01041 str = luaL_checkstring(L, 1); 01042 salt = luaL_checkstring(L, 2); 01043 if (strlen(salt) < 2) 01044 luaL_error(L, "not enough salt"); 01045 01046 res = crypt(str, salt); 01047 lua_pushstring(L, res); 01048 01049 return 1; 01050 } 01051 01052 /* Like POSIX's setrlimit()/getrlimit() API functions. 01053 * 01054 * Syntax: 01055 * posix.setrlimit(resource, softlimit, hardlimit) 01056 * 01057 * Any negative limit or nil will be replace with the current 01058 * limit by an additional call of getrlimit(). 01059 * 01060 * Valid resouces are: 01061 * "core", "cpu", "data", "fsize", "memlock", 01062 * "nofile", "nproc", "rss", "stack" 01063 * 01064 * Example usage: 01065 * posix.setrlimit("NOFILE", 1000, 2000) 01066 */ 01067 01068 static const int Krlimit[] = 01069 { 01070 RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_MEMLOCK, 01071 RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_STACK, 01072 -1 01073 }; 01074 01075 static const char *const Srlimit[] = 01076 { 01077 "core", "cpu", "data", "fsize", "memlock", 01078 "nofile", "nproc", "rss", "stack", 01079 NULL 01080 }; 01081 01082 static int get_rlimit_const(const char *str) 01083 { 01084 int i; 01085 for (i = 0; Srlimit[i] != NULL; i++) 01086 if (strcmp(Srlimit[i], str) == 0) 01087 return Krlimit[i]; 01088 return -1; 01089 } 01090 01091 static int Psetrlimit(lua_State *L) 01092 { 01093 int softlimit; 01094 int hardlimit; 01095 const char *rid_str; 01096 int rid = 0; 01097 struct rlimit lim; 01098 struct rlimit lim_current; 01099 int rc; 01100 01101 rid_str = luaL_checkstring(L, 1); 01102 softlimit = luaL_optint(L, 2, -1); 01103 hardlimit = luaL_optint(L, 3, -1); 01104 01105 if (softlimit < 0 || hardlimit < 0) { 01106 if ((rc = getrlimit(rid, &lim_current)) < 0) 01107 return pushresult(L, rc, "getrlimit"); 01108 } 01109 01110 if (softlimit < 0) lim.rlim_cur = lim_current.rlim_cur; 01111 else lim.rlim_cur = softlimit; 01112 if (hardlimit < 0) lim.rlim_max = lim_current.rlim_max; 01113 else lim.rlim_max = hardlimit; 01114 01115 return pushresult(L, setrlimit(rid, &lim), "setrlimit"); 01116 } 01117 01118 static int Pgetrlimit(lua_State *L) 01119 { 01120 struct rlimit lim; 01121 int rid, rc; 01122 const char *rid_str = luaL_checkstring(L, 1); 01123 rid = get_rlimit_const(rid_str); 01124 rc = getrlimit(rid, &lim); 01125 if (rc < 0) 01126 return pusherror(L, "getrlimit"); 01127 lua_pushnumber(L, lim.rlim_cur); 01128 lua_pushnumber(L, lim.rlim_max); 01129 return 2; 01130 } 01131 01132 static int Pgettimeofday(lua_State *L) 01133 { 01134 struct timeval tv; 01135 struct timezone tz; 01136 if (gettimeofday(&tv, &tz) == -1) 01137 return pusherror(L, "gettimeofday"); 01138 lua_pushnumber(L, tv.tv_sec); 01139 lua_pushnumber(L, tv.tv_usec); 01140 lua_pushnumber(L, tz.tz_minuteswest); 01141 lua_pushnumber(L, tz.tz_dsttime); 01142 return 4; 01143 } 01144 01145 static int Ptime(lua_State *L) 01146 { 01147 time_t t = time(NULL); 01148 if ((time_t)-1 == t) 01149 return pusherror(L, "time"); 01150 lua_pushnumber(L, t); 01151 return 1; 01152 } 01153 01154 static int Plocaltime(lua_State *L) 01155 { 01156 struct tm res; 01157 time_t t = luaL_optint(L, 1, time(NULL)); 01158 if (localtime_r(&t, &res) == NULL) 01159 return pusherror(L, "localtime"); 01160 lua_createtable(L, 0, 9); 01161 lua_pushnumber(L, res.tm_sec); 01162 lua_setfield(L, -2, "sec"); 01163 lua_pushnumber(L, res.tm_min); 01164 lua_setfield(L, -2, "min"); 01165 lua_pushnumber(L, res.tm_hour); 01166 lua_setfield(L, -2, "hour"); 01167 lua_pushnumber(L, res.tm_mday); 01168 lua_setfield(L, -2, "monthday"); 01169 lua_pushnumber(L, res.tm_mon + 1); 01170 lua_setfield(L, -2, "month"); 01171 lua_pushnumber(L, res.tm_year + 1900); 01172 lua_setfield(L, -2, "year"); 01173 lua_pushnumber(L, res.tm_wday); 01174 lua_setfield(L, -2, "weekday"); 01175 lua_pushnumber(L, res.tm_yday); 01176 lua_setfield(L, -2, "yearday"); 01177 lua_pushboolean(L, res.tm_isdst); 01178 lua_setfield(L, -2, "is_dst"); 01179 return 1; 01180 } 01181 01182 01183 static int Pgmtime(lua_State *L) 01184 { 01185 struct tm res; 01186 time_t t = luaL_optint(L, 1, time(NULL)); 01187 if (gmtime_r(&t, &res) == NULL) 01188 return pusherror(L, "localtime"); 01189 lua_createtable(L, 0, 9); 01190 lua_pushnumber(L, res.tm_sec); 01191 lua_setfield(L, -2, "sec"); 01192 lua_pushnumber(L, res.tm_min); 01193 lua_setfield(L, -2, "min"); 01194 lua_pushnumber(L, res.tm_hour); 01195 lua_setfield(L, -2, "hour"); 01196 lua_pushnumber(L, res.tm_mday); 01197 lua_setfield(L, -2, "monthday"); 01198 lua_pushnumber(L, res.tm_mon + 1); 01199 lua_setfield(L, -2, "month"); 01200 lua_pushnumber(L, res.tm_year + 1900); 01201 lua_setfield(L, -2, "year"); 01202 lua_pushnumber(L, res.tm_wday); 01203 lua_setfield(L, -2, "weekday"); 01204 lua_pushnumber(L, res.tm_yday); 01205 lua_setfield(L, -2, "yearday"); 01206 lua_pushboolean(L, res.tm_isdst); 01207 lua_setfield(L, -2, "is_dst"); 01208 return 1; 01209 } 01210 01211 static int get_clk_id_const(const char *str) 01212 { 01213 if (str == NULL) 01214 return CLOCK_REALTIME; 01215 else if (strcmp(str, "monotonic") == 0) 01216 return CLOCK_MONOTONIC; 01217 else if (strcmp(str, "process_cputime_id") == 0) 01218 return CLOCK_PROCESS_CPUTIME_ID; 01219 else if (strcmp(str, "thread_cputime_id") == 0) 01220 return CLOCK_THREAD_CPUTIME_ID; 01221 else 01222 return CLOCK_REALTIME; 01223 } 01224 01225 static int Pclock_getres(lua_State *L) 01226 { 01227 struct timespec res; 01228 const char *str = lua_tostring(L, 1); 01229 if (clock_getres(get_clk_id_const(str), &res) == -1) 01230 return pusherror(L, "clock_getres"); 01231 lua_pushnumber(L, res.tv_sec); 01232 lua_pushnumber(L, res.tv_nsec); 01233 return 2; 01234 } 01235 01236 static int Pclock_gettime(lua_State *L) 01237 { 01238 struct timespec res; 01239 const char *str = lua_tostring(L, 1); 01240 if (clock_gettime(get_clk_id_const(str), &res) == -1) 01241 return pusherror(L, "clock_gettime"); 01242 lua_pushnumber(L, res.tv_sec); 01243 lua_pushnumber(L, res.tv_nsec); 01244 return 2; 01245 } 01246 01247 static int Pstrftime(lua_State *L) 01248 { 01249 char tmp[256]; 01250 const char *format = luaL_checkstring(L, 1); 01251 01252 struct tm t; 01253 if (lua_istable(L, 2)) { 01254 lua_getfield(L, 2, "sec"); 01255 t.tm_sec = luaL_optint(L, -1, 0); 01256 lua_pop(L, 1); 01257 lua_getfield(L, 2, "min"); 01258 t.tm_min = luaL_optint(L, -1, 0); 01259 lua_pop(L, 1); 01260 lua_getfield(L, 2, "hour"); 01261 t.tm_hour = luaL_optint(L, -1, 0); 01262 lua_pop(L, 1); 01263 lua_getfield(L, 2, "monthday"); 01264 t.tm_mday = luaL_optint(L, -1, 0); 01265 lua_pop(L, 1); 01266 lua_getfield(L, 2, "month"); 01267 t.tm_mon = luaL_optint(L, -1, 0); 01268 lua_pop(L, 1); 01269 lua_getfield(L, 2, "year"); 01270 t.tm_year = luaL_optint(L, -1, 0); 01271 lua_pop(L, 1); 01272 lua_getfield(L, 2, "weekday"); 01273 t.tm_wday = luaL_optint(L, -1, 0); 01274 lua_pop(L, 1); 01275 lua_getfield(L, 2, "yearday"); 01276 t.tm_yday = luaL_optint(L, -1, 0); 01277 lua_pop(L, 1); 01278 lua_getfield(L, 2, "is_dst"); 01279 t.tm_isdst = lua_tointeger(L, -1); 01280 lua_pop(L, 1); 01281 } else { 01282 time_t now = time(NULL); 01283 localtime_r(&now, &t); 01284 } 01285 01286 strftime(tmp, sizeof(tmp), format, &t); 01287 lua_pushlstring(L, tmp, strlen(tmp)); 01288 return 1; 01289 } 01290 01291 01292 static const luaL_reg R[] = 01293 { 01294 {"access", Paccess}, 01295 {"basename", Pbasename}, 01296 {"chdir", Pchdir}, 01297 {"chmod", Pchmod}, 01298 {"chown", Pchown}, 01299 {"clock_getres", Pclock_getres}, 01300 {"clock_gettime", Pclock_gettime}, 01301 {"crypt", Pcrypt}, 01302 {"ctermid", Pctermid}, 01303 {"dirname", Pdirname}, 01304 {"dir", Pdir}, 01305 {"dup", Pdup}, 01306 {"errno", Perrno}, 01307 {"exec", Pexec}, 01308 {"execp", Pexecp}, 01309 {"fdopen", Pfdopen}, 01310 {"fileno", Pfileno}, 01311 {"files", Pfiles}, 01312 {"fork", Pfork}, 01313 {"getcwd", Pgetcwd}, 01314 {"getenv", Pgetenv}, 01315 {"getgroup", Pgetgroup}, 01316 {"getlogin", Pgetlogin}, 01317 {"getpasswd", Pgetpasswd}, 01318 {"getpid", Pgetpid}, 01319 {"getrlimit", Pgetrlimit}, 01320 {"gettimeofday", Pgettimeofday}, 01321 {"glob", Pglob}, 01322 {"gmtime", Pgmtime}, 01323 {"hostid", Phostid}, 01324 {"kill", Pkill}, 01325 {"link", Plink}, 01326 {"localtime", Plocaltime}, 01327 {"mkdir", Pmkdir}, 01328 {"mkfifo", Pmkfifo}, 01329 {"pathconf", Ppathconf}, 01330 {"pipe", Ppipe}, 01331 {"readlink", Preadlink}, 01332 {"rmdir", Prmdir}, 01333 {"rpoll", Ppoll}, 01334 {"setenv", Psetenv}, 01335 {"setpid", Psetpid}, 01336 {"setrlimit", Psetrlimit}, 01337 {"sleep", Psleep}, 01338 {"stat", Pstat}, 01339 {"strftime", Pstrftime}, 01340 {"sysconf", Psysconf}, 01341 {"time", Ptime}, 01342 {"times", Ptimes}, 01343 {"ttyname", Pttyname}, 01344 {"unlink", Punlink}, 01345 {"umask", Pumask}, 01346 {"uname", Puname}, 01347 {"utime", Putime}, 01348 {"wait", Pwait}, 01349 01350 #if ENABLE_SYSLOG 01351 {"openlog", Popenlog}, 01352 {"syslog", Psyslog}, 01353 {"closelog", Pcloselog}, 01354 {"setlogmask", Psetlogmask}, 01355 #endif 01356 01357 {NULL, NULL} 01358 }; 01359 01360 #define set_const(key, value) \ 01361 lua_pushliteral(L, key); \ 01362 lua_pushnumber(L, value); \ 01363 lua_settable(L, -3) 01364 01365 LUALIB_API int luaopen_posix (lua_State *L) 01366 { 01367 luaL_register(L,MYNAME,R); 01368 lua_pushliteral(L,"version"); 01369 lua_pushliteral(L,MYVERSION); 01370 lua_settable(L,-3); 01371 01372 #if ENABLE_SYSLOG 01373 set_const("LOG_AUTH", LOG_AUTH); 01374 set_const("LOG_AUTHPRIV", LOG_AUTHPRIV); 01375 set_const("LOG_CRON", LOG_CRON); 01376 set_const("LOG_DAEMON", LOG_DAEMON); 01377 set_const("LOG_FTP", LOG_FTP); 01378 set_const("LOG_KERN", LOG_KERN); 01379 set_const("LOG_LOCAL0", LOG_LOCAL0); 01380 set_const("LOG_LOCAL1", LOG_LOCAL1); 01381 set_const("LOG_LOCAL2", LOG_LOCAL2); 01382 set_const("LOG_LOCAL3", LOG_LOCAL3); 01383 set_const("LOG_LOCAL4", LOG_LOCAL4); 01384 set_const("LOG_LOCAL5", LOG_LOCAL5); 01385 set_const("LOG_LOCAL6", LOG_LOCAL6); 01386 set_const("LOG_LOCAL7", LOG_LOCAL7); 01387 set_const("LOG_LPR", LOG_LPR); 01388 set_const("LOG_MAIL", LOG_MAIL); 01389 set_const("LOG_NEWS", LOG_NEWS); 01390 set_const("LOG_SYSLOG", LOG_SYSLOG); 01391 set_const("LOG_USER", LOG_USER); 01392 set_const("LOG_UUCP", LOG_UUCP); 01393 01394 set_const("LOG_EMERG", LOG_EMERG); 01395 set_const("LOG_ALERT", LOG_ALERT); 01396 set_const("LOG_CRIT", LOG_CRIT); 01397 set_const("LOG_ERR", LOG_ERR); 01398 set_const("LOG_WARNING", LOG_WARNING); 01399 set_const("LOG_NOTICE", LOG_NOTICE); 01400 set_const("LOG_INFO", LOG_INFO); 01401 set_const("LOG_DEBUG", LOG_DEBUG); 01402 #endif 01403 01404 01405 return 1; 01406 } 01407 01408 /*EOF*/