1) _GNU_SOURCE needs to be defined for strerror_r to work correctly in
libnpfs/error.c
2) After the error handling changes in utils, local errors are not
registered properly as xp_nodeerror takes into account errors returned
by the remote nodes only. This patch makes sure we return errors
correctly, local or remote.
Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>
Index: libnpfs/error.c
===================================================================
--- libnpfs/error.c (revision 693)
+++ libnpfs/error.c (working copy)
@@ -20,6 +20,7 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Index: utils/xgetent.c
===================================================================
--- utils/xgetent.c (revision 693)
+++ utils/xgetent.c (working copy)
@@ -72,7 +72,7 @@
exit(1);
}
-int read_pwent(Xpnode *node) {
+int read_pwent(Xpnode *node, void *cba) {
Spcfsys *fs;
Spcfid *fid;
char *buf;
@@ -91,6 +91,7 @@
return -1;
}
+ printf("\nPassword Database From Node: %s\n", node->name);
off = 0;
while ((n = spc_read(fid, (u8 *) buf, bufsize, off)) > 0) {
printf("%s", buf);
@@ -105,7 +106,7 @@
free(buf);
return ret;
}
-int read_grent(Xpnode *node) {
+int read_grent(Xpnode *node, void *cba) {
Spcfsys *fs;
Spcfid *fid;
char *buf;
@@ -123,7 +124,8 @@
spc_umount(fs);
return -1;
}
-
+
+ printf("\nGroup Database From Node: %s\n", node->name);
off = 0;
while ((n = spc_read(fid, (u8 *) buf, bufsize, off)) > 0) {
printf("%s", buf);
@@ -142,7 +144,7 @@
int
main(int argc, char **argv)
{
- int i, c, ecode, rc;
+ int c, ecode;
int allflag = 0;
char *ename, db[7];
Xpnodeset *nds, *nds2;
@@ -199,34 +201,27 @@
}
if (!nds)
- goto error;
+ goto lerror;
if (init_user() < 0)
- goto error;
+ goto lerror;
- rc = 0;
- printf("\n");
- for (i=0; i < nds->len; i++) {
- if (!strcmp("passwd", db)) {
- printf("Password Database From Node: %s\n",
- nds->nodes[i].name);
- rc = read_pwent(&nds->nodes[i]);
- }
- else {
- printf("Group Database From Node: %s\n",
- nds->nodes[i].name);
- rc = read_grent(&nds->nodes[i]);
- }
-
- printf("\n");
- if (rc)
- goto error;
+ if (!strcmp("passwd", db)) {
+ if (xp_nodeset_iterate(nds, read_pwent, NULL) > 0)
+ goto rerror;
+ } else {
+ if (xp_nodeset_iterate(nds, read_grent, NULL) > 0)
+ goto rerror;
}
+
+ return 0;
- exit(0);
-
- error:
+lerror:
sp_rerror(&ename, &ecode);
- fprintf(stderr, "Error: %s: %d\n", ename, ecode);
+ fprintf(stderr, "Error: %s\n", ename);
return 1;
+
+rerror:
+ xp_nodeerror_print(argv[0]);
+ return 1;
}
Index: utils/xgroupset.c
===================================================================
--- utils/xgroupset.c (revision 693)
+++ utils/xgroupset.c (working copy)
@@ -110,9 +110,9 @@
int
main(int argc, char **argv)
{
- int c;
+ int c, ecode;
char cmd[7];
- char *nodeset;
+ char *nodeset, *ename;
char *adminkeyfile = "/etc/xcpu/admin_key";
struct passwd *pw;
Xpnodeset *nds, *nds2;
@@ -157,7 +157,7 @@
adminkey = xauth_privkey_create(adminkeyfile);
if (!adminkey)
- goto error;
+ goto lerror;
setpwent();
while ((pw = getpwent()) != NULL) {
@@ -191,14 +191,19 @@
}
if (!nds)
- goto error;
+ goto lerror;
if (xp_nodeset_iterate(nds, setgroup, NULL) > 0)
- goto error;
+ goto rerror;
return 0;
-error:
+lerror:
+ sp_rerror(&ename, &ecode);
+ fprintf(stderr, "Error: %s\n", ename);
+ return 1;
+
+rerror:
xp_nodeerror_print(argv[0]);
return 1;
}
Index: utils/xuserset.c
===================================================================
--- utils/xuserset.c (revision 693)
+++ utils/xuserset.c (working copy)
@@ -149,9 +149,9 @@
int
main(int argc, char **argv)
{
- int c, fd, n;
+ int c, fd, n, ecode;
char *s, cmd[7];
- char *nodeset;
+ char *nodeset, *ename;
char *adminkeyfile = "/etc/xcpu/admin_key";
struct passwd *pw;
Xpnodeset *nds, *nds2;
@@ -196,13 +196,13 @@
fd = open(argv[optind], O_RDONLY);
if (fd < 0) {
sp_suerror(argv[optind-1], errno);
- goto error;
+ goto lerror;
}
n = read(fd, userkey, sizeof(userkey) - 1);
if (n < 0) {
sp_uerror(errno);
- goto error;
+ goto lerror;
}
s = strchr(userkey, '\n');
if (s)
@@ -214,7 +214,7 @@
}
adminkey = xauth_privkey_create(adminkeyfile);
if (!adminkey)
- goto error;
+ goto lerror;
setpwent();
while ((pw = getpwent()) != NULL) {
@@ -247,14 +247,19 @@
nds = xp_nodeset_from_string(nodeset);
}
if (!nds)
- goto error;
+ goto lerror;
if (xp_nodeset_iterate(nds, setuser, NULL) > 0)
- goto error;
+ goto rerror;
return 0;
+
+lerror:
+ sp_rerror(&ename, &ecode);
+ fprintf(stderr, "Error: %s\n", ename);
+ return 1;
-error:
+rerror:
xp_nodeerror_print(argv[0]);
return 1;
}