File: error.c

package info (click to toggle)
lfc-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,676 kB
  • ctags: 10,779
  • sloc: ansic: 146,136; sh: 13,176; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 861; fortran: 113
file content (206 lines) | stat: -rw-r--r-- 5,337 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * $Id: error.c,v 1.1 2005/03/31 13:13:00 baud Exp $
 */

/*
 * Copyright (C) 1990-2004 by CERN-IT
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: error.c,v $ $Revision: 1.1 $ $Date: 2005/03/31 13:13:00 $ CERN/IT/PDP/DM Frederic Hemmer";
#endif /* not lint */

/* error.c      Remote File I/O - error numbers and message handling    */

/*
 * System remote file I/O definitions
 */
#define RFIO_KERNEL     1 
#include <Castor_limits.h>
#include "rfio.h"
#include <Cglobals.h>
#include <rfio_errno.h>

/*
 * RFIO global error number.
 */

char *rfio_lasthost() ;
char *rfio_serror() ;

/*
 * Get remote error string corresponding to code.
 */
char DLL_DECL *rfio_errmsg_r (s, code, buf, buflen)   
int     s;
int     code;
char 	*buf;
size_t 	buflen;
{
   char   *p;
   LONG   len;
   char msg[CA_MAXLINELEN+1];
   char rfio_buf[CA_MAXLINELEN+1];

   if( buf == NULL || buflen <=0 ) return NULL;
   memset(buf, '\0', buflen);
   
   INIT_TRACE("RFIO_TRACE");
   TRACE(1, "rfio", "rfio_errmsg(%d, %d)",s,code) ;
   p= rfio_buf ;
   marshall_WORD(p, RFIO_MAGIC);
   marshall_WORD(p, RQST_ERRMSG);
   marshall_LONG(p, code);
   TRACE(2,"rfio","rfio_errmsg: sending %d bytes",RQSTSIZE) ;
   if (netwrite_timeout(s,rfio_buf,RQSTSIZE,RFIO_CTRL_TIMEOUT) != RQSTSIZE)  {
      TRACE(2, "rfio" ,"rfio_errmsg: write(): ERROR occured (errno=%d)", errno);
      END_TRACE();
      return((char *) NULL);
   }
   TRACE(2, "rfio", "rfio_errmsg: reading %d bytes", LONGSIZE);
   if (netread_timeout(s,rfio_buf, LONGSIZE, RFIO_CTRL_TIMEOUT) != LONGSIZE) {
      TRACE(2, "rfio" ,"rfio_errmsg: read(): ERROR occured (errno=%d)", errno);
      END_TRACE();
      return((char *) NULL);
   }
   p = rfio_buf ;
   unmarshall_LONG(p, len);
   TRACE(2, "rfio", "rfio_errmsg: reading %d bytes", len);
   if (netread_timeout(s,rfio_buf,len,RFIO_CTRL_TIMEOUT) != len) {
      TRACE(2, "rfio" ,"rfio_errmsg: read(): ERROR occured (errno=%d)", errno);
      END_TRACE();
      return((char *) NULL);
   }
   p= rfio_buf;
   unmarshall_STRINGN(p, msg, CA_MAXLINELEN+1);
   TRACE(1, "rfio", "rfio_errmsg: <%s>", msg);
   END_TRACE();
   strcpy(buf, msg);
   return(buf);
}

static int rfio_error_key = -1;

char DLL_DECL *rfio_errmsg(s, code) 
int     s;
int     code;
{
   char *buf = NULL;
   int buflen = CA_MAXLINELEN+1;

   Cglobals_get(&rfio_error_key, (void **)&buf, buflen);
   return(rfio_errmsg_r(s, code, buf, buflen));
}


char DLL_DECL *rfio_serror_r(buf, buflen)   /* print an error message  */
char *buf;
size_t buflen;   
{
   int          s;
   int		last_rferr ; 	/* to preserve rfio_errno 		*/
   int		last_err ; 	/* to preserve errno 			*/
   int          last_serrno ;   /* to preserve serrno                   */
   int 		rt ;		/* Request is from other network?  	*/
   char 	*rferrmsg ;
   char 	rerrlist[CA_MAXLINELEN+1] ; /* Message from errlist 		*/

   if( buf == NULL || buflen <=0 ) return NULL;
   memset(buf, '\0', buflen);

   INIT_TRACE("RFIO_TRACE");
   last_err = errno ;
   last_rferr = rfio_errno ;
   last_serrno = serrno ;
   TRACE(2, "rfio", "rfio_serror: errno=%d, serrno=%d, rfio_errno=%d",
	 errno, serrno, rfio_errno);
   END_TRACE();
   if (last_serrno != 0) {
      return (  sstrerror(serrno) );
   }
   else    {
      if (last_rferr != 0)        {
	 if ((s=rfio_connect(rfio_lasthost(),&rt)) == -1)  {
	    sprintf(rerrlist,"Unable to fetch remote error %d",last_rferr);
	    rfio_errno = last_rferr ;
	    strcpy(buf, rerrlist);
	    return (buf);
	 }
	 else    {
	    if ( (rferrmsg = rfio_errmsg(s,last_rferr)) != NULL )
	       sprintf(rerrlist, "%s (error %d on %s)", rferrmsg, last_rferr, rfio_lasthost());
	    else
	       sprintf(rerrlist, " (error %d on %s)", last_rferr, rfio_lasthost());
	    netclose(s);
	    rfio_errno = last_rferr ;
	    strcpy(buf, rerrlist);
	    return (buf);
	 }
      }
      else    {
	 if (serrno != 0)  {
	    strcpy( buf, sstrerror(serrno));
	    return (buf);
	 }
	 else {
	    strcpy(buf, strerror(last_err));
	    return (buf);
	 }
      }
   }
}

int DLL_DECL rfio_serrno()   /* get error number - return -1 if cannot get it */
{
   int          s;
   int		last_rferr ; 	/* to preserve rfio_errno 		*/
   int		last_err ; 	/* to preserve errno 			*/
   int          last_serrno ;   /* to preserve serrno                   */
   int 		rt ;		/* Request is from other network?  	*/

   INIT_TRACE("RFIO_TRACE");
   last_err = errno ;
   last_rferr = rfio_errno ;
   last_serrno = serrno ;
   TRACE(2, "rfio", "rfio_serrno: errno=%d, serrno=%d, rfio_errno=%d",
	 errno, serrno, rfio_errno);
   END_TRACE();
   if (last_serrno != 0) {
     return (serrno);
   } else {
     if (last_rferr != 0) {
       rfio_errno = last_rferr ;
       return (rfio_errno);
     } else {
       if (serrno != 0)  {
         return (serrno);
       } else {
         return (last_err);
       }
     }
   }
}

static int rfio_serror_key = -1;

char DLL_DECL *rfio_serror() 
{
   char *buf = NULL;
   int buflen = CA_MAXLINELEN+1;

   Cglobals_get(&rfio_serror_key, (void **)&buf, buflen);
   return(rfio_serror_r(buf, buflen));
}


void DLL_DECL rfio_perror(umsg)
char *umsg ;
{
   char *errmsg ;
   errmsg =  rfio_serror();
   if (errmsg != NULL ) 
      fprintf(stderr,"%s : %s\n",umsg, errmsg);
   else
      fprintf(stderr,"%s : No error message\n",umsg);
}