From 1100b37feb672134fdd05c400e7290d7e4323609 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Thu, 14 Jan 2010 00:46:48 +0000 Subject: [PATCH] Minor adjustments to UDF source code and file system structure --- extra/mysqludfsys/linux/Makefile | 6 +- .../linux/{src => }/lib_mysqludf_sys.c | 0 .../mysqludfsys/linux/so/lib_mysqludf_sys.so | Bin 9568 -> 0 bytes extra/postgresqludfsys/linux/Makefile | 19 +- extra/postgresqludfsys/linux/install.sh | 14 +- .../{src/8.3 => }/lib_postgresqludf_sys.c | 17 +- .../linux/so/8.2/lib_postgresqludf_sys.so | Bin 5472 -> 0 bytes .../linux/so/8.3/lib_postgresqludf_sys.so | Bin 5472 -> 0 bytes .../linux/src/8.2/lib_postgresqludf_sys.c | 192 ------------------ 9 files changed, 40 insertions(+), 208 deletions(-) rename extra/mysqludfsys/linux/{src => }/lib_mysqludf_sys.c (100%) delete mode 100755 extra/mysqludfsys/linux/so/lib_mysqludf_sys.so rename extra/postgresqludfsys/linux/{src/8.3 => }/lib_postgresqludf_sys.c (89%) mode change 100644 => 100755 delete mode 100644 extra/postgresqludfsys/linux/so/8.2/lib_postgresqludf_sys.so delete mode 100755 extra/postgresqludfsys/linux/so/8.3/lib_postgresqludf_sys.so delete mode 100755 extra/postgresqludfsys/linux/src/8.2/lib_postgresqludf_sys.c diff --git a/extra/mysqludfsys/linux/Makefile b/extra/mysqludfsys/linux/Makefile index 24ddc7193..4b15ab590 100644 --- a/extra/mysqludfsys/linux/Makefile +++ b/extra/mysqludfsys/linux/Makefile @@ -1,6 +1,6 @@ LIBDIR=/usr/lib install: - gcc -Wall -I/usr/include/mysql -O1 -shared src/lib_mysqludf_sys.c -o so/lib_mysqludf_sys.so - strip -sx so/lib_mysqludf_sys.so - sudo cp -f so/lib_mysqludf_sys.so $(LIBDIR)/lib_mysqludf_sys.so + gcc -Wall -I/usr/include/mysql -O1 -shared lib_mysqludf_sys.c -o lib_mysqludf_sys.so + strip -sx lib_mysqludf_sys.so + sudo cp -f lib_mysqludf_sys.so $(LIBDIR)/lib_mysqludf_sys.so diff --git a/extra/mysqludfsys/linux/src/lib_mysqludf_sys.c b/extra/mysqludfsys/linux/lib_mysqludf_sys.c similarity index 100% rename from extra/mysqludfsys/linux/src/lib_mysqludf_sys.c rename to extra/mysqludfsys/linux/lib_mysqludf_sys.c diff --git a/extra/mysqludfsys/linux/so/lib_mysqludf_sys.so b/extra/mysqludfsys/linux/so/lib_mysqludf_sys.so deleted file mode 100755 index 699065da356ed27e0720b4cd6b61f829f46ef9eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9568 zcmeHNeT-aH6~8n4whVM=hcd+}tnI5#VT*NG+7$tbE;C&|D=O^*wQh&$?3>+z`B>(? zX?ICMHj_>IcuZ)hHJE6GU{oR^1~jw?E-dVWM0CNL@&_@E1l_u;wq~J)HjKaDeedl~ zr){FfL{0X#=bd}*Irp4%&pq$nxA)H1JJ(&~^ZA5VnnaTzb>Epnv;z+;cR1}r70sem zED;gO_vDFJo#Q|=iI9+dWtkAlB@P6jFa((A^8LUO@FU<8#z7OvR{&pm*XRK{sd)UG z!LQeU9Fhd~g&DB|@F~DzKmgDRSPJk;lUrHj;xd05tBn*%-JdGg7rUDiMRsv2{&OqaZfRDM% z`KJ;>8^SMI>UfxLS%P>njw~DpeIiZ0zJSuPbBX=h^WO_J?Nn~BkjL@U7RSeNFeWO1 zF=JsISQtCb3u8*(8E=+fuNv9gd)3yRlfV7jf`QUSJN8r$FL>*&+ge`y!;#WApc$i{gVdyhZ^YLG{_%lp#2T7vn}r&lf8}huy?lB+eB3KnL5TIQky0eG}Eqb^7iG ze=qDYhp7Jm``5|eg7(fj`E$X4012zR^3QEVI{B->AA)~_F8_7V_5NsR zzoAb467Wk{02Tt%pJDJffRF!@UXJ!!o&6-}PWaC_QT}n@G=%@`(vN_@1^#h8Ab&sb z7x99A!PPI4$=-aikkpM-$w($eGLtQ2(U=}cv6{+d@76@}hONn)wcf05X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zp1Dq zMU_%-IgfD#vQgw(A}1sJ=I`ZeRF7e8F~8khCTRAhF|rU3et)zgSl>Yxuj5sGNzotl~JycSY~Dy9olbP6s4a5t0RcLEa2sk zbn;fd2`3E!OAZDWK?Y1lO#9^31nX)*<_{JPxeLucFmUXr-5+3K89g6=0&@|Vi@;n2{_i7zzY68~nuj?co)PejoF}=w!@@DOyzAnL$UeY(AJvL2 zIMc>4vUmUw98-(8LF1TOECj}}vpiqt>HRd$nb9O^o_z7hnRliN^s>GdC&Roi90BkS zng_++UEN2uT5%d@n((bipAG?k8}x_3)cNle-no0_tMK6t0MG8lwTZ-)YHQb)a=|F8 z?XfknHJ|=WSyJsQ9r}MyCZ_k{h|5TA5wYGvIo6lb`$Vi~u%Hj-9c+{w4vunoj&lN$ z1h1s!DDPDIbB2h?E1{U74WKTs;9{ksyv&JdeaQ^Z$wVw|6iYe`IOvWv6hTQUpH0I+ z5gqY}No`I~+ybFfF^}Ur!;AetgBL=GImWqW-Vv@tA~?4~&fPq7lKJ+&n-k1S!U)`!JO!W*<`*%~)OiQXzLaBr6PVXtp)AV^0CSTp<|Tpmw4PnI6IKJ5%d9h> z313FN-Y!USH2~=-`|!OWjDYs^QJ(L|4FFG$?-7B1Q;zSTC$}DT`pWl{?=gX??iI?h z+ywCC)(H7@N}SQroPRUV;tn~Z*T_2czMO^b1xdGmvTX@2f@?G4cEzqAs2?6rvt2+`u(Ug z#?&W&*8{onIzIc*k6i%IF7M+eAjdVbAYJh^`WJ86fw diff --git a/extra/postgresqludfsys/linux/Makefile b/extra/postgresqludfsys/linux/Makefile index 006bd245b..fcbb4a13e 100644 --- a/extra/postgresqludfsys/linux/Makefile +++ b/extra/postgresqludfsys/linux/Makefile @@ -1,11 +1,16 @@ LIBDIR=/tmp -8.2: - gcc -Wall -I/usr/include/postgresql/8.2/server -O1 -shared src/8.2/lib_postgresqludf_sys.c -o so/8.2/lib_postgresqludf_sys.so - strip -sx so/8.2/lib_postgresqludf_sys.so - cp -f so/8.2/lib_postgresqludf_sys.so $(LIBDIR)/lib_postgresqludf_sys.so +8.4: + gcc -Wall -I/usr/include/postgresql/8.4/server -O1 -shared lib_postgresqludf_sys.c -o lib_postgresqludf_sys.so + strip -sx lib_postgresqludf_sys.so + cp -f lib_postgresqludf_sys.so $(LIBDIR)/lib_postgresqludf_sys.so 8.3: - gcc -Wall -I/usr/include/postgresql/8.3/server -O1 -shared src/8.3/lib_postgresqludf_sys.c -o so/8.3/lib_postgresqludf_sys.so - strip -sx so/8.3/lib_postgresqludf_sys.so - cp -f so/8.3/lib_postgresqludf_sys.so $(LIBDIR)/lib_postgresqludf_sys.so + gcc -Wall -I/usr/include/postgresql/8.3/server -O1 -shared lib_postgresqludf_sys.c -o lib_postgresqludf_sys.so + strip -sx lib_postgresqludf_sys.so + cp -f lib_postgresqludf_sys.so $(LIBDIR)/lib_postgresqludf_sys.so + +8.2: + gcc -Wall -I/usr/include/postgresql/8.2/server -O1 -shared lib_postgresqludf_sys.c -o lib_postgresqludf_sys.so + strip -sx lib_postgresqludf_sys.so + cp -f lib_postgresqludf_sys.so $(LIBDIR)/lib_postgresqludf_sys.so diff --git a/extra/postgresqludfsys/linux/install.sh b/extra/postgresqludfsys/linux/install.sh index a5aa0c6a2..ed636efcb 100755 --- a/extra/postgresqludfsys/linux/install.sh +++ b/extra/postgresqludfsys/linux/install.sh @@ -19,11 +19,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Adapt the following settings to your environment -#PORT="5433" -#VERSION="8.2" -PORT="5432" -VERSION="8.3" USER="postgres" +PORT="5434" +VERSION="8.4" +#PORT="5433" +#VERSION="8.3" +#PORT="5432" +#VERSION="8.2" echo "Compiling the PostgreSQL UDF" make ${VERSION} @@ -34,8 +36,10 @@ if test $? -ne 0; then if test "${VERSION}" == "8.2"; then echo "apt-get install postgresql-server-dev-8.2" - else + else if test "${VERSION}" == "8.3"; then echo "apt-get install postgresql-server-dev-8.3" + else if test "${VERSION}" == "8.4"; then + echo "apt-get install postgresql-server-dev-8.4" fi exit 1 diff --git a/extra/postgresqludfsys/linux/src/8.3/lib_postgresqludf_sys.c b/extra/postgresqludfsys/linux/lib_postgresqludf_sys.c old mode 100644 new mode 100755 similarity index 89% rename from extra/postgresqludfsys/linux/src/8.3/lib_postgresqludf_sys.c rename to extra/postgresqludfsys/linux/lib_postgresqludf_sys.c index 48cabdcc2..c269c5421 --- a/extra/postgresqludfsys/linux/src/8.3/lib_postgresqludf_sys.c +++ b/extra/postgresqludfsys/linux/lib_postgresqludf_sys.c @@ -47,7 +47,11 @@ PG_MODULE_MAGIC; #endif PG_FUNCTION_INFO_V1(sys_exec); +#ifdef PGDLLIMPORT extern PGDLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) { +#else +extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) { +#endif text *argv0 = PG_GETARG_TEXT_P(0); int32 argv0_size; int32 result = 0; @@ -72,7 +76,11 @@ extern PGDLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) { } PG_FUNCTION_INFO_V1(sys_eval); +#ifdef PGDLLIMPORT extern PGDLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) { +#else +extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) { +#endif text *argv0 = PG_GETARG_TEXT_P(0); text *result_text; int32 argv0_size; @@ -112,15 +120,22 @@ extern PGDLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) { } result_text = (text *)malloc(VARHDRSZ + strlen(result)); - //VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ; +#ifdef SET_VARSIZE SET_VARSIZE(result_text, VARHDRSZ + strlen(result)); +#else + VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ; +#endif memcpy(VARDATA(result_text), result, strlen(result)); PG_RETURN_POINTER(result_text); } PG_FUNCTION_INFO_V1(sys_bineval); +#ifdef PGDLLIMPORT extern PGDLLIMPORT Datum sys_bineval(PG_FUNCTION_ARGS) { +#else +extern DLLIMPORT Datum sys_bineval(PG_FUNCTION_ARGS) { +#endif text *argv0 = PG_GETARG_TEXT_P(0); int32 argv0_size; size_t len; diff --git a/extra/postgresqludfsys/linux/so/8.2/lib_postgresqludf_sys.so b/extra/postgresqludfsys/linux/so/8.2/lib_postgresqludf_sys.so deleted file mode 100644 index 16556d4fb7e61b682e38efcd9035543e88d372bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5472 zcmeHLeQZVIx%ZxX{hq(It!sN-U7e8BAQ}X%-3x{2gdAMvdOAf=G>Ua% zg=lsB5>NTwVwW3f1cc-F-7AFeewY0S7yvKu{PmEn@VCNGF2g3%?*l(^P49>JHe+zkE{7%7R*fER)N;5!lX=Qt$J8B68R zr}4QOyxcVfmIbScIf9phSAwevQ+KEdpDmtFai6Czfnv!AMwi=YyvpL5{HVtMVU2yW%H|r&HDPlQ{5dKf1tEVc4M@iSu*UvbjeVuY{;0+t zsj+`qW1p+B|5#&xuf}G*NLmBs_tJo5zTd90Ip42=??a)mUYfDn`yl@S;|0%-L#{%x zjbdTwUj^9`L?b95rtL+rn}Uw%*b3B8RlMh5hpX&mHTWa&Z-DA zbxmZW$&7}yIk)HmB^p1V#3G3#!|G~EWMes170Eh8k@eTGaK3-=UgxTLUh;aLCoX-7u%wYIB zV>HmSzqiEsRl;Z(Dy?*e_gTY1;4!`B*6^&WEiM{t!}#_kW7OBvTe8|hr4uCdKRb#w zbt0V|nb+Q&*Un1Km|SP}&Y1aG^Z7Yzo8Q_L;Dk6ubIfXWl)}ip$4?`f!bn~-Cmw|B zvEty|xG&@^G@(YNuGq5SMtOW|h)W_Mog)C*^nh#o`Mvi*+1wiPp(jD^ASGkg)_0mm zL;m7+AH8OqJG}kwd7|E5?})-kQC}-w2q7XLL^uMs)LDII;9?uk(`S~g-We-DYdt?_ zPC85QjeUEDCO?l3>MPEcZJSy@QZw0cOSm)3&KZ@4`86mNclb;_2M*=V zp)m20Z8M`YSXG(7S$L1Fg{$~vrte3JZ%sizOXD0;wm*2y{Pm483dA}^P~C^-Ga;XK zlEKUtZx5W%OrTg`XQp8}Z4FM~`8=Hn)=3U&?hW~!<-vTtUfzykBMXNxu!r-;aN`}@ zAoRu7NhUJ3HDHU2%+Pv^$y{K@=CnES!D}~uXT05DHp%2J!|P(I+}24pn~S8w>23-!O; zyZId&lNxH_%Yy;kZ$9eHZ0fcO;(5Y-a0*Ecm0m=KmJvXHtlSmF*QplItmPsZfA!gA zYXKbj8F`MY?y24AT6r0Z^EB?H9Plh5$(;Ba+|B)vLGUKVh(4IkKJ>y@t7jIAaR{L&vI~y89a;d z*^ggrJga;x;d|y)bfP|iAbh{z*ApJOoaZt=yOVC&cIG(z$Sni6n1b91`z9pE{9lOg z+>#!_m+N-0KZuqcTef^DxURb|pVsri&TvP#;|pKRJ67jIuKoXq32Sk@9_W!iy#A*1 z;dn%gi*Wzpw01bBB?|a17y$Jq=#)vN)U++K(?3F26nVs%tZ4$@2ByWN)$7MUY9n4y$&Uz;AhF(1`Oz}7vuK-RTo(nS1g^Wi$AGUW@;dqY7 z%$qo#L5bS~ow@R?@EnsLhAxRX($~Qf7sPoW*W!qMx(dhN$jCco5crq_Nde1vdBo2)ZPROQC`Bh?@Y0EPcdE{Sb8GxDL+mZzv%7?t-Ry9Dk#bxF*~O zO?SW*s&Fm9wE!o_s*d*}46ZT9<^96n_sY;EmXdi4gXOqY7NF47lKQ@3qNmBm_8aO`lYYKva`%mlg3-}pN5^-mw0V#cQOz9c{?pM;N G!u<=TDiQtw diff --git a/extra/postgresqludfsys/linux/so/8.3/lib_postgresqludf_sys.so b/extra/postgresqludfsys/linux/so/8.3/lib_postgresqludf_sys.so deleted file mode 100755 index bb7cfa39c21f02e4c43a1882a9e9a6ebdc2ea954..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5472 zcmeHLeQZh6W+2Ni+#sI~NMk1v#|L^>m4lXcp_l z3eo2HC7$w~#V$9~2nxsVyITm~y)OF^FbH1Y`5P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`vL0%l6HizZ6=xyT6dp3!$z^XQcDj|A&ca3A`TY(SE%C zW(tu+R7;4+z@dzGDD6r;?|KfXc`cdE++ry3<<%7Nu98dXBI3LTMRauty7Mv=$!DGS zgNT|?;`wM=6_J>p&1)FI72l2_5Q0S0$ruL6q9Z;cPBgbCUM$cln@+14U9SDdk^D`9 zHOBg3-I0F>W?hk3k7U-{KT#9Ju`bC^L9fU0w+Uj2W4)4TFa}jh)+v7%VP6Lag*DE) zmL%2Bpn_!VJ^^ diff --git a/extra/postgresqludfsys/linux/src/8.2/lib_postgresqludf_sys.c b/extra/postgresqludfsys/linux/src/8.2/lib_postgresqludf_sys.c deleted file mode 100755 index ffc890e9c..000000000 --- a/extra/postgresqludfsys/linux/src/8.2/lib_postgresqludf_sys.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - lib_postgresqludf_sys - a library with miscellaneous (operating) system level functions - Copyright (C) 2009 Bernardo Damele A. G. - web: http://bernardodamele.blogspot.com/ - email: bernardo.damele@gmail.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) -#define _USE_32BIT_TIME_T -#define DLLEXP __declspec(dllexport) -#define BUILDING_DLL 1 -#else -#define DLLEXP -#include -#include -#include -#include -#endif - -#include -#include -#include -#include - -#include - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) -DWORD WINAPI exec_payload(LPVOID lpParameter); -#endif - -#ifdef PG_MODULE_MAGIC -PG_MODULE_MAGIC; -#endif - -PG_FUNCTION_INFO_V1(sys_exec); -extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) { - text *argv0 = PG_GETARG_TEXT_P(0); - int32 argv0_size; - int32 result = 0; - char *command; - - argv0_size = VARSIZE(argv0) - VARHDRSZ; - command = (char *)malloc(argv0_size + 1); - - memcpy(command, VARDATA(argv0), argv0_size); - command[argv0_size] = '\0'; - - /* - Only if you want to log - elog(NOTICE, "Command execution: %s", command); - */ - - result = system(command); - free(command); - - PG_FREE_IF_COPY(argv0, 0); - PG_RETURN_INT32(result); -} - -PG_FUNCTION_INFO_V1(sys_eval); -extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) { - text *argv0 = PG_GETARG_TEXT_P(0); - text *result_text; - int32 argv0_size; - char *command; - char *result; - FILE *pipe; - char line[1024]; - int32 outlen, linelen; - - argv0_size = VARSIZE(argv0) - VARHDRSZ; - command = (char *)malloc(argv0_size + 1); - - memcpy(command, VARDATA(argv0), argv0_size); - command[argv0_size] = '\0'; - - /* - Only if you want to log - elog(NOTICE, "Command evaluated: %s", command); - */ - - result = (char *)malloc(1); - outlen = 0; - - pipe = popen(command, "r"); - - while (fgets(line, sizeof(line), pipe) != NULL) { - linelen = strlen(line); - result = (char *)realloc(result, outlen + linelen); - strncpy(result + outlen, line, linelen); - outlen = outlen + linelen; - } - - pclose(pipe); - - if (*result) { - result[outlen-1] = 0x00; - } - - result_text = (text *)malloc(VARHDRSZ + strlen(result)); - VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ; - //SET_VARSIZE(result_text, VARHDRSZ + strlen(result)); - memcpy(VARDATA(result_text), result, strlen(result)); - - PG_RETURN_POINTER(result_text); -} - -PG_FUNCTION_INFO_V1(sys_bineval); -extern DLLIMPORT Datum sys_bineval(PG_FUNCTION_ARGS) { - text *argv0 = PG_GETARG_TEXT_P(0); - int32 argv0_size; - size_t len; - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) - int pID; - char *code; -#else - int *addr; - size_t page_size; - pid_t pID; -#endif - - argv0_size = VARSIZE(argv0) - VARHDRSZ; - len = (size_t)argv0_size; - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) - // allocate a +rwx memory page - code = (char *) VirtualAlloc(NULL, len+1, MEM_COMMIT, PAGE_EXECUTE_READWRITE); - strncpy(code, VARDATA(argv0), len); - - WaitForSingleObject(CreateThread(NULL, 0, exec_payload, code, 0, &pID), INFINITE); -#else - pID = fork(); - if(pID<0) - PG_RETURN_INT32(1); - - if(pID==0) - { - page_size = (size_t)sysconf(_SC_PAGESIZE)-1; // get page size - page_size = (len+page_size) & ~(page_size); // align to page boundary - - // mmap an rwx memory page - addr = mmap(0, page_size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, 0, 0); - - if (addr == MAP_FAILED) - PG_RETURN_INT32(1); - - strncpy((char *)addr, VARDATA(argv0), len); - - ((void (*)(void))addr)(); - } - - if(pID>0) - waitpid(pID, 0, WNOHANG); -#endif - - PG_RETURN_INT32(0); -} - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) -DWORD WINAPI exec_payload(LPVOID lpParameter) -{ - __try - { - __asm - { - mov eax, [lpParameter] - call eax - } - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - - } - - return 0; -} -#endif