cvs: /php3 ChangeLog /php3/functions php3_posix.h posix.c
| From: | Kristian K�hntopp | Date: | Sun, 12 Sep 1999 13:59:26 +0000 |
| Subject: | cvs: /php3 ChangeLog /php3/functions php3_posix.h posix.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-10824@lists.php.net to get a copy of this message | ||
kk Sun Sep 12 09:59:26 1999 EDT
Modified files:
/php3 ChangeLog
/php3/functions php3_posix.h posix.c
Log:
Added more functions to posix module.
Index: php3/ChangeLog
diff -u php3/ChangeLog:1.756 php3/ChangeLog:1.757
--- php3/ChangeLog:1.756 Thu Sep 9 13:41:12 1999
+++ php3/ChangeLog Sun Sep 12 09:59:26 1999
@@ -2,6 +2,7 @@
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
???? ??, 1999, Version 3.0.13
+- Added more functions to posix module.
- Close loophole that allowed virtual() to be used on a PHP file
without an error (Ken Coar)
- Add versioning support for shared library (Sascha)
Index: php3/functions/php3_posix.h
diff -u php3/functions/php3_posix.h:1.1 php3/functions/php3_posix.h:1.2
--- php3/functions/php3_posix.h:1.1 Sat Jun 12 06:28:35 1999
+++ php3/functions/php3_posix.h Sun Sep 12 09:59:26 1999
@@ -49,20 +49,34 @@
extern int php3_mshutdown_posix(void);
extern void php3_info_posix(void);
+extern void php3_posix_kill(INTERNAL_FUNCTION_PARAMETERS);
+
extern void php3_posix_getpid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getppid(INTERNAL_FUNCTION_PARAMETERS);
-extern void php3_posix_getpgrp(INTERNAL_FUNCTION_PARAMETERS);
-extern void php3_posix_getpgid(INTERNAL_FUNCTION_PARAMETERS);
-extern void php3_posix_getsid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getuid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getgid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_geteuid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getegid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_setuid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_setgid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_posix_getgroups(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getlogin(INTERNAL_FUNCTION_PARAMETERS);
-extern void php3_posix_getrlimit(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getpgrp(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_setsid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_setpgid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getpgid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_getsid(INTERNAL_FUNCTION_PARAMETERS);
+
extern void php3_posix_uname(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_times(INTERNAL_FUNCTION_PARAMETERS);
+
+extern void php3_posix_ctermid(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_ttyname(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_posix_isatty(INTERNAL_FUNCTION_PARAMETERS);
+
+extern void php3_posix_getrlimit(INTERNAL_FUNCTION_PARAMETERS);
typedef struct {
int dummy;
Index: php3/functions/posix.c
diff -u php3/functions/posix.c:1.7 php3/functions/posix.c:1.8
--- php3/functions/posix.c:1.7 Mon Jun 28 15:57:52 1999
+++ php3/functions/posix.c Sun Sep 12 09:59:26 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: */
+/* $Id: posix.c,v 1.8 1999/09/12 13:59:26 kk Exp $ */
#include "php.h"
@@ -46,27 +46,53 @@
#include <unistd.h>
#include <sys/resource.h>
#include <sys/utsname.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <sys/times.h>
#include <errno.h>
#include "php3_list.h"
#define SAFE_STRING(s) ((s)?(s):"")
function_entry posix_functions[] = {
+ /* POSIX.1, 3.3 */
+ {"posix_kill", php3_posix_kill, NULL},
+
+ /* POSIX.1, 4.1 */
{"posix_getpid", php3_posix_getpid, NULL},
{"posix_getppid", php3_posix_getppid, NULL},
- {"posix_getpgrp", php3_posix_getpgrp, NULL},
- {"posix_getpgid", php3_posix_getpgid, NULL},
- {"posix_getsid", php3_posix_getsid, NULL},
+ /* POSIX.1, 4.2 */
{"posix_getuid", php3_posix_getuid, NULL},
- {"posix_getgid", php3_posix_getgid, NULL},
{"posix_geteuid", php3_posix_geteuid, NULL},
+ {"posix_getgid", php3_posix_getgid, NULL},
{"posix_getegid", php3_posix_getegid, NULL},
+ {"posix_setuid", php3_posix_setuid, NULL},
+ {"posix_setgid", php3_posix_setgid, NULL},
{"posix_getgroups", php3_posix_getgroups, NULL},
+ {"posix_getlogin", php3_posix_getlogin, NULL},
- {"posix_getrlimit", php3_posix_getrlimit, NULL},
+ /* POSIX.1, 4.3 */
+ {"posix_getpgrp", php3_posix_getpgrp, NULL},
+ {"posix_setsid", php3_posix_setsid, NULL},
+ {"posix_setpgid", php3_posix_setpgid, NULL},
+ /* Non-Posix functions which are common */
+ {"posix_getpgid", php3_posix_getpgid, NULL},
+ {"posix_getsid", php3_posix_getsid, NULL},
+
+ /* POSIX.1, 4.4 */
{"posix_uname", php3_posix_uname, NULL},
+ /* POSIX.1, 4.5 */
+ {"posix_times", php3_posix_times, NULL},
+
+ /* POSIX.1, 4.7 */
+ {"posix_ctermid", php3_posix_ctermid, NULL},
+ {"posix_ttyname", php3_posix_ttyname, NULL},
+ {"posix_isatty", php3_posix_isatty, NULL},
+
+ {"posix_getrlimit", php3_posix_getrlimit, NULL},
+
{NULL, NULL, NULL}
};
@@ -102,48 +128,250 @@
void php3_info_posix(void)
{
- php3_printf("$ Revision: $\n");
+ php3_printf("$Revision: 1.8 $\n");
}
+/* {{{ proto int posix_kill(int pid, int sig)
+ Send a signal to a process (POSIX.1, 3.3.2) */
+void php3_posix_kill(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *pid;
+ pval *sig;
+ int result;
+
+ if (getParameters(ht, 2, &pid, &sig)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(pid);
+ convert_to_long(sig);
+
+ result = kill(pid->value.lval, sig->value.lval);
+ if (result< 0) {
+ php3_error(E_WARNING, "posix_kill(%d, %d) failed with '%s'",
+ pid->value.lval,
+ sig->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+
+/* }}} */
+
/* {{{ proto long posix_getpid(void)
- Get the current process id */
+ Get the current process id (POSIX.1, 4.1.1) */
void php3_posix_getpid(INTERNAL_FUNCTION_PARAMETERS)
{
pid_t pid;
pid = getpid();
- return_value->type= IS_LONG;
- return_value->value.lval = pid;
+ RETURN_LONG(pid);
}
/* }}} */
/* {{{ proto long posix_getppid(void)
- Get the parent process id */
+ Get the parent process id (POSIX.1, 4.1.1) */
void php3_posix_getppid(INTERNAL_FUNCTION_PARAMETERS)
{
pid_t ppid;
ppid = getppid();
- return_value->type= IS_LONG;
- return_value->value.lval = ppid;
+ RETURN_LONG(ppid);
+}
+/* }}} */
+
+/* {{{ proto long posix_getuid(void)
+ Get the current user id (POSIX.1, 4.2.1) */
+void php3_posix_getuid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ uid_t uid;
+
+ uid = getuid();
+ RETURN_LONG(uid);
+}
+/* }}} */
+
+/* {{{ proto long posix_getgid(void)
+ Get the current group id (POSIX.1, 4.2.1) */
+void php3_posix_getgid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ gid_t gid;
+
+ gid = getgid();
+ RETURN_LONG(gid);
+}
+/* }}} */
+
+/* {{{ proto long posix_geteuid(void)
+ Get the current effective user id (POSIX.1, 4.2.1) */
+void php3_posix_geteuid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ uid_t uid;
+
+ uid = geteuid();
+ RETURN_LONG(uid);
+}
+/* }}} */
+
+/* {{{ proto long posix_getegid(void)
+ Get the current effective group id (POSIX.1, 4.2.1) */
+void php3_posix_getegid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ gid_t gid;
+
+ gid = getegid();
+ RETURN_LONG(gid);
+}
+/* }}} */
+
+/* {{{ proto long posix_setuid(long uid)
+ Set User ID (POSIX.1, 4.2.2) */
+void php3_posix_setuid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *uid;
+ int result;
+
+ if (getParameters(ht, 1, &uid)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(uid);
+
+ result = setuid(uid->value.lval);
+ if (result < 0) {
+ php3_error(E_WARNING, "posix_setuid(%d) failed with '%s'. Must be root",
+ uid->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto long posix_setgid(long uid)
+ Set Group ID (POSIX.1, 4.2.2) */
+void php3_posix_setgid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *gid;
+ int result;
+
+ if (getParameters(ht, 1, &gid)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(gid);
+
+ result = setgid(gid->value.lval);
+ if (result < 0) {
+ php3_error(E_WARNING, "posix_setgid(%d) failed with '%s'. Must be root",
+ gid->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto long posix_getgroups(void)
+ Get Supplementary Group IDs (POSIX.1, 4.2.3) */
+void php3_posix_getgroups(INTERNAL_FUNCTION_PARAMETERS)
+{
+ gid_t gidlist[NGROUPS_MAX];
+ int result;
+ int i;
+
+ result = getgroups(NGROUPS_MAX, gidlist);
+ if (result < 0) {
+ php3_error(E_WARNING, "posix_getgroups() failed with '%s'",
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ for (i=0; i<result; i++) {
+ add_next_index_long(return_value,gidlist[i]);
+ }
}
/* }}} */
+/* {{{ proto string posix_getlogin(void)
+ Get User Name (POSIX.1, 4.2.4) */
+void php3_posix_getlogin(INTERNAL_FUNCTION_PARAMETERS)
+{
+ char *p;
+
+ p = getlogin();
+ if (p == NULL) {
+ php3_error(E_WARNING, "Cannot determine your login name. Something is really wrong
here.");
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(p, 1);
+}
+/* }}} */
+
/* {{{ proto long posix_getpgrp(void)
- Get the current process group */
+ Get current Process Group ID (POSIX.1, 4.3.1) */
void php3_posix_getpgrp(INTERNAL_FUNCTION_PARAMETERS)
{
pid_t pgrp;
pgrp = getpgrp();
- return_value->type= IS_LONG;
- return_value->value.lval = pgrp;
+ RETURN_LONG(pgrp);
+}
+/* }}} */
+
+/* {{{ proto long posix_setsid(void)
+ Create Session and Set Process Group ID (POSIX.1, 4.3.2) */
+void php3_posix_setsid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pid_t sid;
+
+ sid = setsid();
+ RETURN_LONG(sid);
+}
+/* }}} */
+
+/* {{{ proto long posix_setpgid(long pid, long pgid)
+ Set Process Group ID for Job Control (POSIX.1, 4.3.3) */
+void php3_posix_setpgid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *pid;
+ pval *pgid;
+ int result;
+
+ if (getParameters(ht, 2, &pid, &pgid)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(pid);
+ convert_to_long(pgid);
+
+ result = setpgid(pid->value.lval, pgid->value.lval);
+ if (result< 0) {
+ php3_error(E_WARNING, "posix_setpgid(%d, %d) failed with '%s'",
+ pid->value.lval,
+ pgid->value.lval,
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long posix_getpgid(void)
- Get the process group id of the specified process */
+ Get the process group id of the specified process
+ (This is not a POSIX function, but a SVR4ism, so
+ we compile conditionally) */
void php3_posix_getpgid(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_GETPGID
@@ -172,7 +400,9 @@
/* }}} */
/* {{{ proto long posix_getsid(void)
- get process group ID of session leader */
+ get process group ID of session leader
+ (This is not a POSIX function, but a SVR4ism, so
+ be compile conditionally) */
void php3_posix_getsid(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_GETSID
@@ -200,79 +430,125 @@
}
/* }}} */
-/* {{{ proto long posix_getuid(void)
- Get the current user id */
-void php3_posix_getuid(INTERNAL_FUNCTION_PARAMETERS)
+/* {{{ proto array posix_uname(void)
+ Get System Name (POSIX.1, 4.4.1) */
+
+void php3_posix_uname(INTERNAL_FUNCTION_PARAMETERS)
{
- uid_t uid;
+ struct utsname u;
- uid = getuid();
- return_value->type= IS_LONG;
- return_value->value.lval = uid;
+ uname(&u);
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_string(return_value, "sysname", u.sysname, strlen(u.sysname));
+ add_assoc_string(return_value, "nodename", u.nodename, strlen(u.nodename));
+ add_assoc_string(return_value, "release", u.release, strlen(u.release));
+ add_assoc_string(return_value, "version", u.version, strlen(u.version));
+ add_assoc_string(return_value, "machine", u.machine, strlen(u.machine));
}
/* }}} */
-/* {{{ proto long posix_getgid(void)
- Get the current group id */
-void php3_posix_getgid(INTERNAL_FUNCTION_PARAMETERS)
-{
- gid_t gid;
+/* POSIX.1, 4.5.1 time() - Get System Time
+ already covered by PHP3
+ */
- gid = getgid();
- return_value->type= IS_LONG;
- return_value->value.lval = gid;
-}
-/* }}} */
+/* {{{ proto array posix_times(void)
+ Get Process Times (POSIX.1, 4.5.2) */
-/* {{{ proto long posix_geteuid(void)
- Get the current effective user id */
-void php3_posix_geteuid(INTERNAL_FUNCTION_PARAMETERS)
+void php3_posix_times(INTERNAL_FUNCTION_PARAMETERS)
{
- uid_t uid;
+ struct tms t;
+ clock_t ticks;
- uid = geteuid();
- return_value->type= IS_LONG;
- return_value->value.lval = uid;
+ ticks = times(&t);
+ if (ticks < 0) {
+ php3_error(E_WARNING, "posix_times failed with '%s'",
+ strerror(errno));
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ add_assoc_long(return_value, "ticks", ticks);
+ add_assoc_long(return_value, "utime", t.tms_utime);
+ add_assoc_long(return_value, "stime", t.tms_stime);
+ add_assoc_long(return_value, "cutime", t.tms_cutime);
+ add_assoc_long(return_value, "cstime", t.tms_cstime);
}
/* }}} */
-
-/* {{{ proto long posix_getegid(void)
- Get the current effective group id */
-void php3_posix_getegid(INTERNAL_FUNCTION_PARAMETERS)
-{
- gid_t gid;
- gid = getegid();
- return_value->type= IS_LONG;
- return_value->value.lval = gid;
+/* POSIX.1, 4.6.1 getenv() - Environment Access
+ already covered by PHP3
+*/
+
+/* {{{ proto string posix_ctermid(void)
+ Generate Terminal Pathname (POSIX.1, 4.7.1) */
+void php3_posix_ctermid(INTERNAL_FUNCTION_PARAMETERS)
+{
+ char buffer[L_ctermid];
+ char *p;
+
+ p = ctermid(buffer);
+ if (p == NULL) {
+ php3_error(E_WARNING, "posix_ctermid() failed with '%s'",
+ strerror(errno));
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(buffer, 1);
}
/* }}} */
-/* {{{ proto long posix_getgroups(void)
- get supplementary group access list IDs */
-void php3_posix_getgroups(INTERNAL_FUNCTION_PARAMETERS)
+/* {{{ proto string posix_ttyname(int fd)
+ Determine Terminal Devicename (POSIX.1, 4.7.2) */
+void php3_posix_ttyname(INTERNAL_FUNCTION_PARAMETERS)
{
- gid_t gidlist[NGROUPS_MAX];
- int result;
- int i;
+ pval *fd;
+ char *p;
- result = getgroups(NGROUPS_MAX, gidlist);
- if (result < 0) {
- php3_error(E_WARNING, "posix_getgroups() failed with '%s'",
- strerror(errno));
- RETURN_FALSE;
+ if (getParameters(ht, 1, &fd)==FAILURE) {
+ WRONG_PARAM_COUNT;
}
+ convert_to_long(fd);
- if (array_init(return_value) == FAILURE) {
+ p = ttyname(fd->value.lval);
+ if (p == NULL) {
+ php3_error(E_WARNING, "posix_ttyname(%d) failed with '%s'",
+ fd->value.lval,
+ strerror(errno));
RETURN_FALSE;
}
+
+ RETURN_STRING(p, 1);
+}
+/* }}} */
- for (i=0; i<result; i++) {
- add_next_index_long(return_value,gidlist[i]);
+/* {{{ proto bool posix_isatty(int fd)
+ Determine if filedesc is a tty (POSIX.1, 4.7.1) */
+void php3_posix_isatty(INTERNAL_FUNCTION_PARAMETERS)
+{
+ pval *fd;
+ int result;
+
+ if (getParameters(ht, 1, &fd)==FAILURE) {
+ WRONG_PARAM_COUNT;
}
+ convert_to_long(fd);
+
+ result = isatty(fd->value.lval);
+ if (!result)
+ RETURN_FALSE;
+
+ RETURN_TRUE;
}
/* }}} */
+/*
+ POSIX.1, 4.8.1 sysconf() - TODO
+ */
+
#if HAVE_GETRLIMIT
static int posix_addlimit(int limit, char *name, pval *return_value) {
int result;
@@ -381,25 +657,6 @@
}
/* }}} */
-/* {{{ proto long posix_uname(void)
- get additional information about the current operating system */
-
-void php3_posix_uname(INTERNAL_FUNCTION_PARAMETERS)
-{
- struct utsname u;
-
- uname(&u);
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
- add_assoc_string(return_value, "sysname", u.sysname, strlen(u.sysname));
- add_assoc_string(return_value, "nodename", u.nodename, strlen(u.nodename));
- add_assoc_string(return_value, "release", u.release, strlen(u.release));
- add_assoc_string(return_value, "version", u.version, strlen(u.version));
- add_assoc_string(return_value, "machine", u.machine, strlen(u.machine));
-}
-/* }}} */
#endif