Fossil SCM

Improved error message handling. Fix the "fossil server" command so that it works when run as root on a repository in the root directory.

drh 2013-01-07 18:58 trunk
Commit baa1ebb7d981bc7d80a1d7751917670b61d1b7b3
3 files changed +5 -6 +14 -26 +15
+5 -6
--- src/db.c
+++ src/db.c
@@ -89,11 +89,11 @@
8989
cgi_reply();
9090
}
9191
else if( g.cgiOutput ){
9292
g.cgiOutput = 0;
9393
cgi_printf("<h1>Database Error</h1>\n"
94
- "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
94
+ "<pre>%h</pre>\n<p>%s</p>\n", z, zRebuildMsg);
9595
cgi_reply();
9696
}else{
9797
fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
9898
}
9999
free(z);
@@ -644,11 +644,11 @@
644644
const char *zSql;
645645
va_list ap;
646646
647647
rc = sqlite3_open(zFileName, &db);
648648
if( rc!=SQLITE_OK ){
649
- db_err(sqlite3_errmsg(db));
649
+ db_err("[%s] %s", zFileName, sqlite3_errmsg(db));
650650
}
651651
sqlite3_busy_timeout(db, 5000);
652652
sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
653653
rc = sqlite3_exec(db, zSchema, 0, 0, 0);
654654
if( rc!=SQLITE_OK ){
@@ -702,18 +702,19 @@
702702
static sqlite3 *openDatabase(const char *zDbName){
703703
int rc;
704704
const char *zVfs;
705705
sqlite3 *db;
706706
707
+ if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
707708
zVfs = fossil_getenv("FOSSIL_VFS");
708709
rc = sqlite3_open_v2(
709710
zDbName, &db,
710711
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
711712
zVfs
712713
);
713714
if( rc!=SQLITE_OK ){
714
- db_err(sqlite3_errmsg(db));
715
+ db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
715716
}
716717
sqlite3_busy_timeout(db, 5000);
717718
sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
718719
sqlite3_create_function(db, "now", 0, SQLITE_ANY, 0, db_now_function, 0, 0);
719720
sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_ANY, 0,
@@ -1456,13 +1457,11 @@
14561457
}
14571458
}
14581459
}
14591460
static void db_sql_trace(void *notUsed, const char *zSql){
14601461
int n = strlen(zSql);
1461
- char *zMsg = mprintf("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
1462
- fossil_puts(zMsg, 1);
1463
- fossil_free(zMsg);
1462
+ fossil_trace("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
14641463
}
14651464
14661465
/*
14671466
** Implement the user() SQL function. user() takes no arguments and
14681467
** returns the user ID of the current user.
14691468
--- src/db.c
+++ src/db.c
@@ -89,11 +89,11 @@
89 cgi_reply();
90 }
91 else if( g.cgiOutput ){
92 g.cgiOutput = 0;
93 cgi_printf("<h1>Database Error</h1>\n"
94 "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
95 cgi_reply();
96 }else{
97 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
98 }
99 free(z);
@@ -644,11 +644,11 @@
644 const char *zSql;
645 va_list ap;
646
647 rc = sqlite3_open(zFileName, &db);
648 if( rc!=SQLITE_OK ){
649 db_err(sqlite3_errmsg(db));
650 }
651 sqlite3_busy_timeout(db, 5000);
652 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
653 rc = sqlite3_exec(db, zSchema, 0, 0, 0);
654 if( rc!=SQLITE_OK ){
@@ -702,18 +702,19 @@
702 static sqlite3 *openDatabase(const char *zDbName){
703 int rc;
704 const char *zVfs;
705 sqlite3 *db;
706
 
707 zVfs = fossil_getenv("FOSSIL_VFS");
708 rc = sqlite3_open_v2(
709 zDbName, &db,
710 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
711 zVfs
712 );
713 if( rc!=SQLITE_OK ){
714 db_err(sqlite3_errmsg(db));
715 }
716 sqlite3_busy_timeout(db, 5000);
717 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
718 sqlite3_create_function(db, "now", 0, SQLITE_ANY, 0, db_now_function, 0, 0);
719 sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_ANY, 0,
@@ -1456,13 +1457,11 @@
1456 }
1457 }
1458 }
1459 static void db_sql_trace(void *notUsed, const char *zSql){
1460 int n = strlen(zSql);
1461 char *zMsg = mprintf("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
1462 fossil_puts(zMsg, 1);
1463 fossil_free(zMsg);
1464 }
1465
1466 /*
1467 ** Implement the user() SQL function. user() takes no arguments and
1468 ** returns the user ID of the current user.
1469
--- src/db.c
+++ src/db.c
@@ -89,11 +89,11 @@
89 cgi_reply();
90 }
91 else if( g.cgiOutput ){
92 g.cgiOutput = 0;
93 cgi_printf("<h1>Database Error</h1>\n"
94 "<pre>%h</pre>\n<p>%s</p>\n", z, zRebuildMsg);
95 cgi_reply();
96 }else{
97 fprintf(stderr, "%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
98 }
99 free(z);
@@ -644,11 +644,11 @@
644 const char *zSql;
645 va_list ap;
646
647 rc = sqlite3_open(zFileName, &db);
648 if( rc!=SQLITE_OK ){
649 db_err("[%s] %s", zFileName, sqlite3_errmsg(db));
650 }
651 sqlite3_busy_timeout(db, 5000);
652 sqlite3_exec(db, "BEGIN EXCLUSIVE", 0, 0, 0);
653 rc = sqlite3_exec(db, zSchema, 0, 0, 0);
654 if( rc!=SQLITE_OK ){
@@ -702,18 +702,19 @@
702 static sqlite3 *openDatabase(const char *zDbName){
703 int rc;
704 const char *zVfs;
705 sqlite3 *db;
706
707 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
708 zVfs = fossil_getenv("FOSSIL_VFS");
709 rc = sqlite3_open_v2(
710 zDbName, &db,
711 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
712 zVfs
713 );
714 if( rc!=SQLITE_OK ){
715 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
716 }
717 sqlite3_busy_timeout(db, 5000);
718 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
719 sqlite3_create_function(db, "now", 0, SQLITE_ANY, 0, db_now_function, 0, 0);
720 sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_ANY, 0,
@@ -1456,13 +1457,11 @@
1457 }
1458 }
1459 }
1460 static void db_sql_trace(void *notUsed, const char *zSql){
1461 int n = strlen(zSql);
1462 fossil_trace("%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
 
 
1463 }
1464
1465 /*
1466 ** Implement the user() SQL function. user() takes no arguments and
1467 ** returns the user ID of the current user.
1468
+14 -26
--- src/main.c
+++ src/main.c
@@ -605,14 +605,11 @@
605605
if( g.cgiOutput && once ){
606606
once = 0;
607607
cgi_printf("<p class=\"generalError\">%h</p>", z);
608608
cgi_reply();
609609
}else if( !g.fQuiet ){
610
- char *zOut = mprintf("%s: %s\n", g.argv[0], z);
611
- fossil_force_newline();
612
- fossil_puts(zOut, 1);
613
- fossil_free(zOut);
610
+ fossil_trace("%s: %s\n", g.argv[0], z);
614611
}
615612
}
616613
free(z);
617614
db_force_rollback();
618615
fossil_exit(rc);
@@ -636,17 +633,14 @@
636633
else
637634
#endif
638635
{
639636
if( g.cgiOutput ){
640637
g.cgiOutput = 0;
641
- cgi_printf("<p class=\"generalError\">%h</p>", z);
638
+ cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
642639
cgi_reply();
643640
}else if( !g.fQuiet ){
644
- char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
645
- fossil_force_newline();
646
- fossil_puts(zOut, 1);
647
- fossil_free(zOut);
641
+ fossil_trace("%s: %s\n", g.argv[0], z);
648642
}
649643
}
650644
free(z);
651645
db_force_rollback();
652646
fossil_exit(rc);
@@ -679,17 +673,14 @@
679673
} else
680674
#endif
681675
{
682676
if( g.cgiOutput ){
683677
g.cgiOutput = 0;
684
- cgi_printf("<p class=\"generalError\">%h</p>", z);
678
+ cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
685679
cgi_reply();
686680
}else{
687
- char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
688
- fossil_force_newline();
689
- fossil_puts(zOut, 1);
690
- fossil_free(zOut);
681
+ fossil_trace("%s: %s\n", g.argv[0], z);
691682
}
692683
}
693684
db_force_rollback();
694685
fossil_exit(rc);
695686
}
@@ -707,16 +698,13 @@
707698
json_warn( FSL_JSON_W_UNKNOWN, z );
708699
}else
709700
#endif
710701
{
711702
if( g.cgiOutput ){
712
- cgi_printf("<p class=\"generalError\">%h</p>", z);
703
+ cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
713704
}else{
714
- char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
715
- fossil_force_newline();
716
- fossil_puts(zOut, 1);
717
- fossil_free(zOut);
705
+ fossil_trace("%s: %s\n", g.argv[0], z);
718706
}
719707
}
720708
free(z);
721709
}
722710
@@ -747,13 +735,11 @@
747735
** Who knows why - this is just the way windows works.
748736
*/
749737
char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
750738
WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd);
751739
if( g.fSystemTrace ) {
752
- char *zOut = mprintf("SYSTEM: %s\n", zNewCmd);
753
- fossil_puts(zOut, 1);
754
- fossil_free(zOut);
740
+ fossil_trace("SYSTEM: %s\n", zNewCmd);
755741
}
756742
rc = _wsystem(zUnicode);
757743
fossil_unicode_free(zUnicode);
758744
free(zNewCmd);
759745
#else
@@ -1225,15 +1211,17 @@
12251211
}
12261212
zRepo = "/";
12271213
}else{
12281214
for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
12291215
if( zDir[i]!='/' ) fossil_panic("bad repository name: %s", zRepo);
1230
- zDir[i] = 0;
1231
- if( chdir(zDir) || chroot(zDir) || chdir("/") ){
1232
- fossil_fatal("unable to chroot into %s", zDir);
1216
+ if( i>0 ){
1217
+ zDir[i] = 0;
1218
+ if( chdir(zDir) || chroot(zDir) || chdir("/") ){
1219
+ fossil_fatal("unable to chroot into %s", zDir);
1220
+ }
1221
+ zDir[i] = '/';
12331222
}
1234
- zDir[i] = '/';
12351223
zRepo = &zDir[i];
12361224
}
12371225
if( stat(zRepo, &sStat)!=0 ){
12381226
fossil_fatal("cannot stat() repository: %s", zRepo);
12391227
}
12401228
--- src/main.c
+++ src/main.c
@@ -605,14 +605,11 @@
605 if( g.cgiOutput && once ){
606 once = 0;
607 cgi_printf("<p class=\"generalError\">%h</p>", z);
608 cgi_reply();
609 }else if( !g.fQuiet ){
610 char *zOut = mprintf("%s: %s\n", g.argv[0], z);
611 fossil_force_newline();
612 fossil_puts(zOut, 1);
613 fossil_free(zOut);
614 }
615 }
616 free(z);
617 db_force_rollback();
618 fossil_exit(rc);
@@ -636,17 +633,14 @@
636 else
637 #endif
638 {
639 if( g.cgiOutput ){
640 g.cgiOutput = 0;
641 cgi_printf("<p class=\"generalError\">%h</p>", z);
642 cgi_reply();
643 }else if( !g.fQuiet ){
644 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
645 fossil_force_newline();
646 fossil_puts(zOut, 1);
647 fossil_free(zOut);
648 }
649 }
650 free(z);
651 db_force_rollback();
652 fossil_exit(rc);
@@ -679,17 +673,14 @@
679 } else
680 #endif
681 {
682 if( g.cgiOutput ){
683 g.cgiOutput = 0;
684 cgi_printf("<p class=\"generalError\">%h</p>", z);
685 cgi_reply();
686 }else{
687 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
688 fossil_force_newline();
689 fossil_puts(zOut, 1);
690 fossil_free(zOut);
691 }
692 }
693 db_force_rollback();
694 fossil_exit(rc);
695 }
@@ -707,16 +698,13 @@
707 json_warn( FSL_JSON_W_UNKNOWN, z );
708 }else
709 #endif
710 {
711 if( g.cgiOutput ){
712 cgi_printf("<p class=\"generalError\">%h</p>", z);
713 }else{
714 char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
715 fossil_force_newline();
716 fossil_puts(zOut, 1);
717 fossil_free(zOut);
718 }
719 }
720 free(z);
721 }
722
@@ -747,13 +735,11 @@
747 ** Who knows why - this is just the way windows works.
748 */
749 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
750 WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd);
751 if( g.fSystemTrace ) {
752 char *zOut = mprintf("SYSTEM: %s\n", zNewCmd);
753 fossil_puts(zOut, 1);
754 fossil_free(zOut);
755 }
756 rc = _wsystem(zUnicode);
757 fossil_unicode_free(zUnicode);
758 free(zNewCmd);
759 #else
@@ -1225,15 +1211,17 @@
1225 }
1226 zRepo = "/";
1227 }else{
1228 for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
1229 if( zDir[i]!='/' ) fossil_panic("bad repository name: %s", zRepo);
1230 zDir[i] = 0;
1231 if( chdir(zDir) || chroot(zDir) || chdir("/") ){
1232 fossil_fatal("unable to chroot into %s", zDir);
 
 
 
1233 }
1234 zDir[i] = '/';
1235 zRepo = &zDir[i];
1236 }
1237 if( stat(zRepo, &sStat)!=0 ){
1238 fossil_fatal("cannot stat() repository: %s", zRepo);
1239 }
1240
--- src/main.c
+++ src/main.c
@@ -605,14 +605,11 @@
605 if( g.cgiOutput && once ){
606 once = 0;
607 cgi_printf("<p class=\"generalError\">%h</p>", z);
608 cgi_reply();
609 }else if( !g.fQuiet ){
610 fossil_trace("%s: %s\n", g.argv[0], z);
 
 
 
611 }
612 }
613 free(z);
614 db_force_rollback();
615 fossil_exit(rc);
@@ -636,17 +633,14 @@
633 else
634 #endif
635 {
636 if( g.cgiOutput ){
637 g.cgiOutput = 0;
638 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
639 cgi_reply();
640 }else if( !g.fQuiet ){
641 fossil_trace("%s: %s\n", g.argv[0], z);
 
 
 
642 }
643 }
644 free(z);
645 db_force_rollback();
646 fossil_exit(rc);
@@ -679,17 +673,14 @@
673 } else
674 #endif
675 {
676 if( g.cgiOutput ){
677 g.cgiOutput = 0;
678 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
679 cgi_reply();
680 }else{
681 fossil_trace("%s: %s\n", g.argv[0], z);
 
 
 
682 }
683 }
684 db_force_rollback();
685 fossil_exit(rc);
686 }
@@ -707,16 +698,13 @@
698 json_warn( FSL_JSON_W_UNKNOWN, z );
699 }else
700 #endif
701 {
702 if( g.cgiOutput ){
703 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
704 }else{
705 fossil_trace("%s: %s\n", g.argv[0], z);
 
 
 
706 }
707 }
708 free(z);
709 }
710
@@ -747,13 +735,11 @@
735 ** Who knows why - this is just the way windows works.
736 */
737 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
738 WCHAR *zUnicode = fossil_utf8_to_unicode(zNewCmd);
739 if( g.fSystemTrace ) {
740 fossil_trace("SYSTEM: %s\n", zNewCmd);
 
 
741 }
742 rc = _wsystem(zUnicode);
743 fossil_unicode_free(zUnicode);
744 free(zNewCmd);
745 #else
@@ -1225,15 +1211,17 @@
1211 }
1212 zRepo = "/";
1213 }else{
1214 for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
1215 if( zDir[i]!='/' ) fossil_panic("bad repository name: %s", zRepo);
1216 if( i>0 ){
1217 zDir[i] = 0;
1218 if( chdir(zDir) || chroot(zDir) || chdir("/") ){
1219 fossil_fatal("unable to chroot into %s", zDir);
1220 }
1221 zDir[i] = '/';
1222 }
 
1223 zRepo = &zDir[i];
1224 }
1225 if( stat(zRepo, &sStat)!=0 ){
1226 fossil_fatal("cannot stat() repository: %s", zRepo);
1227 }
1228
+15
--- src/printf.c
+++ src/printf.c
@@ -871,10 +871,25 @@
871871
Blob b = empty_blob;
872872
vxprintf(&b, zFormat, ap);
873873
fossil_puts(blob_str(&b), 0);
874874
blob_reset(&b);
875875
}
876
+ va_end(ap);
877
+}
878
+
879
+/*
880
+** Print a trace message on standard error.
881
+*/
882
+void fossil_trace(const char *zFormat, ...){
883
+ va_list ap;
884
+ Blob b;
885
+ va_start(ap, zFormat);
886
+ b = empty_blob;
887
+ vxprintf(&b, zFormat, ap);
888
+ fossil_puts(blob_str(&b), 1);
889
+ blob_reset(&b);
890
+ va_end(ap);
876891
}
877892
878893
/*
879894
** Like strcmp() except that it accepts NULL pointers. NULL sorts before
880895
** all non-NULL string pointers. Also, this strcmp() is a binary comparison
881896
--- src/printf.c
+++ src/printf.c
@@ -871,10 +871,25 @@
871 Blob b = empty_blob;
872 vxprintf(&b, zFormat, ap);
873 fossil_puts(blob_str(&b), 0);
874 blob_reset(&b);
875 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876 }
877
878 /*
879 ** Like strcmp() except that it accepts NULL pointers. NULL sorts before
880 ** all non-NULL string pointers. Also, this strcmp() is a binary comparison
881
--- src/printf.c
+++ src/printf.c
@@ -871,10 +871,25 @@
871 Blob b = empty_blob;
872 vxprintf(&b, zFormat, ap);
873 fossil_puts(blob_str(&b), 0);
874 blob_reset(&b);
875 }
876 va_end(ap);
877 }
878
879 /*
880 ** Print a trace message on standard error.
881 */
882 void fossil_trace(const char *zFormat, ...){
883 va_list ap;
884 Blob b;
885 va_start(ap, zFormat);
886 b = empty_blob;
887 vxprintf(&b, zFormat, ap);
888 fossil_puts(blob_str(&b), 1);
889 blob_reset(&b);
890 va_end(ap);
891 }
892
893 /*
894 ** Like strcmp() except that it accepts NULL pointers. NULL sorts before
895 ** all non-NULL string pointers. Also, this strcmp() is a binary comparison
896

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button