From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 2/4] ipcmk: remove unnecessary create_key() function
Date: Wed, 9 Jan 2013 19:36:54 +0000 [thread overview]
Message-ID: <1357760216-4068-2-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1357760216-4068-1-git-send-email-kerolasa@iki.fi>
Use seed_random() from randutils instead, and stop generating new seed
when it does not have to happen
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcmk.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/sys-utils/ipcmk.c b/sys-utils/ipcmk.c
index a862ba1..9b943b7 100644
--- a/sys-utils/ipcmk.c
+++ b/sys-utils/ipcmk.c
@@ -34,30 +34,23 @@
#include "nls.h"
#include "strutils.h"
#include "closestream.h"
-
-static key_t create_key(void)
-{
- struct timeval now;
- gettimeofday(&now, NULL);
- srandom(now.tv_usec);
- return random();
-}
+#include "randutils.h"
static int create_shm(size_t size, int permission)
{
- key_t key = create_key();
+ key_t key = random();
return shmget(key, size, permission | IPC_CREAT);
}
static int create_msg(int permission)
{
- key_t key = create_key();
+ key_t key = random();
return msgget(key, permission | IPC_CREAT);
}
static int create_sem(int nsems, int permission)
{
- key_t key = create_key();
+ key_t key = random();
return semget(key, nsems, permission | IPC_CREAT);
}
@@ -100,6 +93,7 @@ int main(int argc, char **argv)
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
atexit(close_stdout);
+ seed_random();
while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) {
switch(opt) {
--
1.8.1
next prev parent reply other threads:[~2013-01-09 19:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-09 19:36 [PATCH 1/4] lib: add function to seed random() Sami Kerola
2013-01-09 19:36 ` Sami Kerola [this message]
2013-01-10 10:19 ` [PATCH 2/4] ipcmk: remove unnecessary create_key() function Karel Zak
2013-01-24 15:32 ` Karel Zak
2013-01-09 19:36 ` [PATCH 3/4] ipcmk: allow user to create more ipc resources at a time Sami Kerola
2013-01-10 9:25 ` Karel Zak
2013-01-09 19:36 ` [PATCH 4/4] include: add missing values to sysfs_cxt initializer definition Sami Kerola
2013-01-24 15:35 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357760216-4068-2-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox