[Pcsclite-cvs-commit] r3098 - in /trunk/PCSC/src: utils.c utils.h
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Tue Aug 26 09:14:38 UTC 2008
Author: rousseau
Date: Tue Aug 26 09:14:38 2008
New Revision: 3098
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=3098
Log:
add StatSynchronize() "Sends an asynchronous event to any waiting
client"
Modified:
trunk/PCSC/src/utils.c
trunk/PCSC/src/utils.h
Modified: trunk/PCSC/src/utils.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/utils.c?rev=3098&op=diff
==============================================================================
--- trunk/PCSC/src/utils.c (original)
+++ trunk/PCSC/src/utils.c Tue Aug 26 09:14:38 2008
@@ -19,11 +19,14 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#include <dirent.h>
+#include <fcntl.h>
#include "debug.h"
#include "config.h"
#include "utils.h"
#include "pcscd.h"
+#include "sys_generic.h"
pid_t GetDaemonPid(void)
{
@@ -72,3 +75,68 @@
return EXIT_SUCCESS;
} /* SendHotplugSignal */
+/**
+ * Sends an asynchronous event to any waiting client
+ *
+ * Just write 1 byte to any fifo in PCSCLITE_EVENTS_DIR and remove the file
+ *
+ * This function must be secured since the files are created by the library
+ * or any non privileged process. We must not follow symlinks for example
+ */
+int StatSynchronize(struct pubReaderStatesList *readerState)
+{
+ DIR *dir_fd;
+ struct dirent *dir;
+
+ if (readerState)
+ SYS_MMapSynchronize((void *)readerState, SYS_GetPageSize() );
+
+ dir_fd = opendir(PCSCLITE_EVENTS_DIR);
+ while ((dir = readdir(dir_fd)) != NULL)
+ {
+ char filename[FILENAME_MAX];
+ int fd;
+ char buf[] = { '\0' };
+ struct stat fstat_buf;
+
+ if ('.' == dir->d_name[0])
+ continue;
+
+ snprintf(filename, sizeof(filename), "%s/%s", PCSCLITE_EVENTS_DIR,
+ dir->d_name);
+ Log2(PCSC_LOG_DEBUG, "status file: %s", filename);
+
+ fd = SYS_OpenFile(filename, O_WRONLY | O_APPEND | O_NONBLOCK, 0);
+ if (fd < 0)
+ {
+ Log3(PCSC_LOG_ERROR, "Can't open %s: %s", filename,
+ strerror(errno));
+ }
+ else
+ {
+ if (fstat(fd, &fstat_buf))
+ {
+ Log3(PCSC_LOG_ERROR, "Can't fstat %s: %s", filename,
+ strerror(errno));
+ }
+ else
+ {
+ /* check that the file is a FIFO */
+ if (!(fstat_buf.st_mode & S_IFIFO))
+ Log2(PCSC_LOG_ERROR, "%s is not a fifo", filename);
+ else
+ SYS_WriteFile(fd, buf, sizeof(buf));
+ }
+
+ SYS_CloseFile(fd);
+ }
+
+ if (unlink(filename))
+ Log3(PCSC_LOG_ERROR, "Can't remove %s: %s", filename,
+ strerror(errno));
+ }
+ closedir(dir_fd);
+
+ return 0;
+} /* StatSynchronize */
+
Modified: trunk/PCSC/src/utils.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/utils.h?rev=3098&op=diff
==============================================================================
--- trunk/PCSC/src/utils.h (original)
+++ trunk/PCSC/src/utils.h Tue Aug 26 09:14:38 2008
@@ -12,6 +12,7 @@
#include <sys/types.h>
#include "wintypes.h"
+#include "readerfactory.h"
#define PID_ASCII_SIZE 11
pid_t GetDaemonPid(void);
@@ -20,5 +21,7 @@
/* defined in winscard_clnt.c */
LONG SCardCheckDaemonAvailability(void);
+int StatSynchronize(struct pubReaderStatesList *readerState);
+
#endif
More information about the Pcsclite-cvs-commit
mailing list