⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsd_cfg.c

📁 GSM猫管理程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  if (result)    (*result)++;}int startup_check(int result){  //int result = 0; // number of problems  char *msg_dir = "%s directory %s cannot be opened.";  char *msg_file = "%s directory %s is not writable.";  int i;  int x;  int y;  FILE *fp;  char tmp[PATH_MAX];  char fname[PATH_MAX];  char *p;  char *p2;  int d_incoming_ok = 0;  int d_saved_ok = 0;  struct stat statbuf;  if (startup_err_str)  {    wrlogfile(NULL, "There was %i error%s while reading the config file.", startup_err_count, (startup_err_count > 1)? "s" : "");      p = startup_err_str;    while (p && *p)    {      if ((p2 = strchr(p, '\n')))        *p2 = 0;      wrlogfile(&result, "- %s", p);      p = (p2)? p2 +1 : NULL;      }    free(startup_err_str);    startup_err_str = NULL;    startup_err_count = 0;  }  // After this a lockfile errors are collected to startup_err_str.   if ((i = check_directory(d_spool)) == 1)    wrlogfile(&result, "Spool (outgoing) directory definition is missing.");  else if (i > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Spool", d_spool);  else if (i == 0)    remove_lockfiles(d_spool);  if ((i = check_directory(d_stats)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Stats", d_stats);  if ((i = check_directory(d_failed)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Failed", d_failed);  else if (i == 0)    remove_lockfiles(d_failed);  if ((i = check_directory(d_incoming)) == 1)    wrlogfile(&result, "Incoming directory definition is missing.");  else if (i > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Incoming", d_incoming);  else if (i == 0)  {    remove_lockfiles(d_incoming);    d_incoming_ok = 1;  }  if (queues[0].name[0] == 0)  {    if ((i = check_directory(d_checked)) == 1)      wrlogfile(&result, "Checked directory definition is missing.");    else if (i > 1)      wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Checked", d_checked);    else if (i == 0)      remove_lockfiles(d_checked);  }  if ((i = check_directory(d_sent)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Sent", d_sent);  else if (i == 0)    remove_lockfiles(d_sent);  if ((i = check_directory(d_report)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Report", d_report);  else if (i == 0)    remove_lockfiles(d_report);  if ((i = check_directory(d_phonecalls)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Phonecalls", d_phonecalls);  else if (i == 0)    remove_lockfiles(d_phonecalls);  if ((i = check_directory(d_saved)) > 1)    wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Saved", d_saved);  else if (i == 0)  {    remove_lockfiles(d_saved);    d_saved_ok = 1;  }  x = 0;  while (queues[x].name[0] && (x < PROVIDER))  {    if ((i = check_directory(queues[x].directory)) == 1)      wrlogfile(&result, "Queue %s directory definition is missing.", queues[x].name);    else if (i > 1)      wrlogfile(&result, (i == 2)? msg_dir : msg_file, "Queue", queues[x].directory);    else if (i == 0)      remove_lockfiles(queues[x].directory);    // Should also check that all queue names have a provider setting too:    if (queues[x].numbers[0][0] == 0)      wrlogfile(&result, "Queue %s has no provider number(s) defined.", queues[x].name);    x++;  }  if (*eventhandler)  {    if (!(fp = fopen(eventhandler, "r")))      wrlogfile(&result, "Eventhandler %s cannot be read: %s", eventhandler, strerror(errno));    else    {      fclose(fp);      if (!is_executable(eventhandler))        wrlogfile(&result, "Eventhandler %s is not executable for smsd.", eventhandler);    }  }  if (*checkhandler)  {    if (!(fp = fopen(checkhandler, "r")))      wrlogfile(&result, "Checkhandler %s cannot be read: %s", checkhandler, strerror(errno));    else    {      fclose(fp);      if (!is_executable(checkhandler))        wrlogfile(&result, "Checkhandler %s is not executable for smsd.", checkhandler);    }  }  if (*alarmhandler)  {    if (!(fp = fopen(alarmhandler, "r")))      wrlogfile(&result, "Alarmhandler %s cannot be read: %s", alarmhandler, strerror(errno));    else    {      fclose(fp);      if (!is_executable(alarmhandler))        wrlogfile(&result, "Alarmhandler %s is not executable for smsd.", alarmhandler);    }  }  if (*regular_run)  {    if (!(fp = fopen(regular_run, "r")))      wrlogfile(&result, "Regular run %s cannot be read: %s", regular_run, strerror(errno));    else    {      fclose(fp);      if (!is_executable(regular_run))        wrlogfile(&result, "Regular run %s is not executable for smsd.", regular_run);    }  }  for (x = 0 ; x < DEVICES; x++)  {    if (devices[x].name[0])    {      if (devices[x].device[0] == 0)        wrlogfile(&result, "%s has no device specified.", devices[x].name);      if (queues[0].name[0])        if (devices[x].queues[0][0] == 0)          wrlogfile(&result, "Queues are used, but %s has no queue(s) defined.", devices[x].name);      if (devices[x].eventhandler[0] && strcmp(eventhandler, devices[x].eventhandler) != 0)      {        if (!(fp = fopen(devices[x].eventhandler, "r")))          wrlogfile(&result, "%s eventhandler %s cannot be read: %s", devices[x].name, devices[x].eventhandler, strerror(errno));        else        {          fclose(fp);          if (!is_executable(devices[x].eventhandler))            wrlogfile(&result, "%s eventhandler %s is not executable for smsd.", devices[x].name, devices[x].eventhandler);        }      }      if (devices[x].pdu_from_file[0])      {        strcpy(tmp, devices[x].pdu_from_file);        if ((p = strrchr(tmp, '/')))        {          *p = 0;          if ((i = check_directory(tmp)) > 1)            wrlogfile(&result, (i == 2)? msg_dir : msg_file, "pdu_from_file", tmp);        }      }      if (devices[x].dev_rr[0])      {        if (!(fp = fopen(devices[x].dev_rr, "r")))          wrlogfile(&result, "%s regular_run file %s cannot be read: %s", devices[x].name, devices[x].dev_rr, strerror(errno));        else        {          fclose(fp);          if (!is_executable(devices[x].dev_rr))            wrlogfile(&result, "%s regular_run file %s is not executable for smsd.", devices[x].name, devices[x].dev_rr);        }      }      if (devices[x].dev_rr_cmdfile[0])      {        strcpy(tmp, devices[x].dev_rr_cmdfile);        if ((p = strrchr(tmp, '/')))        {          *p = 0;          if ((i = check_directory(tmp)) > 1)            wrlogfile(&result, (i == 2)? msg_dir : msg_file, "regular_run_cmdfile", tmp);        }      }      if (devices[x].dev_rr_logfile[0])      {        if (!(fp = fopen(devices[x].dev_rr_logfile, "a")))          wrlogfile(&result, "%s regular_run_logfile %s cannot be written: %s", devices[x].name, devices[x].dev_rr_logfile, strerror(errno));        else          fclose(fp);      }      if (devices[x].dev_rr_statfile[0])      {        if (!(fp = fopen(devices[x].dev_rr_statfile, "a")))          wrlogfile(&result, "%s regular_run_statfile %s cannot be written: %s", devices[x].name, devices[x].dev_rr_statfile, strerror(errno));        else          fclose(fp);        // Devices cannot have the same statfile because it's overwritten by each process.        for (y = 0 ; y < DEVICES; y++)        {          if (y == x)            continue;          if (devices[y].name[0])            if (strcmp(devices[y].dev_rr_statfile, devices[x].dev_rr_statfile) == 0)              wrlogfile(&result, "Devices %s and %s has the same regular_run_statfile %s.", devices[x].name, devices[y].name, devices[x].dev_rr_statfile);        }      }    }  }  if (*whitelist)  {    if (!(fp = fopen(whitelist, "r")))      wrlogfile(&result, "Whitelist %s cannot be read: %s", whitelist, strerror(errno));    else      fclose(fp);  }  if (*blacklist)  {    if (!(fp = fopen(blacklist, "r")))      wrlogfile(&result, "Blacklist %s cannot be read: %s", blacklist, strerror(errno));    else      fclose(fp);  }  if (*infofile)  {    if (!(fp = fopen(infofile, "w")))      wrlogfile(&result, "Infofile %s cannot be created: %s", infofile, strerror(errno));    else      fclose(fp);    unlink(infofile);  }  if (store_received_pdu < 0 || store_received_pdu > 3)    wrlogfile(&result, "Invalid value for store_received_pdu.");  if (store_sent_pdu < 0 || store_sent_pdu > 3)    wrlogfile(&result, "Invalid value for store_sent_pdu.");  if (startup_err_str)  {    wrlogfile(NULL, "There was %i error%s while removing .LOCK files.", startup_err_count, (startup_err_count > 1)? "s" : "");      p = startup_err_str;    while (p && *p)    {      if ((p2 = strchr(p, '\n')))        *p2 = 0;      wrlogfile(&result, "- %s", p);      p = (p2)? p2 +1 : NULL;      }    free(startup_err_str);    startup_err_str = NULL;    startup_err_count = 0;  }  if (d_incoming_ok && d_saved_ok)  {    // 3.1beta7: Search concatenation files from incoming directory.    // If zero sized files found, they can be removed.    // If files with data found, they can be moved to d_saved directory.    // Existing zero sized file is overwritten, but a file containing data produces fatal error.    for (x = 0 ; x < DEVICES; x++)    {      if (devices[x].name[0])      {        sprintf(fname, CONCATENATED_DIR_FNAME, d_incoming, devices[x].name);        if (stat(fname, &statbuf) == 0)        {          if (statbuf.st_size == 0)          {            if (unlink(fname) != 0)              startuperror("Cannot unlink concatenation storage %: %s\n", fname, strerror(errno));          }          else          {            i = 1;            sprintf(tmp, CONCATENATED_DIR_FNAME, d_saved, devices[x].name);            if (stat(tmp, &statbuf) == 0)            {              if (statbuf.st_size != 0)              {                i = 0;                wrlogfile(&result, "Concatenation storage of %s cannot be moved from incoming to saved directory, "                                   "destination exists and has also some data ", devices[x].name);              }            }            if (i)            {              if (movefile(fname, d_saved))              {                // movefile does not inform if removing source file failed:                if (stat(fname, &statbuf) == 0)                {                  if (unlink(fname) != 0)                  {                    startuperror("Failed to move concatenation storage, cannot unlink source file %: %s\n", fname, strerror(errno));                    i = 0;                  }                }                if (i)                  writelogfile(LOG_INFO, "smsd", "Moved concatenation storage of %s from incoming to saved directory", devices[x].name);              }              else                wrlogfile(&result, "Failed to move concatenation storage of %s from incoming to saved directory.", devices[x].name);            }          }        }      }    }  }  if (result > 0)  {    wrlogfile(NULL, "There was %i major problem%s found.", result, (result > 1)? "s" : "");    fprintf(stderr, "Cannot start. See the log file for details.\n");  }  else  {    // Report some settings:    char buffer[1024];    mode_t mode;    mode_t m;    mode = umask(0);    umask(mode);    m = 0666 & ~mode;    sprintf(buffer, "File mode creation mask: 0%o (0%o, %c%c%c%c%c%c%c%c%c).", (int)mode, (int)m,            (m & 0x100)? 'r':'-', (m & 0x80)? 'w':'-', (m & 0x40)? 'x':'-',            (m & 0x20)? 'r':'-', (m & 0x10)? 'w':'-',  (m & 0x8)? 'x':'-',            (m & 0x4)? 'r':'-', (m & 0x2)? 'w':'-', (m & 0x1)? 'x':'-');    writelogfile(LOG_INFO, "smsd", buffer);#ifdef DEBUGMSG  printf("!! %s\n", buffer);#endif    if (validity_period < 255)    {      char tmp[100];      report_validity(tmp, validity_period);      sprintf(buffer, "Default validity period is set to %s.", tmp);      writelogfile(LOG_INFO, "smsd", buffer);#ifdef DEBUGMSG  printf("!! %s\n", buffer);#endif    }  }  return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -