Changeset 481 for trunk/src/sh_unix.c
- Timestamp:
- Jul 18, 2015, 5:06:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_unix.c
r474 r481 103 103 #include "sh_prelink.h" 104 104 #include "sh_pthread.h" 105 #include "sh_sem.h" 105 106 106 107 /* moved here from far below … … 482 483 sl_strlcat(msg, details, 128); 483 484 (void) safe_logger (thesignal, method, msg); 485 486 close_ipc (); 484 487 raise(SIGKILL); 485 488 } … … 526 529 } while (val_return < 0 && errno == EINTR); 527 530 531 close_ipc (); 528 532 safe_logger (mysignal, 0, NULL); 529 533 } … … 594 598 if (skey != NULL) 595 599 memset (skey, '\0', sizeof(sh_key_t)); 596 #ifdef WITH_MESSAGE_QUEUE597 600 close_ipc (); 598 #endif599 601 safe_logger (mysignal, 0, NULL); 600 602 do { … … 636 638 if (skey != NULL) 637 639 memset (skey, '\0', sizeof(sh_key_t)); 638 #ifdef WITH_MESSAGE_QUEUE639 640 close_ipc (); 640 #endif641 641 642 642 do { … … 669 669 #endif 670 670 #ifdef SIGTTOU 671 if (mysignal == SIGTTOU) 672 sig_force_check = 1; 671 if (mysignal == SIGTTOU) { 672 sig_force_check = 1; sh_sem_trylock(); } 673 673 #endif 674 674 #ifdef SIGTTIN … … 682 682 #ifdef SIGQUIT 683 683 if (mysignal == SIGQUIT) 684 { 685 sig_terminate = 1; 686 ++sig_urgent; 687 } 684 sig_terminate = 1; 688 685 #endif 689 686 #ifdef SIGTERM … … 1042 1039 if ((status == ERANGE) && (w == NULL)) 1043 1040 { 1044 if (S L_TRUE == sl_ok_adds( gbufsize, SH_GRBUF_SIZE ))1041 if (S_TRUE == sl_ok_adds( gbufsize, SH_GRBUF_SIZE )) 1045 1042 { 1046 1043 SH_FREE(buffer); … … 1722 1719 struct utsname buf; 1723 1720 int i; 1724 intddot;1721 unsigned int ddot; 1725 1722 int len; 1726 1723 char * p; … … 1892 1889 */ 1893 1890 #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK) 1894 if (skey->mlock_failed == S L_FALSE)1891 if (skey->mlock_failed == S_FALSE) 1895 1892 { 1896 1893 if ( (-1) == sh_unix_mlock( FIL__, __LINE__, … … 1898 1895 { 1899 1896 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 1900 skey->mlock_failed = S L_TRUE;1897 skey->mlock_failed = S_TRUE; 1901 1898 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 1902 1899 } 1903 1900 } 1904 1901 #else 1905 if (skey->mlock_failed == S L_FALSE)1902 if (skey->mlock_failed == S_FALSE) 1906 1903 { 1907 1904 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 1908 skey->mlock_failed = S L_TRUE;1905 skey->mlock_failed = S_TRUE; 1909 1906 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 1910 1907 } … … 1980 1977 1981 1978 if (dummy == NULL) 1982 sh.flag.isdaemon = ON;1979 sh.flag.isdaemon = S_TRUE; 1983 1980 else 1984 1981 res = sh_util_flagval (dummy, &sh.flag.isdaemon); … … 2003 2000 2004 2001 if (dummy == NULL) 2005 sh.flag.isdaemon = OFF;2002 sh.flag.isdaemon = S_FALSE; 2006 2003 else 2007 2004 res = sh_util_flagval (dummy, &sh.flag.isdaemon); … … 2221 2218 char * tz = sh_util_strdup(getenv("TZ")); /* flawfinder: ignore */ 2222 2219 size_t tzlen = strlen(tz); 2223 if (S L_TRUE == sl_ok_adds (4, tzlen)) {2220 if (S_TRUE == sl_ok_adds (4, tzlen)) { 2224 2221 env[3] = SH_ALLOC(4+tzlen); 2225 2222 sl_strlcpy(env[3], "TZ=", 4); … … 2244 2241 memset(skey, 0, sizeof(sh_key_t)); 2245 2242 (void) umask(S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); 2246 sh_unix_closeall (3, -1, S L_TRUE); /* in child process */2243 sh_unix_closeall (3, -1, S_TRUE); /* in child process */ 2247 2244 execve(path, arg, env); 2248 2245 _exit(EXIT_FAILURE); … … 2284 2281 struct tm bb; 2285 2282 2283 struct tm * aptr; 2284 struct tm * bptr; 2285 2286 2286 int sign = 0; 2287 2287 int diff = 0; … … 2292 2292 2293 2293 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GMTIME_R) 2294 gmtime_r (xx, &aa);2294 aptr = gmtime_r (xx, &aa); 2295 2295 #else 2296 memcpy (&aa, gmtime(xx), sizeof(struct tm)); 2296 aptr = gmtime(xx); 2297 if (aptr) 2298 memcpy (&aa, aptr, sizeof(struct tm)); 2297 2299 #endif 2298 2300 2299 2301 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_LOCALTIME_R) 2300 localtime_r (xx, &bb);2302 bptr = localtime_r (xx, &bb); 2301 2303 #else 2302 memcpy (&bb, localtime(xx), sizeof(struct tm)); 2303 #endif 2304 2305 /* Check for datum wrap-around. 2306 */ 2307 if (aa.tm_year < bb.tm_year) 2308 sign = (-1); 2309 else if (aa.tm_mon < bb.tm_mon) 2310 sign = (-1); 2311 else if (aa.tm_mday < bb.tm_mday) 2312 sign = (-1); 2313 else if (bb.tm_year < aa.tm_year) 2314 sign = ( 1); 2315 else if (bb.tm_mon < aa.tm_mon) 2316 sign = ( 1); 2317 else if (bb.tm_mday < aa.tm_mday) 2318 sign = ( 1); 2319 2320 diff = aa.tm_hour * 60 + aa.tm_min; 2321 diff = (bb.tm_hour * 60 + bb.tm_min) - diff; 2322 diff = diff - (sign * 24 * 60); /* datum wrap-around correction */ 2323 hh = diff / 60; 2324 mm = diff - (hh * 60); 2325 sprintf (tz, _("%+03d%02d"), hh, mm); /* known to fit */ 2326 2304 bptr = localtime(xx); 2305 if (bptr) 2306 memcpy (&bb, bptr, sizeof(struct tm)); 2307 #endif 2308 2309 if (bptr && aptr) 2310 { 2311 /* Check for datum wrap-around. 2312 */ 2313 if (aa.tm_year < bb.tm_year) 2314 sign = (-1); 2315 else if (aa.tm_mon < bb.tm_mon) 2316 sign = (-1); 2317 else if (aa.tm_mday < bb.tm_mday) 2318 sign = (-1); 2319 else if (bb.tm_year < aa.tm_year) 2320 sign = ( 1); 2321 else if (bb.tm_mon < aa.tm_mon) 2322 sign = ( 1); 2323 else if (bb.tm_mday < aa.tm_mday) 2324 sign = ( 1); 2325 2326 diff = aa.tm_hour * 60 + aa.tm_min; 2327 diff = (bb.tm_hour * 60 + bb.tm_min) - diff; 2328 diff = diff - (sign * 24 * 60); /* datum wrap-around correction */ 2329 hh = diff / 60; 2330 mm = diff - (hh * 60); 2331 sprintf (tz, _("%+03d%02d"), hh, mm); /* known to fit */ 2332 } 2333 else 2334 { 2335 sprintf (tz, _("%+03d%02d"), 0, 0); 2336 } 2327 2337 SL_RETURN(tz, _("t_zone")); 2328 2338 } … … 2560 2570 static int sh_unix_use_localtime = S_FALSE; 2561 2571 2562 /* whether to use localtime for file times atams in logs2572 /* whether to use localtime for file timestamps in logs 2563 2573 */ 2564 2574 int sh_unix_uselocaltime (const char * c) … … 3485 3495 3486 3496 int sh_unix_checksum_size (char * filename, off_t size, int is_max_size, 3487 char * fileHash, int alert_timeout, SL_TICKET fd )3497 char * fileHash, int alert_timeout, SL_TICKET fd, unsigned long mask) 3488 3498 { 3489 3499 file_type * tmpFile; … … 3517 3527 char hashbuf[KEYBUF_SIZE]; 3518 3528 UINT64 local_length = (UINT64) (tmpFile->size < 0 ? 0 : tmpFile->size); 3529 if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(mask); 3519 3530 sl_strlcpy(fileHash, 3520 3531 sh_tiger_generic_hash (filename, fd, &(local_length), … … 3541 3552 3542 3553 int sh_check_rotated_log (const char * path, 3543 UINT64 old_size, UINT64 old_inode, const char * old_hash )3554 UINT64 old_size, UINT64 old_inode, const char * old_hash, unsigned long mask) 3544 3555 { 3545 3556 struct stat obuf; … … 3560 3571 if (!SL_ISERROR(fd)) 3561 3572 { 3562 sh_unix_checksum_size (rotated_file, old_size, S_FALSE, hashbuf, 120 /* alert_timeout */, fd); 3573 sh_unix_checksum_size (rotated_file, old_size, S_FALSE, 3574 hashbuf, 120 /* alert_timeout */, fd, mask); 3563 3575 3564 3576 sl_close(fd); … … 3814 3826 SL_ENTER(_("sh_unix_getinfo")); 3815 3827 3816 if (!MODI_INITIALIZED(theFile->check_ mask))3828 if (!MODI_INITIALIZED(theFile->check_flags)) 3817 3829 { 3818 3830 tmp2 = sh_util_safe_name (theFile->fullpath); … … 3823 3835 SH_MUTEX_UNLOCK(mutex_thread_nolog); 3824 3836 SH_FREE(tmp2); 3837 SL_RETURN((-1),_("sh_unix_getinfo")); 3825 3838 } 3826 3839 … … 3989 4002 if (fileHash != NULL) 3990 4003 { 3991 if ((theFile->check_ mask& MODI_CHK) == 0 ||4004 if ((theFile->check_flags & MODI_CHK) == 0 || 3992 4005 sh_restrict_this(theFile->fullpath, (UINT64) fbuf.st_size, 3993 4006 (UINT64) fbuf.st_mode, rval_open)) … … 3995 4008 sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1); 3996 4009 } 3997 else if ((theFile->check_ mask& MODI_PREL) != 0 &&4010 else if ((theFile->check_flags & MODI_PREL) != 0 && 3998 4011 S_TRUE == sh_prelink_iself(rval_open, fbuf.st_size, 3999 4012 alert_timeout, theFile->fullpath)) 4000 4013 { 4001 4014 if (0 != sh_prelink_run (theFile->fullpath, 4002 fileHash, alert_timeout ))4015 fileHash, alert_timeout, theFile->check_flags)) 4003 4016 sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1); 4004 4017 } … … 4008 4021 UINT64 length_current = TIGER_NOLIM; 4009 4022 4010 if (MODI_TXT_ENABLED(theFile->check_ mask) && fbuf.st_size < (10 * SH_TXT_MAX))4023 if (MODI_TXT_ENABLED(theFile->check_flags) && fbuf.st_size < (10 * SH_TXT_MAX)) 4011 4024 { 4012 4025 sl_init_content (rval_open, fbuf.st_size); 4013 4026 } 4014 4027 4028 if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(theFile->check_flags); 4015 4029 sl_strlcpy(fileHash, 4016 4030 sh_tiger_generic_hash (theFile->fullpath, … … 4023 4037 content = sh_string_copy(content); 4024 4038 4025 if ((theFile->check_ mask& MODI_SGROW) != 0)4039 if ((theFile->check_flags & MODI_SGROW) != 0) 4026 4040 { 4027 4041 /* Update size so it matches the one for which the checksum … … 4032 4046 sh_unix_checksum_size (theFile->fullpath, length_current, S_TRUE, 4033 4047 &fileHash[KEY_LEN + 1], 4034 alert_timeout, rval_open );4048 alert_timeout, rval_open, theFile->check_flags); 4035 4049 } 4036 4050 } … … 4046 4060 if (fileHash != NULL) 4047 4061 { 4048 if ((theFile->check_ mask& MODI_CHK) == 0 ||4062 if ((theFile->check_flags & MODI_CHK) == 0 || 4049 4063 sh_restrict_this(theFile->fullpath, (UINT64) fbuf.st_size, 4050 4064 (UINT64) fbuf.st_mode, rval_open)) … … 4057 4071 { 4058 4072 if (0 != sh_prelink_run (theFile->fullpath, 4059 fileHash, alert_timeout ))4073 fileHash, alert_timeout, theFile->check_flags)) 4060 4074 sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1); 4061 4075 } … … 4065 4079 UINT64 length_current = TIGER_NOLIM; 4066 4080 4067 if (MODI_TXT_ENABLED(theFile->check_ mask) && fbuf.st_size < (10 * SH_TXT_MAX))4081 if (MODI_TXT_ENABLED(theFile->check_flags) && fbuf.st_size < (10 * SH_TXT_MAX)) 4068 4082 { 4069 4083 sl_init_content (rval_open, fbuf.st_size); 4070 4084 } 4071 4085 4086 if (sh.flag.opts == S_TRUE) sh_tiger_set_hashtype_mask(theFile->check_flags); 4072 4087 sl_strlcpy(fileHash, 4073 4088 sh_tiger_generic_hash (theFile->fullpath, rval_open, … … 4080 4095 content = sh_string_copy(content); 4081 4096 4082 if ((theFile->check_ mask& MODI_SGROW) != 0)4097 if ((theFile->check_flags & MODI_SGROW) != 0) 4083 4098 { 4084 4099 /* Update size so it matches the one for which the checksum … … 4089 4104 sh_unix_checksum_size (theFile->fullpath, length_current, S_TRUE, 4090 4105 &fileHash[KEY_LEN + 1], 4091 alert_timeout, rval_open );4106 alert_timeout, rval_open, theFile->check_flags); 4092 4107 } 4093 4108 } … … 4105 4120 sl_strlcpy(fileHash, SH_KEY_NULL, KEY_LEN+1); 4106 4121 4107 if ((theFile->check_ mask& MODI_CHK) != 0)4122 if ((theFile->check_flags & MODI_CHK) != 0) 4108 4123 { 4109 4124 tmp2 = sh_util_safe_name (theFile->fullpath); … … 4276 4291 /* --- Output the file. --- 4277 4292 */ 4278 if (flag_err_debug == S L_TRUE)4293 if (flag_err_debug == S_TRUE) 4279 4294 { 4280 4295 tmp2 = sh_util_safe_name ((filename == NULL) ? … … 5294 5309 int sh_unix_count_mlock() 5295 5310 { 5296 int i = 0;5311 unsigned int i = 0; 5297 5312 char str[32][64]; 5298 5313 sh_page_l * page_list; … … 5325 5340 #ifdef WITH_TPT 5326 5341 { 5327 int j = 0;5342 unsigned int j = 0; 5328 5343 while (j < i && j < 32) 5329 5344 { 5330 sh_error_handle(SH_ERR_ INFO, FIL__, __LINE__, j, MSG_E_SUBGEN,5345 sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, j, MSG_E_SUBGEN, 5331 5346 str[j], _("sh_unix_count_mlock")); 5332 5347 ++j; … … 5336 5351 5337 5352 sl_snprintf(str[0], 64, _("%d pages locked"), i); 5338 sh_error_handle(SH_ERR_ INFO, FIL__, __LINE__, i, MSG_E_SUBGEN,5353 sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, i, MSG_E_SUBGEN, 5339 5354 str[0], _("sh_unix_count_mlock")); 5340 5355 SL_RETURN((i), _("sh_unix_count_mlock")); … … 5515 5530 this_line = 0; 5516 5531 c = '\0'; 5517 while (c != '\n' && num > 0 &&this_line < (sizeof(theline)-1))5532 while (c != '\n' && this_line < (sizeof(theline)-1)) 5518 5533 { 5519 5534 do {
Note:
See TracChangeset
for help on using the changeset viewer.