Changeset 169 for trunk/src/sh_unix.c
- Timestamp:
- Apr 13, 2008, 9:59:55 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_unix.c
r167 r169 43 43 #include <fcntl.h> 44 44 #include <unistd.h> 45 /* need to undef these, since the #define's may be picked up from 46 * linux/wait.h, and will clash with a typedef in sys/wait.h 47 */ 48 #undef P_ALL 49 #undef P_PID 50 #undef P_PGID 45 51 #include <sys/wait.h> 46 52 … … 2993 2999 someval *= 1000; /* milliseconds in a second */ 2994 3000 sometime = (unsigned long) someval; 2995 /* fprintf(stderr, "FIXME PAUSE %ld\n", sometime); */2996 3001 retry_msleep(0, sometime); 2997 3002 } … … 2999 3004 { 3000 3005 sometime = (unsigned long) someval; 3001 /* fprintf(stderr, "FIXME PAUSE %ld sec\n", sometime); */3002 3006 retry_msleep (sometime, 0); 3003 3007 } … … 3037 3041 3038 3042 SL_ENTER(_("sh_unix_checksum_size")); 3043 3044 tmpFile.link_path = NULL; 3039 3045 3040 3046 if (sh.flag.checkSum != SH_CHECK_INIT) … … 3256 3262 } 3257 3263 #endif 3258 3264 3265 #ifdef HAVE_LIBZ 3266 #include <zlib.h> 3267 #endif 3259 3268 3260 3269 int sh_unix_getinfo (int level, char * filename, file_type * theFile, … … 3402 3411 UINT64 length_nolim = TIGER_NOLIM; 3403 3412 3404 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX)3413 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < (10 * SH_TXT_MAX)) 3405 3414 { 3406 3415 sl_init_content (rval_open, fbuf.st_size); … … 3415 3424 3416 3425 content = sl_get_content(rval_open); 3426 content = sh_string_copy(content); 3417 3427 3418 3428 if ((theFile->check_mask & MODI_SGROW) != 0) … … 3454 3464 UINT64 length_nolim = TIGER_NOLIM; 3455 3465 3456 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < SH_TXT_MAX)3466 if ((theFile->check_mask & MODI_TXT) != 0 && fbuf.st_size < (10 * SH_TXT_MAX)) 3457 3467 { 3458 3468 sl_init_content (rval_open, fbuf.st_size); … … 3467 3477 3468 3478 content = sl_get_content(rval_open); 3479 content = sh_string_copy(content); 3469 3480 3470 3481 if ((theFile->check_mask & MODI_SGROW) != 0) … … 3759 3770 if (content) 3760 3771 { 3761 sh_util_base64_enc_alloc (&(theFile->link_path), 3762 sh_string_str(content), 3763 sh_string_len(content)); 3772 #ifdef HAVE_LIBZ 3773 unsigned long clen = compressBound(sh_string_len(content)); 3774 unsigned char * compressed = SH_ALLOC(clen); 3775 if (Z_OK == compress(compressed, &clen, 3776 (unsigned char *) sh_string_str(content), 3777 sh_string_len(content))) 3778 { 3779 if (clen < SH_TXT_MAX) 3780 { 3781 sh_util_base64_enc_alloc (&(theFile->link_path), 3782 (char *) compressed, clen); 3783 } 3784 else 3785 { 3786 char tmsg[128]; 3787 char * tpath = sh_util_safe_name (theFile->fullpath); 3788 sl_snprintf(tmsg, sizeof(tmsg), 3789 _("compressed file too large (%lu bytes)"), 3790 clen); 3791 sh_error_handle (SH_ERR_WARN, FIL__, __LINE__, -1, 3792 MSG_E_SUBGPATH, tmsg, 3793 _("sh_unix_getinfo"), tpath); 3794 SH_FREE(tpath); 3795 } 3796 } 3797 SH_FREE(compressed); 3798 #endif 3799 sh_string_destroy(&content); 3764 3800 } 3765 3801 } … … 3770 3806 #endif 3771 3807 3772 int sh_unix_unlock (char * lockfile, char * flag); 3773 int sh_unix_lock (char * lockfile, char * flag); 3808 int sh_unix_unlock(char * lockfile, char * flag) 3809 { 3810 int error = 0; 3811 3812 SL_ENTER(_("sh_unix_unlock")); 3813 3814 if (sh.flag.isdaemon == S_FALSE && flag == NULL) 3815 SL_RETURN((0),_("sh_unix_unlock")); 3816 3817 /* --- Logfile is not locked to us. --- 3818 */ 3819 if (sh.flag.islocked == BAD && flag != NULL) 3820 SL_RETURN((-1),_("sh_unix_unlock")); 3821 3822 /* --- Check whether the directory is secure. --- 3823 */ 3824 if (0 != tf_trust_check (lockfile, SL_YESPRIV)) 3825 SL_RETURN((-1),_("sh_unix_unlock")); 3826 3827 /* --- Delete the lock file. --- 3828 */ 3829 error = retry_aud_unlink (FIL__, __LINE__, lockfile); 3830 3831 if (error == 0) 3832 { 3833 if (flag != NULL) 3834 sh.flag.islocked = BAD; /* not locked anymore */ 3835 } 3836 else if (flag != NULL) 3837 { 3838 char errbuf[SH_ERRBUF_SIZE]; 3839 error = errno; 3840 sh_error_handle ((-1), FIL__, __LINE__, error, MSG_E_UNLNK, 3841 sh_error_message(error, errbuf, sizeof(errbuf)), 3842 lockfile); 3843 SL_RETURN((-1),_("sh_unix_unlock")); 3844 } 3845 SL_RETURN((0),_("sh_unix_unlock")); 3846 } 3847 3848 int sh_unix_lock (char * lockfile, char * flag) 3849 { 3850 int filed; 3851 int errnum; 3852 char myPid[64]; 3853 SL_TICKET fd; 3854 extern int get_the_fd (SL_TICKET ticket); 3855 3856 SL_ENTER(_("sh_unix_lock")); 3857 3858 sprintf (myPid, "%ld\n", (long) sh.pid); /* known to fit */ 3859 3860 fd = sl_open_safe_rdwr (lockfile, SL_YESPRIV); /* fails if file exists */ 3861 3862 if (!SL_ISERROR(fd)) 3863 { 3864 errnum = sl_write (fd, myPid, sl_strlen(myPid)); 3865 filed = get_the_fd(fd); 3866 fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); 3867 sl_close (fd); 3868 3869 if (!SL_ISERROR(errnum)) 3870 { 3871 if (flag != NULL) 3872 sh.flag.islocked = GOOD; 3873 SL_RETURN((0),_("sh_unix_lock")); 3874 } 3875 } 3876 3877 TPT((0, FIL__, __LINE__, _("msg=<open pid file failed>\n"))); 3878 if (flag != NULL) 3879 sh.flag.islocked = BAD; 3880 SL_RETURN((-1),_("sh_unix_lock")); 3881 3882 /* notreached */ 3883 } 3884 3774 3885 3775 3886 /* check whether file is locked … … 3964 4075 } 3965 4076 3966 int sh_unix_unlock(char * lockfile, char * flag)3967 {3968 int error = 0;3969 3970 SL_ENTER(_("sh_unix_unlock"));3971 3972 /* --- Logfile is not locked to us. ---3973 */3974 if (sh.flag.islocked == BAD && flag != NULL)3975 SL_RETURN((-1),_("sh_unix_unlock"));3976 3977 /* --- Check whether the directory is secure. ---3978 */3979 if (0 != tf_trust_check (lockfile, SL_YESPRIV))3980 SL_RETURN((-1),_("sh_unix_unlock"));3981 3982 /* --- Delete the lock file. ---3983 */3984 error = retry_aud_unlink (FIL__, __LINE__, lockfile);3985 3986 if (error == 0)3987 {3988 if (flag != NULL)3989 sh.flag.islocked = BAD; /* not locked anymore */3990 }3991 else if (flag != NULL)3992 {3993 char errbuf[SH_ERRBUF_SIZE];3994 error = errno;3995 sh_error_handle ((-1), FIL__, __LINE__, error, MSG_E_UNLNK,3996 sh_error_message(error, errbuf, sizeof(errbuf)),3997 lockfile);3998 SL_RETURN((-1),_("sh_unix_unlock"));3999 }4000 SL_RETURN((0),_("sh_unix_unlock"));4001 }4002 4003 4077 /* rm lock for filename 4004 4078 */ … … 4029 4103 { 4030 4104 return sh_unix_unlock(sh.srvlog.alt, NULL); 4031 }4032 4033 int sh_unix_lock (char * lockfile, char * flag)4034 {4035 int filed;4036 int errnum;4037 char myPid[64];4038 SL_TICKET fd;4039 extern int get_the_fd (SL_TICKET ticket);4040 4041 SL_ENTER(_("sh_unix_lock"));4042 4043 sprintf (myPid, "%ld\n", (long) sh.pid); /* known to fit */4044 4045 fd = sl_open_safe_rdwr (lockfile, SL_YESPRIV); /* fails if file exists */4046 4047 if (!SL_ISERROR(fd))4048 {4049 errnum = sl_write (fd, myPid, sl_strlen(myPid));4050 filed = get_the_fd(fd);4051 fchmod (filed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);4052 sl_close (fd);4053 4054 if (!SL_ISERROR(errnum))4055 {4056 if (flag != NULL)4057 sh.flag.islocked = GOOD;4058 SL_RETURN((0),_("sh_unix_lock"));4059 }4060 }4061 4062 TPT((0, FIL__, __LINE__, _("msg=<open pid file failed>\n")));4063 if (flag != NULL)4064 sh.flag.islocked = BAD;4065 SL_RETURN((-1),_("sh_unix_lock"));4066 4067 /* notreached */4068 4105 } 4069 4106
Note:
See TracChangeset
for help on using the changeset viewer.