[PATCH] xf86-input-synaptics: fix creation of repeater fifo
Peter Hutterer
peter.hutterer at who-t.net
Sun Sep 28 18:12:24 PDT 2008
On Sun, Sep 28, 2008 at 03:11:46PM +0100, Magnus Kessler wrote:
> Testing status against EEXIST is wrong and we should check errno instead if
> we want to allow the use of an existing file. However, since we pass a file
> name that in principle could be any existing file (not just fifos) is there
> any guarantee that we can later actually use the fifo?
Thanks. There is no guarantee that we can use it, but at the same time the
use-case where the pipe already exists is common.
In the simple case of a server restart, the first mkfifo command succeeds but
the second fails with EEXIST. So the pipe is still there and should be used.
Admittedly, it might be a good idea to clean up after ourselves and delete the
fifo if we have created it in the first place. What about the (compile-tested)
code below?
Cheers,
Peter
diff --git a/src/synaptics.c b/src/synaptics.c
index 18168e0..e5cb7f0 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -512,6 +512,9 @@ static void set_repeater_fifo(LocalDevicePtr local)
if (status && (errno != EEXIST)) {
xf86Msg(X_ERROR, "%s can't create repeater fifo\n", local->name);
} else {
+ if (!status)
+ priv->fifo_path = strdup(repeater); /* for unlinking later */
+
/* open the repeater fifo */
optList = xf86NewOption("Device", repeater);
if ((priv->fifofd = xf86OpenSerial(optList)) == -1) {
@@ -608,6 +611,7 @@ SynapticsPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
DBG(9, XisbTrace(priv->comm.buffer, 1));
priv->fifofd = -1;
+ priv->fifo_path = NULL;
set_repeater_fifo(local);
if (!QueryHardware(local)) {
@@ -655,6 +659,13 @@ static void SynapticsUnInit(InputDriverPtr drv,
InputInfoPtr local,
int flags)
{
+ SynapticsPrivate *priv = (SynapticsPrivate *) (local->private);
+
+ if (priv->fifo_path)
+ {
+ unlink(priv->fifo_path);
+ xfree(priv->fifo_path);
+ }
xfree(local->private);
local->private = NULL;
xf86DeleteInput(local, 0);
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index e5202d1..d93e279 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -96,6 +96,7 @@ typedef struct _SynapticsPrivateRec
struct CommData comm;
int fifofd; /* fd for fifo */
+ char *fifo_path; /* path to fifo for unlinking */
SynapticsMoveHistRec move_hist[SYNAPTICS_MOVE_HISTORY]; /* movement history */
int hist_index; /* Last added entry in move_hist[] */
More information about the xorg
mailing list