Commit b236be71 authored by rswindell's avatar rswindell
Browse files

Add/use a new get_ctrl_dir() function to query the SBBSCTRL env var and if

not set (or blank), use the default ("/sbbs/ctrl") and print a warning to
stderr. This resolves a FAQ for sysops that struggle with setting the SBBSCTRL
env var, but do have sbbs install in /sbbs or a symlink from /sbbs to where
sbbs is actually installed.

Note: this function is different than the one previously defined in getctrl.c
but never used. If/when we ever really need to support PREFIX, then perhaps
we'll use that one (which copies a string to a buffer).
parent fbcbdb83
...@@ -728,12 +728,7 @@ int main(int argc, char **argv) ...@@ -728,12 +728,7 @@ int main(int argc, char **argv)
return(1); return(1);
} }
p=getenv("SBBSCTRL"); p = get_ctrl_dir();
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
memset(&scfg,0,sizeof(scfg)); memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg); scfg.size=sizeof(scfg);
......
...@@ -117,16 +117,7 @@ int main(int argc, char **argv) ...@@ -117,16 +117,7 @@ int main(int argc, char **argv)
return(0); return(0);
} }
p=getenv("SBBSCTRL"); p = get_ctrl_dir();
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
#ifdef __unix__
printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
memset(&cfg, 0, sizeof(cfg)); memset(&cfg, 0, sizeof(cfg));
cfg.size=sizeof(cfg); cfg.size=sizeof(cfg);
......
/* $Id$ */ /* $Id$ */
// vi: tabstop=4
#include "sbbs.h" #include "sbbs.h"
#include "crc32.h" #include "crc32.h"
...@@ -76,16 +77,7 @@ int main(int argc,char **argv) ...@@ -76,16 +77,7 @@ int main(int argc,char **argv)
fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File " fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File "
"Finder\n", DUPEFIND_VER, PLATFORM_DESC); "Finder\n", DUPEFIND_VER, PLATFORM_DESC);
p=getenv("SBBSCTRL"); p = get_ctrl_dir();
if(p==NULL) {
fprintf(stderr,"\nSBBSCTRL environment variable must be set.\n");
#ifdef __unix__
fprintf(stderr,"\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
fprintf(stderr,"\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
if(argc>1 && (!stricmp(argv[1],"/?") || !stricmp(argv[1],"?") || !stricmp(argv[1],"-?"))) { if(argc>1 && (!stricmp(argv[1],"/?") || !stricmp(argv[1],"?") || !stricmp(argv[1],"-?"))) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
......
...@@ -102,7 +102,7 @@ int main(int argc, char **argv) ...@@ -102,7 +102,7 @@ int main(int argc, char **argv)
{ {
char revision[16]; char revision[16];
char error[512]; char error[512];
char *p,str[256],fname[256],ext,not[MAX_NOTS][9]; char str[256],fname[256],ext,not[MAX_NOTS][9];
uchar *datbuf,*ixbbuf; uchar *datbuf,*ixbbuf;
int i,j,file,dirnum,libnum,desc_off,lines,nots=0 int i,j,file,dirnum,libnum,desc_off,lines,nots=0
,omode=O_WRONLY|O_CREAT|O_TRUNC; ,omode=O_WRONLY|O_CREAT|O_TRUNC;
...@@ -152,18 +152,11 @@ int main(int argc, char **argv) ...@@ -152,18 +152,11 @@ int main(int argc, char **argv)
exit(0); exit(0);
} }
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
now=time32(NULL); now=time32(NULL);
memset(&scfg,0,sizeof(scfg)); memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg); scfg.size=sizeof(scfg);
SAFECOPY(scfg.ctrl_dir,p); SAFECOPY(scfg.ctrl_dir, get_ctrl_dir());
if(chdir(scfg.ctrl_dir)!=0) if(chdir(scfg.ctrl_dir)!=0)
fprintf(stderr,"!ERROR changing directory to: %s", scfg.ctrl_dir); fprintf(stderr,"!ERROR changing directory to: %s", scfg.ctrl_dir);
......
...@@ -441,15 +441,11 @@ gtk_widget_set_sensitive(w, TRUE); ...@@ -441,15 +441,11 @@ gtk_widget_set_sensitive(w, TRUE);
int read_config(void) int read_config(void)
{ {
char ctrl_dir[MAX_PATH+1]; char ctrl_dir[MAX_PATH+1];
char *p;
p=getenv("SBBSCTRL"); SAFECOPY(ctrl_dir, get_ctrl_dir());
if(p==NULL)
p="/sbbs/ctrl";
SAFECOPY(ctrl_dir, p);
prep_dir("",ctrl_dir,sizeof(ctrl_dir)); prep_dir("",ctrl_dir,sizeof(ctrl_dir));
if(!isdir(ctrl_dir)) { if(!isdir(ctrl_dir)) {
display_message("Environment Errpr","SBBSCTRL does not point to a directory","gtk-dialog-error"); display_message("Environment Error","SBBSCTRL does not point to a directory","gtk-dialog-error");
return(-1); return(-1);
} }
memset(&cfg,0,sizeof(cfg)); memset(&cfg,0,sizeof(cfg));
......
...@@ -1321,13 +1321,7 @@ int main(int argc, char **argv, char** env) ...@@ -1321,13 +1321,7 @@ int main(int argc, char **argv, char** env)
#ifndef JSDOOR #ifndef JSDOOR
if(scfg.ctrl_dir[0]==0) { if(scfg.ctrl_dir[0]==0) {
if((p=getenv("SBBSCTRL"))==NULL) { SAFECOPY(scfg.ctrl_dir, get_ctrl_dir());
fprintf(errfp,"\nSBBSCTRL environment variable not set and -c option not specified.\n");
fprintf(errfp,"\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
fprintf(errfp,"\n or: %s -c /sbbs/ctrl [module]\n",argv[0]);
return(do_bail(1));
}
SAFECOPY(scfg.ctrl_dir,p);
} }
#endif #endif
......
...@@ -105,12 +105,7 @@ int main(int argc, char **argv) ...@@ -105,12 +105,7 @@ int main(int argc, char **argv)
if(strcspn(argv[first_arg],"/\\")!=strlen(argv[first_arg])) if(strcspn(argv[first_arg],"/\\")!=strlen(argv[first_arg]))
p=argv[first_arg++]; p=argv[first_arg++];
else else
p=getenv("SBBSCTRL"); p = get_ctrl_dir();
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
memset(&scfg,0,sizeof(scfg)); memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg); scfg.size=sizeof(scfg);
......
...@@ -172,7 +172,6 @@ int main(int argc, char **argv) ...@@ -172,7 +172,6 @@ int main(int argc, char **argv)
FILE *route,*users,*nodes; FILE *route,*users,*nodes;
time_t now; time_t now;
smbmsg_t msg; smbmsg_t msg;
char *ctrl_dir;
char revision[16]; char revision[16];
sscanf("$Revision$", "%*s %s", revision); sscanf("$Revision$", "%*s %s", revision);
...@@ -253,13 +252,7 @@ int main(int argc, char **argv) ...@@ -253,13 +252,7 @@ int main(int argc, char **argv)
} }
cfg.size=sizeof(cfg); cfg.size=sizeof(cfg);
ctrl_dir=getenv("SBBSCTRL"); SAFECOPY(cfg.ctrl_dir, get_ctrl_dir());
if(ctrl_dir==NULL || ctrl_dir[0]==0) {
ctrl_dir="/sbbs/ctrl"; /* Not set? Use default */
printf("!SBBSCTRL environment variable not set, using default value: %s\n\n"
,ctrl_dir);
}
SAFECOPY(cfg.ctrl_dir, ctrl_dir);
if(!load_cfg(&cfg, NULL, TRUE, str)) { if(!load_cfg(&cfg, NULL, TRUE, str)) {
printf("\7\n%s\n",str); printf("\7\n%s\n",str);
......
...@@ -1176,6 +1176,7 @@ extern "C" { ...@@ -1176,6 +1176,7 @@ extern "C" {
DLLEXPORT BOOL str_is_ascii(const char*); DLLEXPORT BOOL str_is_ascii(const char*);
DLLEXPORT char * utf8_to_cp437_str(char* str); DLLEXPORT char * utf8_to_cp437_str(char* str);
DLLEXPORT char * subnewsgroupname(scfg_t*, sub_t*, char*, size_t); DLLEXPORT char * subnewsgroupname(scfg_t*, sub_t*, char*, size_t);
DLLEXPORT char * get_ctrl_dir(void);
/* msg_id.c */ /* msg_id.c */
DLLEXPORT char * DLLCALL ftn_msgid(sub_t*, smbmsg_t*, char* msgid, size_t); DLLEXPORT char * DLLCALL ftn_msgid(sub_t*, smbmsg_t*, char* msgid, size_t);
......
...@@ -1399,12 +1399,7 @@ int main(int argc, char** argv) ...@@ -1399,12 +1399,7 @@ int main(int argc, char** argv)
loginAttemptListInit(&login_attempt_list); loginAttemptListInit(&login_attempt_list);
atexit(cleanup); atexit(cleanup);
ctrl_dir=getenv("SBBSCTRL"); /* read from environment variable */ ctrl_dir = get_ctrl_dir();
if(ctrl_dir==NULL || ctrl_dir[0]==0) {
ctrl_dir="/sbbs/ctrl"; /* Not set? Use default */
printf("!SBBSCTRL environment variable not set, using default value: %s\n\n"
,ctrl_dir);
}
if(!winsock_startup()) if(!winsock_startup())
return(-1); return(-1);
......
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
#define COPYRIGHT_NOTICE "Copyright 2019 Rob Swindell" #define COPYRIGHT_NOTICE "Copyright 2019 Rob Swindell"
#define COPYRIGHT_CRC 0x0E0503DF #define COPYRIGHT_CRC 0x0E0503DF
#define SBBSCTRL_DEFAULT "/sbbs/ctrl"
#define Y2K_2DIGIT_WINDOW 70 #define Y2K_2DIGIT_WINDOW 70
#define FNOPEN_BUF_SIZE (2*1024) #define FNOPEN_BUF_SIZE (2*1024)
......
...@@ -84,16 +84,7 @@ int main(int argc, char **argv) ...@@ -84,16 +84,7 @@ int main(int argc, char **argv)
"or less\n"); "or less\n");
return(0); } return(0); }
p=getenv("SBBSCTRL"); p = get_ctrl_dir();
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
#ifdef __unix__
printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
memset(&cfg,0,sizeof(cfg)); memset(&cfg,0,sizeof(cfg));
cfg.size=sizeof(cfg); cfg.size=sizeof(cfg);
......
...@@ -719,3 +719,14 @@ char* subnewsgroupname(scfg_t* cfg, sub_t* sub, char* str, size_t size) ...@@ -719,3 +719,14 @@ char* subnewsgroupname(scfg_t* cfg, sub_t* sub, char* str, size_t size)
} }
return str; return str;
} }
char* get_ctrl_dir(void)
{
char* p = getenv("SBBSCTRL");
if(p == NULL || *p == '\0') {
fprintf(stderr, "!SBBSCTRL environment variable not set, using default value: " SBBSCTRL_DEFAULT "\n\n");
p = SBBSCTRL_DEFAULT;
}
return p;
}
...@@ -191,9 +191,8 @@ int main(int argc, char **argv) ...@@ -191,9 +191,8 @@ int main(int argc, char **argv)
FILE *text_js; FILE *text_js;
FILE *text_defaults_c; FILE *text_defaults_c;
if((p=getenv("SBBSCTRL"))==NULL) p = get_ctrl_dir();
p="/sbbs/ctrl"; SAFEPRINTF(path,"%s/text.dat",p);
sprintf(path,"%s/text.dat",p);
if((text_dat=fopen(path,"r"))==NULL) { if((text_dat=fopen(path,"r"))==NULL) {
perror(path); perror(path);
return(1); return(1);
......
...@@ -1895,7 +1895,7 @@ int main(int argc, char** argv) { ...@@ -1895,7 +1895,7 @@ int main(int argc, char** argv) {
int main_dflt=0; int main_dflt=0;
int main_bar=0; int main_bar=0;
char revision[16]; char revision[16];
char str[256],ctrl_dir[41],*p; char str[256],ctrl_dir[MAX_PATH + 1];
char title[256]; char title[256];
int i,j; int i,j;
scfg_t cfg; scfg_t cfg;
...@@ -1917,17 +1917,7 @@ int main(int argc, char** argv) { ...@@ -1917,17 +1917,7 @@ int main(int argc, char** argv) {
printf("\nSynchronet User Editor %s-%s Copyright %s " printf("\nSynchronet User Editor %s-%s Copyright %s "
"Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7); "Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7);
p=getenv("SBBSCTRL"); SAFECOPY(ctrl_dir, get_ctrl_dir());
if(p==NULL) {
printf("\7\nSBBSCTRL environment variable is not set.\n");
printf("This environment variable must be set to your CTRL directory.");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1); }
sprintf(ctrl_dir,"%.40s",p);
if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
&& ctrl_dir[strlen(ctrl_dir)-1]!='/')
strcat(ctrl_dir,"/");
gethostname(str,sizeof(str)-1); gethostname(str,sizeof(str)-1);
......
...@@ -786,7 +786,7 @@ int main(int argc, char** argv) { ...@@ -786,7 +786,7 @@ int main(int argc, char** argv) {
int main_dflt=0; int main_dflt=0;
int main_bar=0; int main_bar=0;
char revision[16]; char revision[16];
char str[256],ctrl_dir[41],*p; char str[256],ctrl_dir[MAX_PATH + 1];
char title[256]; char title[256];
int i,j; int i,j;
node_t node; node_t node;
...@@ -810,17 +810,7 @@ int main(int argc, char** argv) { ...@@ -810,17 +810,7 @@ int main(int argc, char** argv) {
printf("\nSynchronet UNIX Monitor %s-%s Copyright %s " printf("\nSynchronet UNIX Monitor %s-%s Copyright %s "
"Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7); "Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7);
p=getenv("SBBSCTRL"); SAFECOPY(ctrl_dir, get_ctrl_dir());
if(p==NULL) {
printf("\7\nSBBSCTRL environment variable is not set.\n");
printf("This environment variable must be set to your CTRL directory.");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1); }
sprintf(ctrl_dir,"%.40s",p);
if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
&& ctrl_dir[strlen(ctrl_dir)-1]!='/')
strcat(ctrl_dir,"/");
gethostname(str,sizeof(str)-1); gethostname(str,sizeof(str)-1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment