author | Lucy Wang <xiu-yan.wang@oracle.com> |
Mon, 08 Oct 2012 11:10:16 -0700 | |
branch | s11-sru |
changeset 2369 | dcf1e4110247 |
permissions | -rw-r--r-- |
2369
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
1 |
--- ipmitool-1.8.10.old/lib/helper.c Fri Dec 14 12:56:53 2007 |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
2 |
+++ ipmitool-1.8.10/lib/helper.c Mon Oct 1 15:17:37 2012 |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
3 |
@@ -289,19 +289,33 @@ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
4 |
{ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
5 |
struct stat st1, st2; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
6 |
FILE * fp; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
7 |
+ int fd = -1; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
8 |
|
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
9 |
/* verify existance */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
10 |
+ errno = 0; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
11 |
if (lstat(file, &st1) < 0) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
12 |
- if (rw) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
13 |
+ if (rw && (errno == ENOENT)) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
14 |
/* does not exist, ok to create */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
15 |
- fp = fopen(file, "w"); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
16 |
- if (fp == NULL) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
17 |
+ fd = open(file, |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
18 |
+ O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
19 |
+ | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
20 |
+ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
21 |
+ if ( fd == -1 ) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
22 |
lperror(LOG_ERR, "Unable to open file %s " |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
23 |
"for write", file); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
24 |
return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
25 |
} |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
26 |
- /* created ok, now return the descriptor */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
27 |
- return fp; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
28 |
+ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
29 |
+ fp = fdopen(fd, "w"); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
30 |
+ if (fp == NULL) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
31 |
+ close(fd); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
32 |
+ lperror(LOG_ERR, "Unable to open file %s " |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
33 |
+ "for write", file); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
34 |
+ return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
35 |
+ } else |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
36 |
+ /* created ok, now return the descriptor */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
37 |
+ return fp; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
38 |
+ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
39 |
} else { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
40 |
lprintf(LOG_ERR, "File %s does not exist", file); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
41 |
return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
42 |
@@ -322,7 +336,7 @@ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
43 |
|
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
44 |
/* it exists - only regular files, not links */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
45 |
if (S_ISREG(st1.st_mode) == 0) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
46 |
- lprintf(LOG_ERR, "File %s has invalid mode: %d", |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
47 |
+ lprintf(LOG_ERR, "File %s has invalid mode: %#o", |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
48 |
file, st1.st_mode); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
49 |
return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
50 |
} |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
51 |
@@ -347,10 +361,18 @@ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
52 |
return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
53 |
} |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
54 |
|
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
55 |
+ /* verify dev */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
56 |
+ if (st1.st_dev != st2.st_dev) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
57 |
+ lprintf(LOG_ERR, "File %s has invalid dev: %lu != %lu", |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
58 |
+ file, (ulong_t)st1.st_dev, (ulong_t)st2.st_dev); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
59 |
+ fclose(fp); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
60 |
+ return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
61 |
+ } |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
62 |
+ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
63 |
/* verify inode */ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
64 |
if (st1.st_ino != st2.st_ino) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
65 |
- lprintf(LOG_ERR, "File %s has invalid inode: %d != %d", |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
66 |
- file, st1.st_ino, st2.st_ino); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
67 |
+ lprintf(LOG_ERR, "File %s has invalid inode: %lu != %lu", |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
68 |
+ file, (ulong_t)st1.st_ino, (ulong_t)st2.st_ino); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
69 |
fclose(fp); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
70 |
return NULL; |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
71 |
} |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
72 |
@@ -427,7 +449,6 @@ |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
73 |
#endif |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
74 |
|
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
75 |
chdir("/"); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
76 |
- umask(0); |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
77 |
|
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
78 |
for (fd=0; fd<64; fd++) { |
dcf1e4110247
7126312 Problem with utility/ipmitool
Lucy Wang <xiu-yan.wang@oracle.com>
parents:
diff
changeset
|
79 |
if (fd != intf->fd) |