1
0
forked from bip/bip

create mandatory directories

This commit is contained in:
kyoshiro 2007-05-23 20:55:09 +00:00
parent fbd899145f
commit ad9c4d7021
4 changed files with 25 additions and 7 deletions

View File

@ -14,8 +14,10 @@ use strict;
use IO::File;
use Data::Dumper;
my $CFILE = $ENV{'HOME'} . '/.bip/bip.conf.autogen';
my $sfile = $ENV{'HOME'} . '/.bip/bipgenconfig.store';
my $bipdir = $ENV{'HOME'} . '/.bip';
my $CFILE = $bipdir . '/bip.conf.autogen';
my $sfile = $bipdir . '/bipgenconfig.store';
my $certout = $bipdir . '/bip.pem.autogen';
my $SERIALIZE_DBG = 1;
my %cf;
my $DEBUG = 0;
@ -26,7 +28,6 @@ my $mode = 'normal';
my $maxlevel = 5;
my $bipmkpw;
my $tmpcrt = "/tmp/bip-cert.cnf";
my $certout = $ENV{'HOME'} . '/.bip/bip.pem.autogen';
my %optdesc = (
'global' => {
'ip' => { 'type' => 's', 'adv' => 1, 'default' => '0.0.0.0',
@ -39,7 +40,7 @@ my %optdesc = (
'optional' => 1,
'desc' => 'Do you want to enable client side SSL ?' },
'pid_file' => { 'type' => 's', 'adv' => 1, 'optional' => 1,
'default' => $ENV{'HOME'} . '/.bip/bip.pid',
'default' => $bipdir . '/bip.pid',
'desc' => 'Where do you want the pidfile to be stored ?' },
'log' => { 'type' => 'b', 'adv' => 0, 'default' => 'true',
'optional' => 1,
@ -54,7 +55,7 @@ my %optdesc = (
'desc' => 'Define bip\'s system logs verbosity level {less 0 - 7 tremendous}:' },
'log_root' => { 'type' => 's', 'adv' => 0,
'optional' => 1,
'default' => $ENV{'HOME'} . '/.bip/logs',
'default' => $bipdir . '/logs',
'depends' => 'log', 'depval' => 'true',
'desc' => 'In which directory do you want logs to be stored ?' },
'log_format' => { 'type' => 's', 'adv' => 1, 'default' => '%n/%Y-%m/%c.%d.log',
@ -1271,6 +1272,14 @@ sub invMode {
return ($mode eq 'advanced' ? 'normal' : 'advanced');
}
if (! -e $bipdir) {
mkdir($bipdir) || fatal("Unable to create bip's dir `$bipdir'");
} elsif (! -d $bipdir) {
fatal("Bip's dir `$bipdir' already exists and is not a directory");
} elsif (! -w $bipdir) {
fatal("Bip's dir `$bipdir' already exists and is not writable");
}
main_menu();
#sets config backlog
#different user/nick/real ?

View File

@ -985,6 +985,7 @@ int main(int argc, char **argv)
exit(28);
}
check_dir(conf_log_root, 1);
fd = do_pid_stuff();
pid_t pid = 0;
if (conf_daemonize)

View File

@ -38,7 +38,7 @@ static char *_log_wrap(char *dest, char *line);
/* TODO: change fatal("out of memory") to cleanup & return NULL */
int check_dir(char *filename)
int check_dir(char *filename, int is_fatal)
{
int err;
struct stat statbuf;
@ -47,15 +47,22 @@ int check_dir(char *filename)
if (err && errno == ENOENT) {
err = mkdir(filename, 0750);
if (err) {
if (is_fatal)
fatal("mkdir(%s) %s", filename,
strerror(errno));
mylog(LOG_ERROR, "mkdir(%s) %s", filename,
strerror(errno));
return 1;
}
} else if (err) {
if (is_fatal)
fatal("stat(%s) %s", filename, strerror(errno));
mylog(LOG_ERROR, "stat(%s) %s", filename,
strerror(errno));
return 1;
} else if (!(statbuf.st_mode & S_IFDIR)) {
if (is_fatal)
fatal("%s is not a directory", filename);
mylog(LOG_ERROR, "%s is not a directory", filename);
return 1;
}
@ -88,7 +95,7 @@ int check_dir_r(char *dirname)
count += pos;
*(dir + count) = '\0';
mylog(LOG_DEBUGVERB,"check_dir_r: %s", dir);
if (check_dir(dir)) {
if (check_dir(dir, 0)) {
free(dir);
return 1;
}

View File

@ -93,4 +93,5 @@ int log_has_backlog(log_t *logdata, char *destination);
void log_flush_all(void);
void log_client_none_connected(log_t *logdata);
void log_reset(logfilegroup_t *);
int check_dir(char *filename, int is_fatal);
#endif