Date: Sat, 8 Jul 1995 00:42:04 +0300 (EET DST) From: Jukka Ukkonen <jau@jau.csc.fi> To: hackers@freebsd.org Subject: new getsid(2) system call for freebsd... Message-ID: <199507072142.AAA00799@jau.csc.fi>
next in thread | raw e-mail | index | archive | help
Hi all!
A couple of days ago I had a sudden moment of inspiration and
I added an initial version of a new SVR4 style system call
getsid(2) to FreeBSD.
In fact the same piece of code should be just about all right
also for other variants of BSD based systems, if anyone cares
to import it to any of them.
The rationale for such a new system call is first and foremost
completeness and symmetry. The second reason is the fact that
X/Open might begin requiring such a service in their XPG, which
might become a portability issue one day. The third point is
that now and then there are things that would be somewhat easier
to do, if such an interface were available, and moreover it is
practically impossible to do exactly the same thing in a user
mode subroutine.
My version is based on my interpretation of what has been said
about getsid(2) in SGI Irix-6.0 manual pages.
The idea is that the caller can ask the session id (actually the
PID of the session leader) of any process in the system, if the
caller runs with the EUID of root. Any process can also query
the SID of any other process having the same EUID as the caller
or that of any of it's own descendants. Naturally a process can
also query it's own SID by specifying it's own PID or 0 as the
parameter.
The external prototype of the system call is
extern pid_t getsid (pid_t target_process_id);
In the current implementation I just grabbed syscall number 205
for this purpose, because it was the first one which I noticed
not to be previously allocated for any other purpose. Some of
you may certainly argue that some other code should be used
instead, and some of you will supposedly even argue against
having such a system call at all. Anyway you have now seen my
reasoning for including getsid(2) in the system distribution,
and the game is yours.
You are free to change the syscall number and other details
or even drop my patch, if you like. I could imagine at least
one potential enhancement right now. The SID could maybe be
stored in the session structure itself, so that getsid(2)
would not depend on the original session leader or it's zombie
being present in the system just in case a child process had
survived after the termination of the original session leader.
In my own system I will maintain my idea of which processes are
allowed to use getsid(2) to query SIDs of other processes, which
is as close to SVR4 (and supposedly also X/Open) definition I
could get based on the documentation I had, unless or until
someone is able to present a reasonably good basis for different
access rules.
The patch (diff -c) to all the minor but necessary changes
is attached at the end of this message.
(Oh yes, don't even ask. It should be obvious. I did not run
makesyscalls.sh but made the changes to the .h files manually,
though I also modified the syscalls.master file appropriately.)
Cheers,
// jau
------
/ Jukka A. Ukkonen, FUNET / Centre for Scientific Computing
/__ M.Sc. (sw-eng & cs) Tel: (Home) +358-0-578628
/ Internet: ukkonen@csc.fi (Work) +358-0-4573208
/ Internet: jau@funet.fi (Mobile) +358-400-606671
v X.400: c=fi, admd=fumail, no prmd, org=csc, pn=jukka.ukkonen
------------------------------ clip clip ------------------------------
*** /usr/src/lib/libc/sys/Makefile.inc.orig Sat May 27 07:17:04 1995
--- /usr/src/lib/libc/sys/Makefile.inc Fri Jul 7 01:46:41 1995
***************
*** 17,23 ****
fchflags.o fchmod.o fchown.o fcntl.o flock.o fpathconf.o fstat.o \
fstatfs.o fsync.o getdirentries.o getdtablesize.o getegid.o \
geteuid.o getfh.o getfsstat.o getgid.o getgroups.o getitimer.o \
! getpeername.o getpgrp.o getpid.o getppid.o getpriority.o \
getrlimit.o getrusage.o getsockname.o getsockopt.o gettimeofday.o \
getuid.o ioctl.o kill.o ktrace.o lfs_bmapv.o lfs_markv.o \
lfs_segclean.o lfs_segwait.o link.o listen.o lstat.o \
--- 17,23 ----
fchflags.o fchmod.o fchown.o fcntl.o flock.o fpathconf.o fstat.o \
fstatfs.o fsync.o getdirentries.o getdtablesize.o getegid.o \
geteuid.o getfh.o getfsstat.o getgid.o getgroups.o getitimer.o \
! getpeername.o getpgrp.o getpid.o getppid.o getsid.o getpriority.o \
getrlimit.o getrusage.o getsockname.o getsockopt.o gettimeofday.o \
getuid.o ioctl.o kill.o ktrace.o lfs_bmapv.o lfs_markv.o \
lfs_segclean.o lfs_segwait.o link.o listen.o lstat.o \
*** /usr/include/sys/syscall.h.orig Sun Apr 23 15:22:06 1995
--- /usr/include/sys/syscall.h Fri Jul 7 01:12:45 1995
***************
*** 191,193 ****
--- 191,194 ----
#define SYS___sysctl 202
#define SYS_mlock 203
#define SYS_munlock 204
+ #define SYS_getsid 205
*** /usr/include/sys/syscall-hide.h.orig Fri Jul 7 01:14:16 1995
--- /usr/include/sys/syscall-hide.h Fri Jul 7 01:13:22 1995
***************
*** 214,216 ****
--- 214,217 ----
HIDE_BSD(__sysctl)
HIDE_BSD(mlock)
HIDE_BSD(munlock)
+ HIDE_BSD(getsid)
*** /sys/kern/init_sysent.c.orig Fri Jul 7 09:27:51 1995
--- /sys/kern/init_sysent.c Fri Jul 7 09:28:25 1995
***************
*** 177,182 ****
--- 177,183 ----
int __sysctl();
int mlock();
int munlock();
+ int getsid();
int lkmnosys();
#ifdef COMPAT_43
***************
*** 484,490 ****
{ 6, __sysctl }, /* 202 = __sysctl */
{ 2, mlock }, /* 203 = mlock */
{ 2, munlock }, /* 204 = munlock */
! { 0, nosys }, /* 205 = nosys */
{ 0, nosys }, /* 206 = nosys */
{ 0, nosys }, /* 207 = nosys */
{ 0, nosys }, /* 208 = nosys */
--- 485,492 ----
{ 6, __sysctl }, /* 202 = __sysctl */
{ 2, mlock }, /* 203 = mlock */
{ 2, munlock }, /* 204 = munlock */
! /* { 0, nosys }, 205 = nosys */
! { 1, getsid }, /* 205 = getsid */
{ 0, nosys }, /* 206 = nosys */
{ 0, nosys }, /* 207 = nosys */
{ 0, nosys }, /* 208 = nosys */
*** /sys/kern/kern_prot.c.orig Fri Jul 7 09:27:51 1995
--- /sys/kern/kern_prot.c Fri Jul 7 19:13:47 1995
***************
*** 95,100 ****
--- 95,157 ----
return (0);
}
+ /*
+ * External signature: pid_t getsid (pid_t);
+ *
+ * SVR4 style system call getsid()
+ * exists only because this is a trick which is practically
+ * impossible to do from within a user space subroutine.
+ * Often this kind of information is useful to have though,
+ * and probably X/Open will require this anyway.
+ */
+
+ struct getsid_args {
+ pid_t pid;
+ };
+
+ /* ARGSUSED */
+ int
+ getsid (p, uap, retval)
+ struct proc *p;
+ struct getsid_args *uap;
+ int *retval;
+ {
+ /*
+ * Currently the expression
+ *
+ * *retval = p->p_session->s_leader->p_pid;
+ *
+ * is an easier to read form of...
+ *
+ * *retval = p->p_pgrp->pg_session->s_leader->p_pid;
+ */
+
+ register struct proc *targp; /* taget process */
+
+ if (! uap->pid || (uap->pid == p->p_pid))
+ targp = p;
+ else {
+ if (! (targp = pfind(uap->pid)))
+ return (ESRCH);
+
+ /*
+ * For true pedantics only...
+ * 1. Either current proc must be owned by root,
+ * 2. or by the same effective uid as the target,
+ * 3. or the target must be a descendant of the caller.
+ */
+ if (p->p_cred->pc_ucred->cr_uid
+ && (targp->p_cred->pc_ucred->cr_uid
+ != p->p_cred->pc_ucred->cr_uid)
+ && ! inferior(targp))
+ return (EPERM);
+ }
+
+ *retval = targp->p_session->s_leader->p_pid;
+
+ return (0);
+ }
+
/* ARGSUSED */
int
getuid(p, uap, retval)
*** /sys/kern/syscalls.c.orig Fri Jul 7 09:27:51 1995
--- /sys/kern/syscalls.c Fri Jul 7 09:28:25 1995
***************
*** 246,252 ****
"__sysctl", /* 202 = __sysctl */
"mlock", /* 203 = mlock */
"munlock", /* 204 = munlock */
! "#205", /* 205 = nosys */
"#206", /* 206 = nosys */
"#207", /* 207 = nosys */
"#208", /* 208 = nosys */
--- 246,253 ----
"__sysctl", /* 202 = __sysctl */
"mlock", /* 203 = mlock */
"munlock", /* 204 = munlock */
! /* "#205", 205 = nosys */
! "getsid", /* 205 = getsid */
"#206", /* 206 = nosys */
"#207", /* 207 = nosys */
"#208", /* 208 = nosys */
*** /sys/kern/syscalls.master.orig Fri Jul 7 09:27:51 1995
--- /sys/kern/syscalls.master Fri Jul 7 09:28:25 1995
***************
*** 277,283 ****
; here allows to avoid one in libc/sys/Makefile.inc.
203 STD 2 BSD mlock
204 STD 2 BSD munlock
! 205 UNIMPL 0 NOHIDE nosys
206 UNIMPL 0 NOHIDE nosys
207 UNIMPL 0 NOHIDE nosys
208 UNIMPL 0 NOHIDE nosys
--- 277,284 ----
; here allows to avoid one in libc/sys/Makefile.inc.
203 STD 2 BSD mlock
204 STD 2 BSD munlock
! ; 205 UNIMPL 0 NOHIDE nosys
! 205 STD 1 BSD getsid
206 UNIMPL 0 NOHIDE nosys
207 UNIMPL 0 NOHIDE nosys
208 UNIMPL 0 NOHIDE nosys
*** /usr/include/unistd.h.orig Sun Jun 4 16:45:57 1995
--- /usr/include/unistd.h Fri Jul 7 08:25:45 1995
***************
*** 76,81 ****
--- 76,82 ----
pid_t getpgrp __P((void));
pid_t getpid __P((void));
pid_t getppid __P((void));
+ pid_t getsid __P((pid_t));
uid_t getuid __P((void));
int isatty __P((int));
int link __P((const char *, const char *));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199507072142.AAA00799>
