serror.cpp 19.6 KB
Newer Older
1
/*
2
 * Copyright (C) 1990-2002 by CERN/IT/PDP/DM
3
4
5
 * All rights reserved
 */

6
7
8
9
10
11
12
/*
 * Undefine _GNU_SOURCE and set _XOPEN_SOURCE to 600 so that the POSIX
 * version of strerror_r() will be used
 */
#undef _GNU_SOURCE
#define _XOPEN_SOURCE 600

13
/* serror.c     Global error reporting routines                         */
14
15
#include "h/serrno.h"   /* special error numbers and codes              */
#include "h/Cglobals.h"
16
17
18
19
20
21

#include <stdio.h>      /* standard input/output                        */
#include <errno.h>      /* error numbers and codes                      */

#include <string.h>

22
#if !defined(linux)
23
24
25
extern int      sys_nerr;       /* number of system error messages      */
#endif

26
const char *sys_serrlist[SEMAXERR-SEBASEOFF+2]=
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
  {"Error 0",
   "Host not known",
   "Service unknown",
   "Not a remote file",
   "Timed out",
   "Unsupported FORTRAN format",
   "Unknown FORTRAN option",
   "Incompatible FORTRAN options",
   "File name too long",
   "Can't open configuration file",
   "Version ID mismatch",
   "User buffer too small",
   "Invalid reply number",
   "User message too long",
   "Entry not found",
   "Internal error",
   "Connection closed by remote end",
   "Can't find interface name",
   "Communication error",
   "Can't open mapping database",
   "No user mapping",
   "Retry count exhausted",
   "Operation not supported",
   "Resource temporarily unavailable",
   "Operation now in progress",
   "Cthread initialization error",
   "Thread interface call error",
   "System error",
55
56
57
58
   "deprecated error",
   "deprecated error",
   "deprecated error",
   "deprecated error",
59
60
61
62
63
64
   "requestor is not administrator",
   "User unknown",
   "Duplicate key value",
   "Entry already exists",
   "Group unknown",
   "Bad checksum",
65
   "This service class is not available for this host",
66
67
   "Got SQL exception from database",
   "Too many symbolic links",
68
69
   "No port in range",
   "No value",
70
   "Invalid configuration",
71
   "Failed to execute Python",
72
   "Missing operand",
73
   "Mismatch",
74
   "Request failed",
75
   "Invalid number of arguments",
Steven Murray's avatar
Steven Murray committed
76
   "Already initialized",
77
   "Command line not parsed",
78
79
   "Accept connection was interrupted",
   "Failed to allocate memory",
80
   "Not an owner",
81
82
   "BAD ERROR NUMBER"
  };
Dennis Waldron's avatar
Dennis Waldron committed
83

84
85
86
87
88
89
90
91
92
/*
 * Package specific error messages (don't forget to update h/serrno.h)
 */

/*
 *------------------------------------------------------------------------
 * DB specific error messages
 *------------------------------------------------------------------------
 */
93
const char *sys_dberrlist[EDBMAXERR-EDBBASEOFF+2] =
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
  {"Error 0",
   "Cdb api : invalid Cdb_sess_t parameter",
   "Cdb api : invalid Cdb_db_t parameter",
   "Cdb api : invalid value",
   "Cdb api : Cdb server hostname resolution error (Cgethostbyname)",
   "Cdb api : data size rejected (exceeds theorical value)",
   "Cdb api system : socket() error",
   "Cdb api system : [set/get]sockopt() error",
   "Cdb api system : malloc() error",
   "Cdb api        : no last error",
   "Cdb api : interface invalid value",
   "Cdb api system : bind() error",
   "Cdb api system : listen() error",
   "Cdb api system : getsockname() error",
   "Cdb api system : accept() error",
   "Cdb api system : getpeername() error",
   "Cdb api : connection back from bad host",
   "Error 17",
   "Error 18",
   "Error 19",
   "Cdb daemon : invalid value",
   "Cdb daemon : yet done",
   "Cdb daemon : unauthorized",
   "Cdb daemon : login refused",
   "Cdb daemon : password file corrupted",
   "Cdb daemon : database description analysis error",
   "Cdb daemon : bad hash size",
   "Cdb daemon : unknown database/table/key",
   "Cdb daemon : a lock is required",
   "Cdb daemon : datatabase (probably) corrupted",
   "Cdb daemon : data size rejected (exceeds theorical value)",
   "Cdb daemon : no entry",
   "Cdb daemon : unknown record member type",
   "Cdb daemon : unknown record member val",
   "Cdb daemon : null record member value",
   "Cdb daemon : lock deny",
   "Cdb daemon : attempt to free something Cdb claims it is of zero size",
   "Cdb daemon : shutdown in progress",
   "Cdb daemon : deadlock detected",
   "Cdb daemon : yet exists",
   "Cdb daemon : no more space",
   "Cdb daemon : end of dump",
   "Cdb daemon : uniqued key yet exists",
   "Cdb daemon : end of list",
   "Cdb daemon : not in dump mode",
   "Cdb daemon : double DNS check error",
   "Cdb daemon : Connection rejected (not authorised)",
   "Cdb daemon : init in progress",
   "Cdb daemon : inconsistent request (unstop and no previous stop, unfreeze and no previous freeze)",
   "Cdb daemon : bad free hash size",
   "Cdb daemon system : malloc() error",
   "Cdb daemon system : calloc() error",
   "Cdb daemon system : realloc() error",
   "Cdb daemon system : open() error",
   "Cdb daemon system : fstat() error",
   "Cdb daemon system : lseek() error",
   "Cdb daemon system : read() error",
   "Cdb daemon system : write() error",
   "Cdb daemon system : rename() error",
   "Cdb daemon system : ftruncate() error",
   "Cdb daemon system : tmpnam() error",
   "Cdb daemon system : fcntl() error",
   "Cdb daemon system : mkdir() error",
   "Cdb daemon system : times() error",
   "Cdb daemon system : sysconf() err/unav",
   "Cdb daemon system : Cdb client hostname resolution error (Cgethostbyname)",
   "Cdb daemon system : getpeername() error",
   "Cdb daemon system : inet_ntoa() error",
   "Cdb daemon system : remove() error",
   "Cdb daemon system : sigaction() error",
   "Cdb daemon system : getsockname() error",
   "Cdb daemon system : bind() error",
   "Cdb daemon system : listen() error",
   "Cdb daemon system : connect() error",
   "Cdb daemon system : socket() error",
   "Cdb daemon system : [set/get]socketopt() error",
   "Cdb daemon : Host resolution error",
   "Cdb daemon : Request too big",
   "Error 78",
   "Error 79",
   "Cdb config : invalid configuration value",
   "Cdb config : configuration error",
   "Cdb config : configuration value rejected (exceeds maximum size)",
   "Cdb config system : gethostname() error",
   "Error 84",
   "Error 85",
   "Error 86",
   "Error 87",
   "Error 88",
   "Error 89",
   "Cdb : nomoredb",
   "BAD ERROR NUMBER"
  };
187
188
189
190
191
192

/*
 *------------------------------------------------------------------------
 * MSG daemon specific error messages
 *------------------------------------------------------------------------
 */
193
const char *sys_mserrlist[EMSMAXERR-EMSBASEOFF+2] =
194
195
196
197
198
199
  {"Error 0",
   "Message daemon unable to reply",
   "Message daemon system error",
   "Permission denied",
   "BAD ERROR NUMBER"
  };
200
201
202
203
204
205

/*
 *------------------------------------------------------------------------
 * NS (Name Server) specific error messages
 *------------------------------------------------------------------------
 */
206
const char *sys_nserrlist[ENSMAXERR-ENSBASEOFF+2] =
207
208
  {"Error 0",
   "Name server not active",
209
   "File has been overwritten, request ignored",
210
   "Segment had been deleted",
211
   "Is a link",
212
213
   "File class does not allow a copy on tape",
   "Too many copies on tape",
214
   "Cannot overwrite valid segment when replacing",
215
216
   "BAD ERROR NUMBER"
  };
217
218
219
220
221
222

/*
 *------------------------------------------------------------------------
 * RFIO specific error messages
 *------------------------------------------------------------------------
 */
223
const char *sys_rferrlist[ERFMAXERR-ERFBASEOFF+2] =
224
225
226
227
228
229
230
  {"Error 0",
   "Host did not return error number",
   "Host is not on local network and no mapping found",
   "Cannot create linked file across hosts",
   "Protocol not supported",
   "BAD ERROR NUMBER"
  };
231
232
233
234
235
236

/*
 *------------------------------------------------------------------------
 * RTCOPY specific error messages
 *------------------------------------------------------------------------
 */
237
const char *sys_rterrlist[ERTMAXERR-ERTBASEOFF+2] =
238
239
240
241
242
243
244
245
246
247
248
249
250
  {"Error 0",
   "TMS error",
   "Blocks skipped in file",
   "Blocks skipped and file limited by size",
   "Too many skipped blocks",
   "File limited by size",
   "Request interrupted by user",
   "Request interrupted by operator",
   "Request list is not circular",
   "Bad request structure",
   "Request partially processed",
   "Catalogue DB error",
   "Zero sized file",
251
   "Recalled file size incorrect",
252
   "Inconsistent FSEQ in VMGR and Cns",
253
254
   "BAD ERROR NUMBER"
  };
255
256
257
258
259
260

/*
 *------------------------------------------------------------------------
 * STAGE specific error messages
 *------------------------------------------------------------------------
 */
261
const char *sys_sterrlist[ESTMAXERR-ESTBASEOFF+2] =
262
  {"Error 0",
263
   "Aborted",
264
265
266
267
268
269
270
271
272
273
274
275
276
277
   "Enough free space",
   "Symbolic link not created",
   "Symbolic link not supported",
   "Stager not active",
   "Your group is invalid",
   "No GRPUSER in configuration",
   "Invalid user",
   "HSM HOST not specified",
   "tmscheck error",
   "User link name processing error",
   "User path in a non-writable directory",
   "Request killed",
   "Request too long (socket buffer size)",
   "Stage configuration error",
278
   "Unreadable file on tape (segments not all accessible)",
279
   "File replication failed",
280
   "File is currently not available",
281
282
283
   "Job killed by service administrator",
   "Job timed out while waiting to be scheduled",
   "Scheduler error",
284
   "No filesystems available in service class",
285
   "File has no copy on tape and no diskcopies are accessible",
286
   "File is on an offline tape",
287
   "Request canceled while queuing",
288
   "Tape-copy not found",
289
   "The file cannot be routed to tape",
290
291
   "BAD ERROR NUMBER"
  };
292
293
294
295
296
297

/*
 *------------------------------------------------------------------------
 * SYSREQ specific error messages
 *------------------------------------------------------------------------
 */
298
const char *sys_sqerrlist[ESQMAXERR-ESQBASEOFF+2] =
299
300
301
302
  {"Error 0",
   "TMS not active",
   "BAD ERROR NUMBER"
  };
303
304
305
306
307
308

/*
 *------------------------------------------------------------------------
 * TAPE specific error messages
 *------------------------------------------------------------------------
 */
309
const char *sys_terrlist[ETMAXERR-ETBASEOFF+2] =
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
  {"Error 0",
   "Tape daemon not available",
   "System error",
   "Bad parameter",
   "Reserve already issued",
   "Too many drives requested",
   "Invalid device group name",
   "Reserve not done",
   "No drive with requested name/characteristics",
   "Bad label structure",
   "Bad file sequence number",
   "Interrupted by user",
   "EOV found in multivolume set",
   "Release pending",
   "Blank tape",
   "Compatibility problem",
   "Device malfunction",
   "Parity error",
   "Unrecoverable media error",
   "No sense",
   "Reselect server",
   "Volume busy or inaccessible",
   "Drive currently assigned",
   "Drive not ready",
   "Volume absent",
   "Volume archived",
   "Volume held or disabled",
   "File not expired",
   "Operator cancel",
   "Volume unknown",
   "Wrong label type",
   "Cartridge write protected",
   "Wrong vsn",
   "Tape has a bad MIR",
344
   "castor::tape::net::acceptConnection interrupted",
345
346
   "Label information not found in memory",
   "Multi-drive reservations are not supported",
347
   "No memory available for label information",
348
349
350
   "Tape-session error",
   "Invalid tape-file sequence-number",
   "Invalid tape-file file-size",
351
352
   "Failed to mount volume",
   "Failed to dismount volume",
353
   "Failed to query volume",
354
355
   "BAD ERROR NUMBER"
  };
356
357
358
359
360
361

/*
 *------------------------------------------------------------------------
 * VAL (Volume Allocator) specific error messages
 *------------------------------------------------------------------------
 */
362
const char *sys_vaerrlist[EVMMAXERR-EVMBASEOFF+2] =
363
364
  {"Error 0",
   "Volume manager not active",
365
   "VMGR HOST not set",
366
367
   "BAD ERROR NUMBER"
  };
368
369
370
371
372
373

/*
 *------------------------------------------------------------------------
 * UPV (User Privilege Validator) specific error messages
 *------------------------------------------------------------------------
 */
374
const char *sys_uperrlist[EUPMAXERR-EUPBASEOFF+2] =
375
376
377
378
  {"Error 0",
   "UPV not active",
   "BAD ERROR NUMBER"
  };
379
380


381
382
383
384
385
/*
 *------------------------------------------------------------------------
 * DNS specific error messages
 *------------------------------------------------------------------------
 */
386
const char *sys_dnserrlist[EDNSMAXERR-EDNSBASEOFF+2] =
387
388
389
390
391
392
393
394
  {"Error 0",
   "The specified host is unknown",
   "A temporary error occurred on an authoritative name server.  Try again later",
   "A non-recoverable name server error occurred",
   "The requested name is valid but does not have an IP address",
   "The requested name is valid but does not have an IP address",
   "BAD ERROR NUMBER"
  };
395

396
397
398
399
400
/*
 *------------------------------------------------------------------------
 * VDQM (Volume & Drive Queue Manager) specific error messages
 *------------------------------------------------------------------------
 */
401
const char *sys_vqerrlist[EVQMAXERR-EVQBASEOFF+2] =
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
  {"Error 0",
   "Failed system call",
   "Internal DB inconsistency",
   "DB replication failed",
   "No volume request queued",
   "No free drive available",
   "Specified vol. req. not found",
   "Specified drv. req. not found",
   "Specified vol. req. already exists",
   "Unit not up",
   "Bad unit status request",
   "Incorrect vol.req or job ID",
   "Incorrect job ID",
   "Unit not assigned",
   "Attempt to mount with wrong VOLID",
   "Attempt to delete an assigned request",
   "Request for non-existing DGN",
   "Replication pipe is full",
   "Server is held",
   "End of query reached",
   "BAD ERROR NUMBER"
  };
424
425
426
427
428
429

/*
 *------------------------------------------------------------------------
 * RMC (Remote SCSI Media Changer server) specific error messages
 *------------------------------------------------------------------------
 */
430
const char *sys_rmerrlist[ERMMAXERR-ERMBASEOFF+2] =
431
432
433
434
435
436
437
438
439
440
441
442
  {"Error 0",
   "Remote SCSI media changer server not active",
   "Remote SCSI media changer error",
   "Remote SCSI media changer unrec. error",
   "Remote SCSI media changer error (slow retry)",
   "Remote SCSI media changer error (fast retry)",
   "Remote SCSI media changer error (demount force)",
   "Remote SCSI media changer error (drive down)",
   "Remote SCSI media changer error (ops message)",
   "Remote SCSI media changer error (ops message + retry)",
   "Remote SCSI media changer error (ops message + wait)",
   "Remote SCSI media changer error (unload + demount)",
443
   "Unknown drive-loader type",
444
445
446
   "VID is too long",
   "Failed to parse RMC host",
   "Failed to parse ACS drive id",
447
448
   "BAD ERROR NUMBER"
  };
449
450
451
452
453
454

/*
 *------------------------------------------------------------------------
 * Monitor specific error messages
 *------------------------------------------------------------------------
 */
455
const char *sys_monerrlist[EMONMAXERR - EMONBASEOFF +2] =
456
457
458
459
460
461
462
  {"Error 0",
   "System Error",
   "Monitor Host not specified",
   "Monitor Port not specified",
   "Client port not specified",
   "BAD ERROR NUMBER"
  };
463
464
465
466
467
468

/*
 *------------------------------------------------------------------------
 * Security package errors
 *------------------------------------------------------------------------
 */
469
const char *sys_secerrlist[ESECMAXERR-ESECBASEOFF+2] =
470
471
472
473
474
475
476
477
478
479
  {"Error 0",
   "System error",
   "Bad credentials",
   "Could not establish context",
   "Bad magic number",
   "Could not map username to uid/gid",
   "Could not map principal to username",
   "Could not load security mechanism",
   "Context not initialized",
   "Security protocol not supported",
480
   "Service name not set",
481
482
483
484
485
486
   "Service type not set",
   "Could not lookup security protocol",
   "Csec incompatibility",
   "Unexpected response from peer",
   "BAD ERROR NUMBER"
  };
487
488
489
490
491
492
493

/*
 *------------------------------------------------------------------------
 * End of package specific error messages
 *------------------------------------------------------------------------
 */

494
int sstrerror_r(const int n, char *const buf, const size_t buflen) {
495
  const char *tmpstr;
496
  char strerror_r_buf[100];
497
498
499
500
501
502
503

  if ( buf == NULL || buflen <= 0 ) {
    errno = EINVAL;
    serrno = EINVAL;
    return -1;
  }

504
505
506
  memset(buf,'\0',buflen);
  tmpstr = NULL;

Dennis Waldron's avatar
Dennis Waldron committed
507
  if ((n>SEBASEOFF) && (n<=SEMAXERR)) {
508
509
510
511
    /*
     * COMMON error messages
     */
    tmpstr = sys_serrlist[n-SEBASEOFF];
Dennis Waldron's avatar
Dennis Waldron committed
512
  } else if ((n>EDBBASEOFF) && (n<=EDBMAXERR)) {
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
    /*
     * DB specific error messages
     */
    tmpstr = sys_dberrlist[n-EDBBASEOFF];
  } else if ((n>EMSBASEOFF) && (n<=EMSMAXERR)) {
    /*
     * MSG specific error messages
     */
    tmpstr = sys_mserrlist[n-EMSBASEOFF];
  } else if ((n>ENSBASEOFF) && (n<=ENSMAXERR)) {
    /*
     * NS (Name server) specific error messages
     */
    tmpstr = sys_nserrlist[n-ENSBASEOFF];
  } else if ((n>ERFBASEOFF) && (n<=ERFMAXERR)) {
    /*
     * RFIO specific error messages
     */
    tmpstr = sys_rferrlist[n-ERFBASEOFF];
  } else if ((n>ERTBASEOFF) && (n<=ERTMAXERR)) {
    /*
     * RTCOPY specific error messages
     */
    tmpstr = sys_rterrlist[n-ERTBASEOFF];
  } else if ((n>ESTBASEOFF) && (n<=ESTMAXERR)) {
    /*
     * STAGE specific error messages
     */
    tmpstr = sys_sterrlist[n-ESTBASEOFF];
  } else if ((n>ESQBASEOFF) && (n<=ESQMAXERR)) {
    /*
     * SYSREQ specific error messages
     */
    tmpstr = sys_sqerrlist[n-ESQBASEOFF];
  } else if ((n>ETBASEOFF) && (n<=ETMAXERR)) {
    /*
     * TAPE specific error messages
     */
    tmpstr = sys_terrlist[n-ETBASEOFF];
  } else if ((n>EVMBASEOFF) && (n<=EVMMAXERR)) {
    /*
     * VMGR (Volume manager) specific error messages
     */
    tmpstr = sys_vaerrlist[n-EVMBASEOFF];
  } else if ((n>EUPBASEOFF) && (n<=EUPMAXERR)) {
    /*
     * UPV specific error messages
     */
    tmpstr = sys_uperrlist[n-EUPBASEOFF];
  } else if ((n>EDNSBASEOFF) && (n<=EDNSMAXERR)) {
    /*
     * DNS specific error messages
     */
    tmpstr = sys_dnserrlist[n-EDNSBASEOFF];
  } else if ((n>EVQBASEOFF) && (n<=EVQMAXERR)) {
    /*
     * VDQM (Volume & Drive Queue Manager) specific error messages
     */
    tmpstr = sys_vqerrlist[n-EVQBASEOFF];
  } else if ((n>ERMBASEOFF) && (n<=ERMMAXERR)) {
    /*
     * RMC (Remote SCSI media changer server) specific error messages
     */
    tmpstr = sys_rmerrlist[n-ERMBASEOFF];
  } else if ((n>EMONBASEOFF) && (n<=EMONMAXERR)) {
    /*
     * Monitor specific error messages
     */
    tmpstr = sys_monerrlist[n-EMONBASEOFF];
  } else if ((n>ESECBASEOFF) && (n<=ESECMAXERR)) {
    /*
     * Security specific error messages
     */
    tmpstr = sys_secerrlist[n-ESECBASEOFF];
  } else if ((n>0)
588
#ifndef linux
589
             && (n<sys_nerr)
590
#endif
591
592
593
             ) {
    /*
     * SYSTEM error messages
594
595
596
597
     *
     * Note: Explicitly store the result of strerror_r into an integer in order
     * to make sure the XSI-compliant version is being used.  The GNU version
     * returns a pointer to char.
598
     */
599
600
601
602
603
604
605
606
    const int strerror_r_rc =
      strerror_r(n, strerror_r_buf, sizeof(strerror_r_buf));
    if(strerror_r_rc) {
      tmpstr = "Unknown error because call to strerror_r failed";
    } else {
      tmpstr = strerror_r_buf;
    }
    
607
608
609
  }

  if ( tmpstr != NULL ) {
610
    strncpy(buf,tmpstr,buflen-1);
611
612
613
614
  } else {
    /*
     * Unknown error message
     */
615
    sprintf(buf, "%*s: %10d", (int)buflen-14, sys_serrlist[SEMAXERR+1-SEBASEOFF], n);
616
  }
617
  return 0;
618
619
}

620
void sperror(char    *msg)
621
622
623
{
  char buf[80];
  if (serrno)     {
624
625
626
627
628
629
630
    if(sstrerror_r(serrno, buf, sizeof(buf))) {
      /* sstrerror_r() failed so just print msg */
      fprintf(stderr,"%s\n",msg);
    } else {
      /* sstrerror_r() succeeded so print both msg and buf */
      fprintf(stderr,"%s: %s\n", msg, buf);
    }
631
632
633
  } else    {
    perror(msg);
  }
634
635
636
637
}

static int sstrerror_key = -1;

638
const char *sstrerror(const int n) {
639
  void *buf = NULL;
640
  int buflen = 80;
641

642
643
644
645
646
647
648
649
650
651
652
653
  if(Cglobals_get(&sstrerror_key, &buf, buflen)) {
    return "Unknown error"
      ": No thread specific memory to determine error string"
      ": Cglobals_get() failed";
  }

  if(sstrerror_r(n,(char *)buf,buflen)) {
    return "Unknown error"
      ": sstrerror_r() failed";
  } else {
    return (char *)buf;
  }
654
}