util-src/pposix.c
author Matthew Wild <mwild1@gmail.com>
Sun, 10 Jan 2010 21:48:25 +0000
changeset 2438 819ba949c7bc
parent 2437 b1ba2473fd91
child 2441 d72078946a16
permissions -rw-r--r--
util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
896
2c0b9e3c11c3 0.3->0.4
Matthew Wild <mwild1@gmail.com>
parents: 865
diff changeset
     1
/* Prosody IM v0.4
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
     2
-- Copyright (C) 2008-2009 Matthew Wild
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
     3
-- Copyright (C) 2008-2009 Waqas Hussain
864
416c812acde5 pposix: Small fix for copyright notice
Matthew Wild <mwild1@gmail.com>
parents: 861
diff changeset
     4
-- Copyright (C) 2009 Tobias Markmann
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
     5
--
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
     6
-- This project is MIT/X11 licensed. Please see the
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
     7
-- COPYING file in the source package for more information.
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
     8
--
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
*/
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
766
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
    11
/*
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
    12
* pposix.c
433a5226267f Licensing/version updates for some files (forgot to commit, doh...)
Matthew Wild <mwild1@gmail.com>
parents: 730
diff changeset
    13
* POSIX support functions for Lua
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
*/
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
2438
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
    16
#define MODULE_VERSION "0.3.2"
727
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
    17
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
#include <stdlib.h>
2438
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
    19
#include <math.h>
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
#include <unistd.h>
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
#include <libgen.h>
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
    22
#include <sys/resource.h>
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
#include <sys/types.h>
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
#include <sys/stat.h>
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
#include <fcntl.h>
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    27
#include <syslog.h>
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
    28
#include <pwd.h>
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
    29
#include <grp.h>
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    30
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    31
#include <string.h>
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
    32
#include <errno.h>
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    33
#include "lua.h"
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    34
#include "lauxlib.h"
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    35
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    36
/* Daemonization support */
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    37
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
    38
static int lc_daemonize(lua_State *L)
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    40
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    41
	pid_t pid;
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
    42
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    43
	if ( getppid() == 1 )
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    44
	{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    45
		lua_pushboolean(L, 0);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    46
		lua_pushstring(L, "already-daemonized");
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    47
		return 2;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    48
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
    49
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    50
	/* Attempt initial fork */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    51
	if((pid = fork()) < 0)
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    52
	{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    53
		/* Forking failed */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    54
		lua_pushboolean(L, 0);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    55
		lua_pushstring(L, "fork-failed");
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    56
		return 2;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    57
	}
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    58
	else if(pid != 0)
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    59
	{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    60
		/* We are the parent process */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    61
		lua_pushboolean(L, 1);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    62
		lua_pushnumber(L, pid);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    63
		return 2;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    64
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
    65
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    66
	/* and we are the child process */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    67
	if(setsid() == -1)
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    68
	{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    69
		/* We failed to become session leader */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    70
		/* (we probably already were) */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    71
		lua_pushboolean(L, 0);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    72
		lua_pushstring(L, "setsid-failed");
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    73
		return 2;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    74
	}
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    75
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    76
	/* Close stdin, stdout, stderr */
1195
6b91a2b39680 Close std{in,out,err} when daemonizing
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
    77
	close(0);
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    78
	close(1);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    79
	close(2);
1195
6b91a2b39680 Close std{in,out,err} when daemonizing
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
    80
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    81
	/* Final fork, use it wisely */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    82
	if(fork())
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    83
		exit(0);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    84
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    85
	/* Show's over, let's continue */
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    86
	lua_pushboolean(L, 1);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    87
	lua_pushnil(L);
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    88
	return 2;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    89
}
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    90
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    91
/* Syslog support */
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    92
796
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
    93
const char * const facility_strings[] = {
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
    94
					"auth",
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
    95
#if !(defined(sun) || defined(__sun))
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    96
					"authpriv",
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
    97
#endif
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    98
					"cron",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
    99
					"daemon",
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   100
#if !(defined(sun) || defined(__sun))
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   101
					"ftp",
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   102
#endif
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   103
					"kern",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   104
					"local0",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   105
					"local1",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   106
					"local2",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   107
					"local3",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   108
					"local4",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   109
					"local5",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   110
					"local6",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   111
					"local7",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   112
					"lpr",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   113
					"mail",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   114
					"syslog",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   115
					"user",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   116
					"uucp",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   117
					NULL
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   118
				};
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   119
int facility_constants[] =	{
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   120
					LOG_AUTH,
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   121
#if !(defined(sun) || defined(__sun))
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   122
					LOG_AUTHPRIV,
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   123
#endif
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   124
					LOG_CRON,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   125
					LOG_DAEMON,
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   126
#if !(defined(sun) || defined(__sun))
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   127
					LOG_FTP,
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   128
#endif
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   129
					LOG_KERN,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   130
					LOG_LOCAL0,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   131
					LOG_LOCAL1,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   132
					LOG_LOCAL2,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   133
					LOG_LOCAL3,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   134
					LOG_LOCAL4,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   135
					LOG_LOCAL5,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   136
					LOG_LOCAL6,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   137
					LOG_LOCAL7,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   138
					LOG_LPR,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   139
					LOG_MAIL,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   140
					LOG_NEWS,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   141
					LOG_SYSLOG,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   142
					LOG_USER,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   143
					LOG_UUCP,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   144
					-1
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   145
				};
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   146
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   147
/* "
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   148
       The parameter ident in the call of openlog() is probably stored  as-is.
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   149
       Thus,  if  the  string  it  points  to  is  changed, syslog() may start
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   150
       prepending the changed string, and if the string it points to ceases to
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   151
       exist,  the  results  are  undefined.  Most portable is to use a string
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   152
       constant.
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   153
   " -- syslog manpage
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   154
*/
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   155
char* syslog_ident = NULL;
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   156
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   157
int lc_syslog_open(lua_State* L)
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   158
{
796
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
   159
	int facility = luaL_checkoption(L, 2, "daemon", facility_strings);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   160
	facility = facility_constants[facility];
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   161
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   162
	luaL_checkstring(L, 1);
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   163
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   164
	if(syslog_ident)
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   165
		free(syslog_ident);
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   166
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   167
	syslog_ident = strdup(lua_tostring(L, 1));
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   168
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   169
	openlog(syslog_ident, LOG_PID, facility);
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   170
	return 0;
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   171
}
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   172
796
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
   173
const char * const level_strings[] = {
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   174
				"debug",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   175
				"info",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   176
				"notice",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   177
				"warn",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   178
				"error",
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   179
				NULL
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   180
			};
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   181
int level_constants[] = 	{
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   182
				LOG_DEBUG,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   183
				LOG_INFO,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   184
				LOG_NOTICE,
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   185
				LOG_WARNING,
1565
f1eeb049a0a5 pposix: Change LOG_EMERG -> LOG_CRIT, which makes more sense, thanks to intosi for reporting and an initial patch
Matthew Wild <mwild1@gmail.com>
parents: 1195
diff changeset
   186
				LOG_CRIT,
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   187
				-1
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   188
			};
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   189
int lc_syslog_log(lua_State* L)
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   190
{
796
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
   191
	int level = luaL_checkoption(L, 1, "notice", level_strings);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   192
	level = level_constants[level];
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   193
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   194
	luaL_checkstring(L, 2);
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   195
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   196
	syslog(level, "%s", lua_tostring(L, 2));
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   197
	return 0;
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   198
}
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   199
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   200
int lc_syslog_close(lua_State* L)
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   201
{
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   202
	closelog();
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   203
	if(syslog_ident)
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   204
	{
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   205
		free(syslog_ident);
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   206
		syslog_ident = NULL;
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   207
	}
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   208
	return 0;
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   209
}
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   210
729
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   211
int lc_syslog_setmask(lua_State* L)
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   212
{
796
63f56696c66c util.pposix: Fix incompatible pointer type compiler warnings
Matthew Wild <mwild1@gmail.com>
parents: 766
diff changeset
   213
	int level_idx = luaL_checkoption(L, 1, "notice", level_strings);
729
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   214
	int mask = 0;
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   215
	do
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   216
	{
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   217
		mask |= LOG_MASK(level_constants[level_idx]);
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   218
	} while (++level_idx<=4);
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   219
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   220
	setlogmask(mask);
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   221
	return 0;
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   222
}
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   223
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   224
/* getpid */
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   225
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   226
int lc_getpid(lua_State* L)
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   227
{
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   228
	lua_pushinteger(L, getpid());
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   229
	return 1;
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   230
}
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   231
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   232
/* UID/GID functions */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   233
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   234
int lc_getuid(lua_State* L)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   235
{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   236
	lua_pushinteger(L, getuid());
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   237
	return 1;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   238
}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   239
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   240
int lc_getgid(lua_State* L)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   241
{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   242
	lua_pushinteger(L, getgid());
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   243
	return 1;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   244
}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   245
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   246
int lc_setuid(lua_State* L)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   247
{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   248
	int uid = -1;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   249
	if(lua_gettop(L) < 1)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   250
		return 0;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   251
	if(!lua_isnumber(L, 1) && lua_tostring(L, 1))
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   252
	{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   253
		/* Passed UID is actually a string, so look up the UID */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   254
		struct passwd *p;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   255
		p = getpwnam(lua_tostring(L, 1));
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   256
		if(!p)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   257
		{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   258
			lua_pushboolean(L, 0);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   259
			lua_pushstring(L, "no-such-user");
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   260
			return 2;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   261
		}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   262
		uid = p->pw_uid;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   263
	}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   264
	else
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   265
	{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   266
		uid = lua_tonumber(L, 1);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   267
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   268
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   269
	if(uid>-1)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   270
	{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   271
		/* Ok, attempt setuid */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   272
		errno = 0;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   273
		if(setuid(uid))
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   274
		{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   275
			/* Fail */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   276
			lua_pushboolean(L, 0);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   277
			switch(errno)
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   278
			{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   279
			case EINVAL:
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   280
				lua_pushstring(L, "invalid-uid");
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   281
				break;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   282
			case EPERM:
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   283
				lua_pushstring(L, "permission-denied");
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   284
				break;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   285
			default:
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   286
				lua_pushstring(L, "unknown-error");
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   287
			}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   288
			return 2;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   289
		}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   290
		else
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   291
		{
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   292
			/* Success! */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   293
			lua_pushboolean(L, 1);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   294
			return 1;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   295
		}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   296
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   297
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   298
	/* Seems we couldn't find a valid UID to switch to */
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   299
	lua_pushboolean(L, 0);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   300
	lua_pushstring(L, "invalid-uid");
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   301
	return 2;
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   302
}
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   303
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   304
int lc_setgid(lua_State* L)
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   305
{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   306
	int gid = -1;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   307
	if(lua_gettop(L) < 1)
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   308
		return 0;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   309
	if(!lua_isnumber(L, 1) && lua_tostring(L, 1))
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   310
	{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   311
		/* Passed GID is actually a string, so look up the GID */
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   312
		struct group *g;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   313
		g = getgrnam(lua_tostring(L, 1));
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   314
		if(!g)
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   315
		{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   316
			lua_pushboolean(L, 0);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   317
			lua_pushstring(L, "no-such-group");
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   318
			return 2;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   319
		}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   320
		gid = g->gr_gid;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   321
	}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   322
	else
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   323
	{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   324
		gid = lua_tonumber(L, 1);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   325
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   326
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   327
	if(gid>-1)
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   328
	{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   329
		/* Ok, attempt setgid */
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   330
		errno = 0;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   331
		if(setgid(gid))
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   332
		{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   333
			/* Fail */
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   334
			lua_pushboolean(L, 0);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   335
			switch(errno)
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   336
			{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   337
			case EINVAL:
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   338
				lua_pushstring(L, "invalid-gid");
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   339
				break;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   340
			case EPERM:
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   341
				lua_pushstring(L, "permission-denied");
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   342
				break;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   343
			default:
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   344
				lua_pushstring(L, "unknown-error");
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   345
			}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   346
			return 2;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   347
		}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   348
		else
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   349
		{
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   350
			/* Success! */
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   351
			lua_pushboolean(L, 1);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   352
			return 1;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   353
		}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   354
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   355
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   356
	/* Seems we couldn't find a valid GID to switch to */
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   357
	lua_pushboolean(L, 0);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   358
	lua_pushstring(L, "invalid-gid");
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   359
	return 2;
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   360
}
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   361
2438
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   362
int lc_umask(lua_State* L)
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   363
{
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   364
	char old_mode_string[7];
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   365
	mode_t old_mode = umask(strtoul(luaL_checkstring(L, 1), NULL, 8));
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   366
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   367
	snprintf(old_mode_string, sizeof(old_mode_string), "%03o", old_mode);
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   368
	old_mode_string[sizeof(old_mode_string)-1] = 0;
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   369
	lua_pushstring(L, old_mode_string);
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   370
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   371
	return 1;
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   372
}
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   373
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   374
/*	Like POSIX's setrlimit()/getrlimit() API functions.
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   375
 *
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   376
 *	Syntax:
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   377
 *	pposix.setrlimit( resource, soft limit, hard limit)
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   378
 *
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   379
 *	Any negative limit will be replace with the current limit by an additional call of getrlimit().
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   380
 *
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   381
 *	Example usage:
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   382
 *	pposix.setrlimit("NOFILE", 1000, 2000)
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   383
 */
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   384
int string2resource(const char *s) {
861
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   385
	if (!strcmp(s, "CORE")) return RLIMIT_CORE;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   386
	if (!strcmp(s, "CPU")) return RLIMIT_CPU;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   387
	if (!strcmp(s, "DATA")) return RLIMIT_DATA;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   388
	if (!strcmp(s, "FSIZE")) return RLIMIT_FSIZE;
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   389
	if (!strcmp(s, "NOFILE")) return RLIMIT_NOFILE;
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   390
	if (!strcmp(s, "STACK")) return RLIMIT_STACK;
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   391
#if !(defined(sun) || defined(__sun))
861
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   392
	if (!strcmp(s, "MEMLOCK")) return RLIMIT_MEMLOCK;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   393
	if (!strcmp(s, "NPROC")) return RLIMIT_NPROC;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   394
	if (!strcmp(s, "RSS")) return RLIMIT_RSS;
1842
8337c0d4aee4 util.pposix: Compatibility with Solaris systems (thanks Filip)
Matthew Wild <mwild1@gmail.com>
parents: 1579
diff changeset
   395
#endif
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   396
	return -1;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   397
}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   398
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   399
int lc_setrlimit(lua_State *L) {
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   400
	int arguments = lua_gettop(L);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   401
	int softlimit = -1;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   402
	int hardlimit = -1;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   403
	const char *resource = NULL;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   404
	int rid = -1;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   405
	if(arguments < 1 || arguments > 3) {
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   406
		lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   407
		lua_pushstring(L, "incorrect-arguments");
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   408
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   409
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   410
	resource = luaL_checkstring(L, 1);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   411
	softlimit = luaL_checkinteger(L, 2);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   412
	hardlimit = luaL_checkinteger(L, 3);
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   413
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   414
	rid = string2resource(resource);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   415
	if (rid != -1) {
861
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   416
		struct rlimit lim;
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   417
		struct rlimit lim_current;
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   418
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   419
		if (softlimit < 0 || hardlimit < 0) {
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   420
			if (getrlimit(rid, &lim_current)) {
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   421
				lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   422
				lua_pushstring(L, "getrlimit-failed");
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   423
				return 2;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   424
			}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   425
		}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   426
861
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   427
		if (softlimit < 0) lim.rlim_cur = lim_current.rlim_cur;
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   428
			else lim.rlim_cur = softlimit;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   429
		if (hardlimit < 0) lim.rlim_max = lim_current.rlim_max;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   430
			else lim.rlim_max = hardlimit;
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   431
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   432
		if (setrlimit(rid, &lim)) {
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   433
			lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   434
			lua_pushstring(L, "setrlimit-failed");
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   435
			return 2;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   436
		}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   437
	} else {
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   438
		/* Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard. */
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   439
		lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   440
		lua_pushstring(L, "invalid-resource");
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   441
		return 2;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   442
	}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   443
	lua_pushboolean(L, 1);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   444
	return 1;
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   445
}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   446
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   447
int lc_getrlimit(lua_State *L) {
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   448
	int arguments = lua_gettop(L);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   449
	const char *resource = NULL;
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   450
	int rid = -1;
861
2a5373897128 Make the code actually build.
Tobias Markmann <tm@ayena.de>
parents: 860
diff changeset
   451
	struct rlimit lim;
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   452
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   453
	if (arguments != 1) {
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   454
		lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   455
		lua_pushstring(L, "invalid-arguments");
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   456
		return 2;
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   457
	}
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   458
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   459
	resource = luaL_checkstring(L, 1);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   460
	rid = string2resource(resource);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   461
	if (rid != -1) {
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   462
		if (getrlimit(rid, &lim)) {
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   463
			lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   464
			lua_pushstring(L, "getrlimit-failed.");
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   465
			return 2;
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   466
		}
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   467
	} else {
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   468
		/* Unsupported resoucrce. Sorry I'm pretty limited by POSIX standard. */
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   469
		lua_pushboolean(L, 0);
865
2dce34e9182d pposix: Standardize error messages
Matthew Wild <mwild1@gmail.com>
parents: 864
diff changeset
   470
		lua_pushstring(L, "invalid-resource");
860
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   471
		return 2;
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   472
	}
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   473
	lua_pushboolean(L, 1);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   474
	lua_pushnumber(L, lim.rlim_cur);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   475
	lua_pushnumber(L, lim.rlim_max);
048aaec22b57 Added missing code.
Tobias Markmann <tm@ayena.de>
parents: 859
diff changeset
   476
	return 3;
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   477
}
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   478
2437
b1ba2473fd91 util.pposix: Fix return type of lc_abort to shush compiler warning
Matthew Wild <mwild1@gmail.com>
parents: 2436
diff changeset
   479
int lc_abort(lua_State* L)
2060
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   480
{
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   481
	abort();
2437
b1ba2473fd91 util.pposix: Fix return type of lc_abort to shush compiler warning
Matthew Wild <mwild1@gmail.com>
parents: 2436
diff changeset
   482
	return 0;
2060
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   483
}
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   484
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   485
/* Register functions */
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   486
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   487
int luaopen_util_pposix(lua_State *L)
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   488
{
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   489
	lua_newtable(L);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   490
2060
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   491
	lua_pushcfunction(L, lc_abort);
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   492
	lua_setfield(L, -2, "abort");
b23295b5428a util.pposix: Add abort() function
Matthew Wild <mwild1@gmail.com>
parents: 1842
diff changeset
   493
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   494
	lua_pushcfunction(L, lc_daemonize);
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   495
	lua_setfield(L, -2, "daemonize");
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   496
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   497
	lua_pushcfunction(L, lc_syslog_open);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   498
	lua_setfield(L, -2, "syslog_open");
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   499
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   500
	lua_pushcfunction(L, lc_syslog_close);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   501
	lua_setfield(L, -2, "syslog_close");
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   502
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   503
	lua_pushcfunction(L, lc_syslog_log);
722
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   504
	lua_setfield(L, -2, "syslog_log");
63456c9d0522 mod_posix: Support for logging to syslog (log = 'syslog' in config)
Matthew Wild <mwild1@gmail.com>
parents: 588
diff changeset
   505
729
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   506
	lua_pushcfunction(L, lc_syslog_setmask);
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   507
	lua_setfield(L, -2, "syslog_setminlevel");
f62ef65d5c01 pposix: Add syslog_setmask (use config: minimum_log_level = 'warn' etc.)
Matthew Wild <mwild1@gmail.com>
parents: 727
diff changeset
   508
723
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   509
	lua_pushcfunction(L, lc_getpid);
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   510
	lua_setfield(L, -2, "getpid");
c1e7d280c174 mod_posix/pposix: Fix reporting of incorrect PID on daemonization. Log correct PID, and support writing a pidfile (pidfile = '/path/to/prosody.pid' in config). Added getpid() to pposix and improved function names.
Matthew Wild <mwild1@gmail.com>
parents: 722
diff changeset
   511
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   512
	lua_pushcfunction(L, lc_getuid);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   513
	lua_setfield(L, -2, "getuid");
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   514
	lua_pushcfunction(L, lc_getgid);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   515
	lua_setfield(L, -2, "getgid");
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   516
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   517
	lua_pushcfunction(L, lc_setuid);
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   518
	lua_setfield(L, -2, "setuid");
1578
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   519
	lua_pushcfunction(L, lc_setgid);
5bd8b3bdbfbc pposix: Add setgid() function
Matthew Wild <mwild1@gmail.com>
parents: 1565
diff changeset
   520
	lua_setfield(L, -2, "setgid");
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   521
2438
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   522
	lua_pushcfunction(L, lc_umask);
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   523
	lua_setfield(L, -2, "umask");
819ba949c7bc util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Matthew Wild <mwild1@gmail.com>
parents: 2437
diff changeset
   524
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   525
	lua_pushcfunction(L, lc_setrlimit);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   526
	lua_setfield(L, -2, "setrlimit");
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   527
859
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   528
	lua_pushcfunction(L, lc_getrlimit);
43f7e342135d Adding setrlimits() binding.
Tobias Markmann <tm@ayena.de>
parents: 804
diff changeset
   529
	lua_setfield(L, -2, "getrlimit");
804
9bc1544c99b7 util.pposix: Add getuid/setuid (we don't use them yet)
Matthew Wild <mwild1@gmail.com>
parents: 796
diff changeset
   530
727
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
   531
	lua_pushliteral(L, "pposix");
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
   532
	lua_setfield(L, -2, "_NAME");
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
   533
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
   534
	lua_pushliteral(L, MODULE_VERSION);
78c9542de94e pposix: Add _NAME and _VERSION
Matthew Wild <mwild1@gmail.com>
parents: 723
diff changeset
   535
	lua_setfield(L, -2, "_VERSION");
2436
ccc71b5d2e01 util.posix: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents: 2060
diff changeset
   536
586
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   537
	return 1;
b828d7d47973 Add posix support library, and adjust makefiles for it
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   538
};