Re: [PATCH v2 1/5] dix: Add facilities for client ID tracking.

2010-09-14 Thread Vignatti Tiago (Nokia-MS/Helsinki)
On Fri, Sep 10, 2010 at 06:58:38PM +0200, ext Rami Ylimäki wrote:
 An interface is provided for figuring out the PID and process name of
 a client. Make some existing functionality from SELinux and IA
 extensions available for general use.
 
 Signed-off-by: Rami Ylimäki rami.ylim...@vincit.fi
 ---
  dix/Makefile.am  |1 +
  dix/client.c |  338 
 ++
  include/client.h |   54 +
  include/os.h |2 +
  os/access.c  |   46 
  5 files changed, 441 insertions(+), 0 deletions(-)
  create mode 100644 dix/client.c
  create mode 100644 include/client.h
 
 diff --git a/dix/Makefile.am b/dix/Makefile.am
 index 5e2dad7..bc87da5 100644
 --- a/dix/Makefile.am
 +++ b/dix/Makefile.am
 @@ -7,6 +7,7 @@ libmain_la_SOURCES =\
 
  libdix_la_SOURCES =\
 atom.c  \
 +   client.c\
 colormap.c  \
 cursor.c\
 deprecated.c\
 diff --git a/dix/client.c b/dix/client.c
 new file mode 100644
 index 000..99152a4
 --- /dev/null
 +++ b/dix/client.c
 @@ -0,0 +1,338 @@
 +/*
 + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). All
 + * rights reserved.
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a 
 copy
 + * of this software and associated documentation files (the Software), to 
 deal
 + * in the Software without restriction, including without limitation the 
 rights
 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 + * copies of the Software, and to permit persons to whom the Software is
 + * furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE
 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 FROM,
 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 + * THE SOFTWARE.
 + *
 + * Author: Rami Ylimäki rami.ylim...@vincit.fi
 + *
 + * This file contains functionality for identifying clients by various
 + * means. The primary purpose of identification is to simply aid in
 + * finding out which clients are using X server and how they are using
 + * it. For example, it's often necessary to monitor what requests
 + * clients are executing (to spot bad behaviour) and how they are
 + * allocating resources in X server (to spot excessive resource
 + * usage).
 + *
 + * This framework automatically allocates information, that can be
 + * used for client identification, when a client connects to the
 + * server. The information is freed when the client disconnects. The
 + * allocated information is just a collection of various IDs, such as
 + * PID and process name for local clients, that are likely to be
 + * useful in analyzing X server usage.
 + *
 + * Users of the framework can query ID information about clients at
 + * any time. To avoid repeated polling of IDs the users can also
 + * subscribe for notifications about the availability of ID
 + * information. Use GetClient* to query information and
 + * GetClientIds*Cbs to register for notifications.
 + */

doxygen's @file directive maybe could be used here?

 +
 +#include stdlib.h
 +#include unistd.h

I pretty much think that those two system header files are already indirected
included (by misc.h - os.h or something like that)


 +#include os.h
 +#include client.h
 +#include dixstruct.h
 +
 +/* Key for identifying ID information for a client. */
 +static DevPrivateKeyRec ClientIdsPrivKeyRec;
 +static DevPrivateKey ClientIdsPrivKey = ClientIdsPrivKeyRec;
 +
 +/**
 + * @return Client private holding PID and command line string. Error
 + * (NULL) if PID is not available for the client.
 + */
 +ClientIdsPrivatePtr GetClientIds(ClientPtr client)
 +{
 +PrivatePtr *privates = (client)-devPrivates;
 +pointer priv = dixLookupPrivate(privates, ClientIdsPrivKey);
 +return (ClientIdsPrivatePtr) priv;
 +}
 +
 +/* Called after PID and command line string have been determined for a
 + * client (all clients, including remote clients, except server
 + * client). You may call GetClientPid and GetClientCmd after this
 + * notification. */
 +static CallbackListPtr ClientIdsReservedCbs = NULL;
 +
 +/**
 + * @return Publisher of client ID allocation notifications.
 + *
 + * @see AddCallback
 + */
 +CallbackListPtr *GetClientIdsReservedCbs(void)
 +{
 +return ClientIdsReservedCbs;
 +}
 +
 +/* Called before PID and command line string will be invalidated for a
 + * client (all clients, including remote clients, except server
 + * client). 

[PATCH v2 1/5] dix: Add facilities for client ID tracking.

2010-09-10 Thread Rami Ylimäki
An interface is provided for figuring out the PID and process name of
a client. Make some existing functionality from SELinux and IA
extensions available for general use.

Signed-off-by: Rami Ylimäki rami.ylim...@vincit.fi
---
 dix/Makefile.am  |1 +
 dix/client.c |  338 ++
 include/client.h |   54 +
 include/os.h |2 +
 os/access.c  |   46 
 5 files changed, 441 insertions(+), 0 deletions(-)
 create mode 100644 dix/client.c
 create mode 100644 include/client.h

diff --git a/dix/Makefile.am b/dix/Makefile.am
index 5e2dad7..bc87da5 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -7,6 +7,7 @@ libmain_la_SOURCES =\
 
 libdix_la_SOURCES =\
atom.c  \
+   client.c\
colormap.c  \
cursor.c\
deprecated.c\
diff --git a/dix/client.c b/dix/client.c
new file mode 100644
index 000..99152a4
--- /dev/null
+++ b/dix/client.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). All
+ * rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Author: Rami Ylimäki rami.ylim...@vincit.fi
+ *
+ * This file contains functionality for identifying clients by various
+ * means. The primary purpose of identification is to simply aid in
+ * finding out which clients are using X server and how they are using
+ * it. For example, it's often necessary to monitor what requests
+ * clients are executing (to spot bad behaviour) and how they are
+ * allocating resources in X server (to spot excessive resource
+ * usage).
+ *
+ * This framework automatically allocates information, that can be
+ * used for client identification, when a client connects to the
+ * server. The information is freed when the client disconnects. The
+ * allocated information is just a collection of various IDs, such as
+ * PID and process name for local clients, that are likely to be
+ * useful in analyzing X server usage.
+ *
+ * Users of the framework can query ID information about clients at
+ * any time. To avoid repeated polling of IDs the users can also
+ * subscribe for notifications about the availability of ID
+ * information. Use GetClient* to query information and
+ * GetClientIds*Cbs to register for notifications.
+ */
+
+#include stdlib.h
+#include unistd.h
+
+#include os.h
+#include client.h
+#include dixstruct.h
+
+/* Key for identifying ID information for a client. */
+static DevPrivateKeyRec ClientIdsPrivKeyRec;
+static DevPrivateKey ClientIdsPrivKey = ClientIdsPrivKeyRec;
+
+/**
+ * @return Client private holding PID and command line string. Error
+ * (NULL) if PID is not available for the client.
+ */
+ClientIdsPrivatePtr GetClientIds(ClientPtr client)
+{
+PrivatePtr *privates = (client)-devPrivates;
+pointer priv = dixLookupPrivate(privates, ClientIdsPrivKey);
+return (ClientIdsPrivatePtr) priv;
+}
+
+/* Called after PID and command line string have been determined for a
+ * client (all clients, including remote clients, except server
+ * client). You may call GetClientPid and GetClientCmd after this
+ * notification. */
+static CallbackListPtr ClientIdsReservedCbs = NULL;
+
+/**
+ * @return Publisher of client ID allocation notifications.
+ *
+ * @see AddCallback
+ */
+CallbackListPtr *GetClientIdsReservedCbs(void)
+{
+return ClientIdsReservedCbs;
+}
+
+/* Called before PID and command line string will be invalidated for a
+ * client (all clients, including remote clients, except server
+ * client). GetClientPid and GetClientCmd will return errors when
+ * called after this notification. */
+static CallbackListPtr ClientIdsReleasedCbs = NULL;
+
+/**
+ * @return Publisher of client ID deallocation notifications.
+ *
+ * @see AddCallback
+ */
+CallbackListPtr *GetClientIdsReleasedCbs(void)
+{
+return ClientIdsReleasedCbs;
+}
+
+/**
+ * Try to determine a PID for a client