Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c37dac

Browse files
author
Michael Paquier
committed
Sanitize error checks
All the ERROR_* fields are removed in favor of a more simple layermade of ERROR, FATAL, PANIC. The two last ones are not actually usedyet, thought there should be some code paths that would need morepolishing on this matter.The error message emitted before leaving should be fine to let theuser know what is happening.
1 parent3a9cc02 commit5c37dac

File tree

20 files changed

+164
-196
lines changed

20 files changed

+164
-196
lines changed

‎backup.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
7575

7676
/* Block backup operations on a standby */
7777
if (pg_is_standby())
78-
elog(ERROR_SYSTEM,"Backup cannot run on a standby.");
78+
elog(ERROR,"Backup cannot run on a standby.");
7979

8080
elog(INFO,"database backup start");
8181

@@ -102,7 +102,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
102102

103103
prev_backup=catalog_get_last_data_backup(backup_list,current.tli);
104104
if (prev_backup==NULL)
105-
elog(ERROR_SYSTEM,"Valid full backup not found for "
105+
elog(ERROR,"Valid full backup not found for "
106106
"differential backup. Either create a full backup "
107107
"or validate existing one.");
108108
}
@@ -123,7 +123,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
123123
{
124124
elog(LOG,"backup_label does not exist, stopping backup");
125125
pg_stop_backup(NULL);
126-
elog(ERROR_SYSTEM,"backup_label does not exist in PGDATA.");
126+
elog(ERROR,"backup_label does not exist in PGDATA.");
127127
}
128128

129129
/*
@@ -138,12 +138,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
138138
pgBackupGetPath(&current,path,lengthof(path),MKDIRS_SH_FILE);
139139
fp=fopen(path,"wt");
140140
if (fp==NULL)
141-
elog(ERROR_SYSTEM,"can't open make directory script \"%s\": %s",
141+
elog(ERROR,"can't open make directory script \"%s\": %s",
142142
path,strerror(errno));
143143
dir_print_mkdirs_sh(fp,backup_files_list,pgdata);
144144
fclose(fp);
145145
if (chmod(path,DIR_PERMISSION)==-1)
146-
elog(ERROR_SYSTEM,"can't change mode of \"%s\": %s",path,
146+
elog(ERROR,"can't change mode of \"%s\": %s",path,
147147
strerror(errno));
148148
}
149149

@@ -255,12 +255,12 @@ do_backup(pgBackupOption bkupopt)
255255

256256
/* PGDATA and BACKUP_MODE are always required */
257257
if (pgdata==NULL)
258-
elog(ERROR_ARGS,"Required parameter not specified: PGDATA "
258+
elog(ERROR,"Required parameter not specified: PGDATA "
259259
"(-D, --pgdata)");
260260

261261
/* A backup mode is needed */
262262
if (current.backup_mode==BACKUP_MODE_INVALID)
263-
elog(ERROR_ARGS,"Required parameter not specified: BACKUP_MODE "
263+
elog(ERROR,"Required parameter not specified: BACKUP_MODE "
264264
"(-b, --backup-mode)");
265265

266266
/* Confirm data block size and xlog block size are compatible */
@@ -280,9 +280,9 @@ do_backup(pgBackupOption bkupopt)
280280
/* get exclusive lock of backup catalog */
281281
ret=catalog_lock();
282282
if (ret==-1)
283-
elog(ERROR_SYSTEM,"cannot lock backup catalog");
283+
elog(ERROR,"cannot lock backup catalog");
284284
elseif (ret==1)
285-
elog(ERROR_ALREADY_RUNNING,
285+
elog(ERROR,
286286
"another pg_arman is running, skipping this backup");
287287

288288
/* initialize backup result */
@@ -302,15 +302,15 @@ do_backup(pgBackupOption bkupopt)
302302
if (!check)
303303
{
304304
if (pgBackupCreateDir(&current))
305-
elog(ERROR_SYSTEM,"cannot create backup directory");
305+
elog(ERROR,"cannot create backup directory");
306306
pgBackupWriteIni(&current);
307307
}
308308
elog(LOG,"backup destination is initialized");
309309

310310
/* get list of backups already taken */
311311
backup_list=catalog_get_backup_list(NULL);
312312
if (!backup_list)
313-
elog(ERROR_SYSTEM,"cannot process any more");
313+
elog(ERROR,"cannot process any more");
314314

315315
/* set the error processing function for the backup process */
316316
pgut_atexit_push(backup_cleanup,NULL);
@@ -379,7 +379,7 @@ check_server_version(void)
379379
/* confirm server version */
380380
server_version=PQserverVersion(connection);
381381
if (server_version!=PG_VERSION_NUM)
382-
elog(ERROR_PG_INCOMPATIBLE,
382+
elog(ERROR,
383383
"server version is %d.%d.%d, must be %s or higher.",
384384
server_version /10000,
385385
(server_version /100) %100,
@@ -402,12 +402,12 @@ confirm_block_size(const char *name, int blcksz)
402402

403403
res=execute("SELECT current_setting($1)",1,&name);
404404
if (PQntuples(res)!=1||PQnfields(res)!=1)
405-
elog(ERROR_PG_COMMAND,"cannot get %s: %s",
405+
elog(ERROR,"cannot get %s: %s",
406406
name,PQerrorMessage(connection));
407407
block_size=strtol(PQgetvalue(res,0,0),&endp,10);
408408
PQclear(res);
409409
if ((endp&&*endp)||block_size!=blcksz)
410-
elog(ERROR_PG_INCOMPATIBLE,
410+
elog(ERROR,
411411
"%s(%d) is not compatible(%d expected)",
412412
name,block_size,blcksz);
413413
}
@@ -494,11 +494,11 @@ wait_for_archive(pgBackup *backup, const char *sql)
494494
{
495495
sleep(1);
496496
if (interrupted)
497-
elog(ERROR_INTERRUPTED,
497+
elog(ERROR,
498498
"interrupted during waiting for WAL archiving");
499499
try_count++;
500500
if (try_count>TIMEOUT_ARCHIVE)
501-
elog(ERROR_ARCHIVE_FAILED,
501+
elog(ERROR,
502502
"switched WAL could not be archived in %d seconds",
503503
TIMEOUT_ARCHIVE);
504504
}
@@ -539,7 +539,7 @@ get_lsn(PGresult *res, XLogRecPtr *lsn)
539539
uint32xrecoff;
540540

541541
if (res==NULL||PQntuples(res)!=1||PQnfields(res)!=1)
542-
elog(ERROR_PG_COMMAND,
542+
elog(ERROR,
543543
"result of backup command is invalid: %s",
544544
PQerrorMessage(connection));
545545

@@ -560,13 +560,13 @@ static void
560560
get_xid(PGresult*res,uint32*xid)
561561
{
562562
if (res==NULL||PQntuples(res)!=1||PQnfields(res)!=1)
563-
elog(ERROR_PG_COMMAND,
563+
elog(ERROR,
564564
"result of txid_current() is invalid: %s",
565565
PQerrorMessage(connection));
566566

567567
if (sscanf(PQgetvalue(res,0,0),"%u",xid)!=1)
568568
{
569-
elog(ERROR_PG_COMMAND,
569+
elog(ERROR,
570570
"result of txid_current() is invalid: %s",
571571
PQerrorMessage(connection));
572572
}
@@ -653,12 +653,12 @@ backup_files(const char *from_root,
653653

654654
/* If current time is rewinded, abort this backup. */
655655
if (tv.tv_sec<file->mtime)
656-
elog(ERROR_SYSTEM,
656+
elog(ERROR,
657657
"current time may be rewound. Please retry with full backup mode.");
658658

659659
/* check for interrupt */
660660
if (interrupted)
661-
elog(ERROR_INTERRUPTED,"interrupted during backup");
661+
elog(ERROR,"interrupted during backup");
662662

663663
/* print progress in verbose mode */
664664
if (verbose)
@@ -688,7 +688,7 @@ backup_files(const char *from_root,
688688
}
689689
else
690690
{
691-
elog(ERROR_SYSTEM,
691+
elog(ERROR,
692692
"can't stat backup mode. \"%s\": %s",
693693
file->path,strerror(errno));
694694
}
@@ -852,7 +852,7 @@ create_file_list(parray *files,
852852
pgBackupGetPath(&current,path,lengthof(path),subdir);
853853
fp=fopen(path,is_append ?"at" :"wt");
854854
if (fp==NULL)
855-
elog(ERROR_SYSTEM,"can't open file list \"%s\": %s",path,
855+
elog(ERROR,"can't open file list \"%s\": %s",path,
856856
strerror(errno));
857857
dir_print_file_list(fp,files,root,prefix);
858858
fclose(fp);

‎catalog.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ catalog_lock(void)
4040
join_path_components(id_path,backup_path,PG_RMAN_INI_FILE);
4141
lock_fd=open(id_path,O_RDWR);
4242
if (lock_fd==-1)
43-
elog(errno==ENOENT ?ERROR_CORRUPTED :ERROR_SYSTEM,
43+
elog(errno==ENOENT ?ERROR :ERROR,
4444
"cannot open file \"%s\": %s",id_path,strerror(errno));
4545

4646
ret=flock(lock_fd,LOCK_EX |LOCK_NB);/* non-blocking */
@@ -55,7 +55,7 @@ catalog_lock(void)
5555
{
5656
interrno_tmp=errno;
5757
close(lock_fd);
58-
elog(ERROR_SYSTEM,"cannot lock file \"%s\": %s",id_path,
58+
elog(ERROR,"cannot lock file \"%s\": %s",id_path,
5959
strerror(errno_tmp));
6060
}
6161
}
@@ -351,7 +351,7 @@ pgBackupWriteIni(pgBackup *backup)
351351
pgBackupGetPath(backup,ini_path,lengthof(ini_path),BACKUP_INI_FILE);
352352
fp=fopen(ini_path,"wt");
353353
if (fp==NULL)
354-
elog(ERROR_SYSTEM,"cannot open INI file \"%s\": %s",ini_path,
354+
elog(ERROR,"cannot open INI file \"%s\": %s",ini_path,
355355
strerror(errno));
356356

357357
/* configuration section */
@@ -416,7 +416,7 @@ catalog_read_ini(const char *path)
416416
options[i++].var=&status;
417417
Assert(i==lengthof(options)-1);
418418

419-
pgut_readopt(path,options,ERROR_CORRUPTED);
419+
pgut_readopt(path,options,ERROR);
420420

421421
if (backup_mode)
422422
{
@@ -489,7 +489,7 @@ parse_backup_mode(const char *value)
489489
returnBACKUP_MODE_DIFF_PAGE;
490490

491491
/* Backup mode is invalid, so leave with an error */
492-
elog(ERROR_ARGS,"invalid backup-mode \"%s\"",value);
492+
elog(ERROR,"invalid backup-mode \"%s\"",value);
493493
returnBACKUP_MODE_INVALID;
494494
}
495495

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp