Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
c4985e94
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c4985e94
编写于
1月 22, 2009
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use the gnulib random_r function
上级
1b745219
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
12 deletion
+54
-12
ChangeLog
ChangeLog
+10
-1
Makefile.maint
Makefile.maint
+1
-1
src/libvirt.c
src/libvirt.c
+3
-5
src/util.c
src/util.c
+35
-3
src/util.h
src/util.h
+3
-0
src/uuid.c
src/uuid.c
+2
-2
未找到文件。
ChangeLog
浏览文件 @
c4985e94
Thu
Jan
21
19
:
04
:
12
GMT
2009
Daniel
P
.
Berrange
<
berrange
@
redhat
.
com
>
Thu
Jan
21
19
:
44
:
12
GMT
2009
Daniel
P
.
Berrange
<
berrange
@
redhat
.
com
>
Use
the
GNULIB
random_r
function
*
Makefile
.
maint
:
print
4
lines
of
context
when
complaining
about
prohibited
POSIX
apis
*
src
/
libvirt
.
c
:
Initialize
random
number
generator
*
src
/
util
.
c
,
src
/
util
.
h
:
Generate
API
for
random
number
gen
*
src
/
uuid
.:
Use
generic
random
number
generator
API
Thu
Jan
21
19
:
41
:
12
GMT
2009
Daniel
P
.
Berrange
<
berrange
@
redhat
.
com
>
Remove
use
of
non
-
reentrant
POSIX
api
calls
*
configure
.
in
:
Check
for
strtok_r
getmntent_r
getgrnam_r
getpwuid_r
...
...
Makefile.maint
浏览文件 @
c4985e94
...
...
@@ -117,7 +117,7 @@ sc_prohibit_nonreentrant:
@
fail
=
0
;
\
for
i
in
$(NON_REENTRANT)
;
\
do
\
grep
-nE
"
\<
$$
i
\>
[:space:]*
\(
"
$$
(
$(VC_LIST_EXCEPT)
)
&&
\
grep
-
-before
2
--after
1
-
nE
"
\<
$$
i
\>
[:space:]*
\(
"
$$
(
$(VC_LIST_EXCEPT)
)
&&
\
fail
=
1
&&
echo
"
$(ME)
: use
$
${i}
_r, not
$
${i}
"
||
:
;
\
done
;
\
exit
$$
fail
...
...
src/libvirt.c
浏览文件 @
c4985e94
...
...
@@ -21,6 +21,7 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#include <time.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
...
...
@@ -257,7 +258,8 @@ virInitialize(void)
initialized
=
1
;
if
(
virThreadInitialize
()
<
0
||
virErrorInitialize
()
<
0
)
virErrorInitialize
()
<
0
||
virRandomInitialize
(
time
(
NULL
)
^
getpid
()))
return
-
1
;
#ifdef ENABLE_DEBUG
...
...
@@ -332,23 +334,19 @@ DllMain (HINSTANCE instance ATTRIBUTE_UNUSED,
{
switch
(
reason
)
{
case
DLL_PROCESS_ATTACH
:
fprintf
(
stderr
,
"Initializing DLL
\n
"
);
virInitialize
();
break
;
case
DLL_THREAD_ATTACH
:
fprintf
(
stderr
,
"Thread start
\n
"
);
/* Nothing todo in libvirt yet */
break
;
case
DLL_THREAD_DETACH
:
fprintf
(
stderr
,
"Thread exit
\n
"
);
/* Release per-thread local data */
virThreadOnExit
();
break
;
case
DLL_PROCESS_DETACH
:
fprintf
(
stderr
,
"Process exit
\n
"
);
/* Don't bother releasing per-thread data
since (hopefully) windows cleans up
everything on process exit */
...
...
src/util.c
浏览文件 @
c4985e94
...
...
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
...
...
@@ -59,6 +60,7 @@
#include "buf.h"
#include "util.h"
#include "memory.h"
#include "threads.h"
#ifndef NSIG
# define NSIG 32
...
...
@@ -1285,9 +1287,9 @@ void virGenerateMacAddr(const unsigned char *prefix,
addr
[
0
]
=
prefix
[
0
];
addr
[
1
]
=
prefix
[
1
];
addr
[
2
]
=
prefix
[
2
];
addr
[
3
]
=
(
int
)(
256
*
(
rand
()
/
(
RAND_MAX
+
1
.
0
))
);
addr
[
4
]
=
(
int
)(
256
*
(
rand
()
/
(
RAND_MAX
+
1
.
0
))
);
addr
[
5
]
=
(
int
)(
256
*
(
rand
()
/
(
RAND_MAX
+
1
.
0
))
);
addr
[
3
]
=
virRandom
(
256
);
addr
[
4
]
=
virRandom
(
256
);
addr
[
5
]
=
virRandom
(
256
);
}
...
...
@@ -1436,6 +1438,36 @@ int virKillProcess(pid_t pid, int sig)
}
static
char
randomState
[
128
];
static
struct
random_data
randomData
;
static
virMutex
randomLock
;
int
virRandomInitialize
(
unsigned
int
seed
)
{
if
(
virMutexInit
(
&
randomLock
)
<
0
)
return
-
1
;
if
(
initstate_r
(
seed
,
randomState
,
sizeof
(
randomState
),
&
randomData
)
<
0
)
return
-
1
;
return
0
;
}
int
virRandom
(
int
max
)
{
int32_t
ret
;
virMutexLock
(
&
randomLock
);
random_r
(
&
randomData
,
&
ret
);
virMutexUnlock
(
&
randomLock
);
return
(
int
)
((
double
)
max
*
((
double
)
ret
/
(
double
)
RAND_MAX
));
}
#ifdef HAVE_GETPWUID_R
char
*
virGetUserDirectory
(
virConnectPtr
conn
,
uid_t
uid
)
...
...
src/util.h
浏览文件 @
c4985e94
...
...
@@ -177,4 +177,7 @@ char *virGetUserDirectory(virConnectPtr conn,
uid_t
uid
);
#endif
int
virRandomInitialize
(
unsigned
int
seed
);
int
virRandom
(
int
max
);
#endif
/* __VIR_UTIL_H__ */
src/uuid.c
浏览文件 @
c4985e94
...
...
@@ -35,6 +35,7 @@
#include "c-ctype.h"
#include "internal.h"
#include "util.h"
#define qemudLog(level, msg...) fprintf(stderr, msg)
...
...
@@ -74,9 +75,8 @@ static int
virUUIDGeneratePseudoRandomBytes
(
unsigned
char
*
buf
,
int
buflen
)
{
srand
(
time
(
NULL
));
while
(
buflen
>
0
)
{
*
buf
=
(
int
)
(
255
.
0
*
(
rand
()
/
(
double
)
RAND_MAX
)
);
*
buf
=
virRandom
(
256
);
buflen
--
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录