struct GNUNET_CRYPTO_RsaPrivateKey *
GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
{
+#ifndef MINGW
+ // FIXME NILS
struct flock fl;
+#endif
struct GNUNET_CRYPTO_RsaPrivateKey *ret;
struct RsaPrivateKeyBinaryEncoded *enc;
struct stat sbuf;
"open", filename);
return NULL;
}
+#ifndef MINGW
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
cnt = 0;
+
while (0 != fcntl (fd, F_SETLK, &fl))
{
sleep (1);
fl.l_whence = SEEK_SET;
fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
}
+#endif
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Creating a new private key. This may take a while.\n"));
ret = GNUNET_CRYPTO_rsa_key_create ();
GNUNET_assert (enc != NULL);
GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len)));
GNUNET_free (enc);
+#ifndef MINGW
fdatasync (fd);
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_UNLCK;
if (0 != fcntl (fd, F_SETLK, &fl))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"fcntl", filename);
+#endif
GNUNET_assert (0 == CLOSE (fd));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Stored new private key in `%s'.\n"), filename);
cnt = 0;
while (1)
{
+#ifndef MINGW
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_RDLCK;
fl.l_whence = SEEK_SET;
sleep (1);
continue;
}
+#endif
if (0 != STAT (filename, &sbuf))
{
/* eh, what!? File we opened is now gone!? */
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"stat", filename);
+#ifndef MINGW
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"fcntl", filename);
GNUNET_assert (0 == CLOSE (fd));
+#endif
return NULL;
}
if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded))
{
+#ifndef MINGW
/* maybe we got the read lock before the hostkey generating
process had a chance to get the write lock; give it up! */
memset (&fl, 0, sizeof (struct flock));
}
sleep (2); /* wait a bit longer! */
continue;
+#endif
}
break;
}
filename);
GNUNET_free (enc);
}
+#ifndef MINGW
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded);
if (0 != fcntl (fd, F_SETLK, &fl))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+#endif
GNUNET_assert (0 == CLOSE (fd));
return ret;
}