Changeset 410 for trunk/src/sh_err_log.c


Ignore:
Timestamp:
Aug 28, 2012, 7:06:46 PM (12 years ago)
Author:
katerina
Message:

Improvements for ticket #303 (option SetReportFile for writing out summary after file check).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_err_log.c

    r405 r410  
    10581058static char * gEfile = NULL;
    10591059static int    gFail  = 0;
     1060static long   gGid   = 0;
     1061
     1062int sh_efile_group(const char * str)
     1063{
     1064  int  fail;
     1065  long gid = sh_group_to_gid(str, &fail);
     1066
     1067  if (fail < 0)
     1068    {
     1069      return -1;
     1070    }
     1071  gGid = gid;
     1072  return 0;
     1073}
     1074
    10601075
    10611076int sh_efile_path(const char * str)
     
    11481163              fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
    11491164              sl_close (fd);
     1165            }
     1166          else
     1167            {
     1168              static int nFail = 0;
     1169
     1170              if (nFail == 0)
     1171                {
     1172                  char errmsg[1024];
     1173                  char * tmp  = sh_util_safe_name (lockfile);
     1174                 
     1175                  sl_snprintf(errmsg, sizeof(errmsg),
     1176                              _("Error creating lockfile %s"),
     1177                              tmp);
     1178                 
     1179                  sh_error_handle (SH_ERR_ERR, FIL__, __LINE__,
     1180                                   0, MSG_E_SUBGEN,
     1181                                   errmsg, _("sh_efile_lock"));
     1182                  ++nFail;
     1183                  SH_FREE(tmp);
     1184                }
    11501185            }
    11511186        }
     
    11911226void sh_efile_report()
    11921227{
     1228  extern int get_the_fd (SL_TICKET ticket);
    11931229  SL_TICKET     fd;
    11941230  char         *efile;
     
    12261262
    12271263              time_t now = time(NULL);
     1264              int  filed = get_the_fd(fd);
    12281265
    12291266              (void) sh_unix_time (now, tstamp, sizeof(tstamp));
     
    12331270                          tstamp,
    12341271                          (long long) now,
    1235                           tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
     1272                          (long) tmp[0], (long) tmp[1], (long) tmp[2],
     1273                          (long) tmp[3], (long) tmp[4], (long) tmp[5]);
    12361274#else
    12371275              sl_snprintf(report, sizeof(report),
     
    12391277                          tstamp,
    12401278                          (long) now,
    1241                           tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
     1279                          (long) tmp[0], (long) tmp[1], (long) tmp[2],
     1280                          (long) tmp[3], (long) tmp[4], (long) tmp[5]);
    12421281#endif
    12431282                         
     
    12461285                status = sl_write (fd, report,  strlen(report));
    12471286              (void) sl_sync(fd);
     1287
     1288              /* make group writeable, such that nagios can truncate */
     1289              fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
     1290              status = fchown (filed, -1, gGid);
     1291              if (status < 0)
     1292                {
     1293                  int  errnum = errno;
     1294                  static int nFail = 0;
     1295                  if (nFail == 0)
     1296                    {
     1297                      char errmsg[1024];
     1298                      char buf[256];
     1299                      char * tmp  = sh_util_safe_name (efile);
     1300
     1301                      sl_snprintf(errmsg, sizeof(errmsg),
     1302                                  _("Error changing group of %s to %ld: %s"),
     1303                                  tmp, gGid,
     1304                                  sh_error_message (errnum, buf, sizeof(buf)));
     1305                      sh_error_handle (SH_ERR_ERR, FIL__, __LINE__,
     1306                                       errnum, MSG_E_SUBGEN,
     1307                                       errmsg, _("sh_efile_report"));
     1308                      ++nFail;
     1309                      SH_FREE(tmp);
     1310                    }
     1311                }
     1312
    12481313              (void) sl_close(fd);
    12491314            }
Note: See TracChangeset for help on using the changeset viewer.